:root {
  color-scheme: light;
  --paper: #f7f2e9;
  --paper-bright: #fffdf7;
  --ink: #071730;
  --muted: #5e6878;
  --blue: #153cce;
  --blue-dark: #0b2d9f;
  --orange: #ff8a35;
  --green: #31bd73;
  --line: #0a1a31;
  --shadow: 8px 8px 0 #071730;
  --soft-shadow: 4px 4px 0 rgba(7, 23, 48, 0.16);
  --radius: 10px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background-color: var(--paper);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Ccircle cx='1' cy='1' r='.55' fill='%23071730' fill-opacity='.09'/%3E%3C/svg%3E");
}

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }
a { color: inherit; }

.skip-link {
  position: fixed;
  left: 12px;
  top: -80px;
  z-index: 100;
  padding: 12px 16px;
  background: var(--ink);
  color: white;
  font-weight: 800;
}
.skip-link:focus { top: 12px; }

.site-header {
  min-height: 88px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px clamp(20px, 5vw, 72px);
  border-bottom: 3px solid var(--line);
  background: rgba(255, 253, 247, 0.96);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  text-decoration: none;
}
.brand > span:last-child { display: grid; gap: 1px; }
.brand strong {
  font-family: Impact, "Arial Black", sans-serif;
  font-size: clamp(1.2rem, 2.1vw, 1.65rem);
  letter-spacing: 0.045em;
  line-height: 1;
}
.brand small {
  font-size: 0.66rem;
  font-weight: 900;
  letter-spacing: 0.12em;
}
.brand-mark {
  width: 52px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  position: relative;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: var(--blue);
  color: white;
  box-shadow: 3px 3px 0 var(--ink);
  font-family: Impact, "Arial Black", sans-serif;
  font-size: 1.75rem;
  letter-spacing: -0.08em;
}
.brand-mark small { align-self: end; margin: 0 0 5px -3px; font-size: 0.62rem; }

.site-header nav, footer nav { display: flex; gap: clamp(14px, 2.5vw, 30px); }
.site-header nav a, footer nav a {
  text-decoration-thickness: 2px;
  text-underline-offset: 5px;
  font-size: 0.84rem;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.site-header nav a:hover, footer nav a:hover { color: var(--blue); }

main { width: min(1180px, calc(100% - 32px)); margin: 0 auto; }
.hero { padding: clamp(28px, 4vw, 48px) 0 22px; max-width: 860px; }
.eyebrow {
  margin: 0 0 10px;
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 950;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
h1, h2, h3, p { margin-top: 0; }
h1, h2 {
  font-family: Impact, "Arial Black", sans-serif;
  font-weight: 900;
  letter-spacing: 0.025em;
}
h1 { margin-bottom: 16px; max-width: 900px; font-size: clamp(3rem, 7vw, 5.7rem); line-height: 0.92; text-transform: uppercase; }
h2 { font-size: clamp(2rem, 5vw, 3.6rem); line-height: 0.98; }
.hero-copy { max-width: 760px; margin-bottom: 0; color: #344055; font-size: clamp(1rem, 2.1vw, 1.25rem); line-height: 1.6; }

.game-card {
  overflow: hidden;
  border: 3px solid var(--line);
  border-radius: 15px;
  background: var(--paper-bright);
  box-shadow: var(--shadow);
}
.game-topbar {
  min-height: 74px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px 18px;
  border-bottom: 3px solid var(--line);
}
.game-topbar > div:first-child { display: grid; }
.mode-label { color: var(--blue); font-size: 0.7rem; font-weight: 900; letter-spacing: 0.1em; text-transform: uppercase; }
#puzzle-number { font-size: 1rem; }
.top-actions { display: flex; gap: 10px; }
.icon-button, .primary-button, .secondary-button {
  min-height: 44px;
  border: 2px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
  font-weight: 900;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.icon-button { position: relative; padding: 9px 12px; background: white; color: var(--ink); }
.icon-button:hover, .icon-button:focus-visible { background: #edf1ff; outline: 3px solid rgba(21, 60, 206, 0.22); outline-offset: 2px; }
.icon-button b {
  position: absolute;
  right: -8px;
  top: -10px;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 2px solid white;
  border-radius: 50%;
  background: var(--blue);
  color: white;
  font-size: 0.7rem;
}
.icon-button:disabled { opacity: 0.45; cursor: not-allowed; }

.game-layout {
  display: grid;
  grid-template-columns: minmax(140px, 0.72fr) minmax(300px, 2fr) minmax(170px, 0.88fr);
  gap: clamp(18px, 4vw, 50px);
  align-items: center;
  padding: clamp(22px, 4vw, 52px);
}
.score-rail { display: grid; gap: 22px; align-self: stretch; align-content: center; }
.metric { padding-bottom: 18px; border-bottom: 2px dotted #98a0aa; }
.metric > span, .goal-note > span:first-child, .legend strong { display: block; margin-bottom: 4px; font-size: 0.72rem; font-weight: 950; letter-spacing: 0.1em; }
.metric strong { display: block; color: var(--blue); font-family: Impact, "Arial Black", sans-serif; font-size: clamp(2.2rem, 4vw, 3.75rem); font-variant-numeric: tabular-nums; letter-spacing: 0.025em; }
.metric strong small { margin-left: 3px; font-size: 0.4em; }
.goal-note { padding: 16px; border: 1px solid #cfc9be; border-radius: 8px; background: #fffaf0; }
.goal-note p { margin-bottom: 14px; font-size: 0.88rem; line-height: 1.45; }
.mini-grid { color: var(--blue); font-size: 0.8rem; line-height: 1.1; letter-spacing: 0.12em; }

.board-column { min-width: 0; display: grid; justify-items: center; gap: 15px; }
.board {
  width: min(100%, 520px);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: clamp(4px, 0.8vw, 7px);
  padding: clamp(6px, 1vw, 10px);
  border: 3px solid var(--line);
  border-radius: 10px;
  background: var(--ink);
  box-shadow: 8px 8px 0 rgba(7, 23, 48, 0.92);
}
.tile {
  min-width: 0;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  position: relative;
  border: 0;
  border-radius: 4px;
  background: var(--paper-bright);
  color: var(--ink);
  cursor: pointer;
  font-family: Impact, "Arial Black", sans-serif;
  font-size: clamp(2.25rem, 7vw, 5rem);
  line-height: 1;
  transition: transform 130ms ease, background-color 130ms ease, color 130ms ease;
}
.tile::after {
  content: "";
  width: 30%;
  height: 5px;
  position: absolute;
  bottom: 10%;
  left: 35%;
  border-radius: 99px;
  background: transparent;
}
.tile[data-grade="correct"] { background: var(--green); }
.tile[data-grade="correct"]::after { background: #087541; }
.tile[data-grade="in-row"] { background: var(--orange); }
.tile[data-grade="in-row"]::after { background: #ce4e00; }
.tile:hover { transform: translateY(-2px); }
.tile:focus-visible { z-index: 2; outline: 4px solid var(--blue); outline-offset: -4px; }
.tile.selected { z-index: 3; outline: 5px solid var(--blue); outline-offset: -3px; transform: translate(-3px, -3px); box-shadow: 4px 4px 0 var(--ink); }
.tile.swap-pop { animation: swap-pop 260ms ease; }
@keyframes swap-pop { 50% { transform: scale(0.86) rotate(-2deg); } }

.move-prompt { margin: 2px 0 0; color: var(--muted); font-size: 0.78rem; font-weight: 800; text-align: center; }
.game-message { min-height: 24px; color: var(--blue-dark); font-size: 0.88rem; font-weight: 800; text-align: center; }
.game-message.error { color: #b52a2a; }

.legend { display: grid; gap: 24px; }
.legend > div { display: grid; grid-template-columns: 32px 1fr; column-gap: 10px; }
.legend > div p { grid-column: 2; margin: 0; color: #3f4856; font-size: 0.82rem; line-height: 1.45; }
.swatch { width: 29px; height: 6px; margin-top: 5px; border-radius: 99px; background: #a5acb5; }
.swatch-row { background: var(--orange); }
.swatch-correct { background: var(--green); }
.new-puzzle { width: 100%; }

.primary-button, .secondary-button { padding: 11px 17px; }
.primary-button { background: var(--blue); color: white; box-shadow: 3px 3px 0 var(--ink); }
.primary-button:hover, .primary-button:focus-visible { background: var(--blue-dark); outline: 3px solid rgba(21, 60, 206, 0.2); outline-offset: 3px; }
.secondary-button { background: white; color: var(--ink); }
.secondary-button:hover, .secondary-button:focus-visible { background: #edf1ff; outline: 3px solid rgba(21, 60, 206, 0.2); outline-offset: 3px; }

.result-panel {
  width: min(100%, 520px);
  padding: 22px;
  border: 3px solid var(--line);
  border-radius: 9px;
  background: #edf1ff;
  box-shadow: var(--soft-shadow);
  text-align: center;
}
.result-panel h2 { margin-bottom: 8px; font-size: 2.5rem; }
.result-panel p:not(.eyebrow) { margin-bottom: 18px; color: #38455b; }
.result-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; }

.rule-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px 24px;
  border-top: 3px solid var(--line);
  background: #edf1ff;
}
.rule-strip span { width: 30px; height: 30px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; background: var(--blue); color: white; }
.rule-strip p { margin: 0; font-size: clamp(0.8rem, 1.8vw, 1rem); text-align: center; }

.content-section { padding: clamp(70px, 10vw, 126px) 0; }
.content-section + .content-section { border-top: 2px solid var(--line); }
.section-heading { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 12px 30px; margin-bottom: 38px; }
.section-heading .eyebrow { grid-column: 1 / -1; margin-bottom: -2px; }
.section-heading h2 { margin-bottom: 0; }
.section-heading a { color: var(--blue); font-weight: 900; text-underline-offset: 5px; }

.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin: 0; padding: 0; list-style: none; }
.steps li { min-height: 240px; padding: 26px; border: 2px solid var(--line); border-radius: 9px; background: var(--paper-bright); box-shadow: var(--soft-shadow); }
.steps li > span { display: block; margin-bottom: 45px; color: var(--blue); font-family: Impact, "Arial Black", sans-serif; font-size: 2.2rem; }
.steps h3 { margin-bottom: 8px; font-size: 1.15rem; }
.steps p { margin: 0; color: #4d5765; line-height: 1.55; }

.faq-list { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 18px; }
details { border: 2px solid var(--line); border-radius: 7px; background: var(--paper-bright); }
summary { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 13px 16px; cursor: pointer; font-weight: 900; list-style: none; }
summary::-webkit-details-marker { display: none; }
summary::after { content: "+"; color: var(--blue); font-size: 1.5rem; }
details[open] summary::after { content: "−"; }
details p { margin: 0; padding: 0 16px 18px; color: #4d5765; line-height: 1.6; }

.stats-band { display: flex; justify-content: space-between; align-items: center; gap: 30px; margin-bottom: 100px; padding: clamp(26px, 5vw, 52px); border: 3px solid var(--line); border-radius: 12px; background: var(--blue); color: white; box-shadow: var(--shadow); }
.stats-band .eyebrow { color: #ffbe82; }
.stats-band h2 { margin: 0; }
.stats-band dl { display: grid; grid-template-columns: repeat(3, minmax(90px, 1fr)); gap: 14px; margin: 0; }
.stats-band dl div { min-width: 90px; padding: 12px; border: 2px solid white; border-radius: 7px; text-align: center; }
.stats-band dt { font-size: 0.7rem; font-weight: 900; letter-spacing: 0.09em; text-transform: uppercase; }
.stats-band dd { margin: 4px 0 0; font-family: Impact, "Arial Black", sans-serif; font-size: 2rem; }

footer { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 20px 36px; padding: 34px clamp(20px, 5vw, 72px); border-top: 3px solid var(--line); background: var(--paper-bright); }
.brand.compact .brand-mark { width: 42px; font-size: 1.35rem; }
.brand.compact strong { font-size: 1.1rem; }
footer p, footer small { margin: 0; color: var(--muted); font-size: 0.8rem; }

@media (max-width: 900px) {
  .site-header nav { display: none; }
  .game-layout { grid-template-columns: 1fr; padding: 20px; }
  .score-rail { grid-template-columns: 1fr 1fr; gap: 12px; order: -1; }
  .metric { padding: 10px 14px; border: 2px solid var(--line); border-radius: 7px; text-align: center; }
  .metric strong { font-size: 2rem; }
  .goal-note { display: none; }
  .legend { grid-template-columns: repeat(3, 1fr); gap: 10px; }
  .legend > div { grid-template-columns: 20px 1fr; column-gap: 6px; }
  .legend > div p { font-size: 0.72rem; }
  .swatch { width: 18px; }
  .new-puzzle { grid-column: 1 / -1; }
  .steps { grid-template-columns: 1fr; }
  .steps li { min-height: 0; }
  .steps li > span { margin-bottom: 22px; }
  .stats-band { align-items: stretch; flex-direction: column; }
  footer { grid-template-columns: 1fr; text-align: center; justify-items: center; }
}

@media (max-width: 560px) {
  .site-header { min-height: 70px; padding: 12px 16px; }
  .brand-mark { width: 42px; font-size: 1.4rem; }
  .brand strong { font-size: 1.08rem; }
  .brand > span:last-child small { font-size: 0.52rem; }
  main { width: min(100% - 20px, 1180px); }
  .hero { padding-top: 28px; }
  h1 { font-size: clamp(2.65rem, 13vw, 3.8rem); }
  .game-card { box-shadow: 5px 5px 0 var(--ink); }
  .game-topbar { padding: 10px 12px; }
  .icon-button span { display: none; }
  #hint-button span { display: inline; }
  .icon-button { min-width: 44px; padding: 8px 10px; }
  .game-layout { gap: 16px; padding: 14px 10px 18px; }
  .board { width: min(100%, 390px); gap: 4px; padding: 5px; box-shadow: 5px 5px 0 var(--ink); }
  .tile { min-height: 58px; font-size: clamp(2.3rem, 16vw, 4rem); }
  .tile::after { height: 4px; }
  .legend { grid-template-columns: 1fr; padding: 2px 8px; }
  .legend > div { grid-template-columns: 24px 95px 1fr; align-items: center; }
  .legend > div p { grid-column: 3; }
  .rule-strip { align-items: flex-start; padding: 13px 12px; }
  .rule-strip p { text-align: left; line-height: 1.45; }
  .section-heading { grid-template-columns: 1fr; }
  .faq-list { grid-template-columns: 1fr; }
  .stats-band dl { gap: 7px; }
  .stats-band dl div { min-width: 0; padding: 9px 5px; }
  footer nav { flex-wrap: wrap; justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
