:root {
  --bg: #090b12;
  --bg-2: #0d1019;
  --surface: #141824;
  --surface-2: #10131d;
  --surface-3: #191d2b;
  --border: #262b39;
  --border-strong: #3a4052;
  --text: #f1f1f4;
  --muted: #9699a6;
  --faint: #646877;
  --indigo: #756cff;
  --pink: #f16bb7;
  --purple: #c28aff;
  --teal: #31d7c2;
  --amber: #ffc24a;
  --blue: #65aaff;
  --coral: var(--pink);
  --saffron: var(--amber);
  --cobalt: var(--indigo);
  --sage: var(--teal);
  --sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --serif: Newsreader, Georgia, "Times New Roman", serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
  --ease: cubic-bezier(.16, .84, .44, 1);
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--bg); color-scheme: dark; }

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  background:
    radial-gradient(58rem 50rem at 82% -8%, rgba(117, 108, 255, .17), transparent 60%),
    radial-gradient(50rem 46rem at 2% 8%, rgba(241, 107, 183, .11), transparent 62%),
    radial-gradient(55rem 42rem at 50% 110%, rgba(49, 215, 194, .065), transparent 66%),
    var(--bg);
  font: 16px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body::before {
  content: "";
  position: fixed;
  z-index: -1;
  inset: 0;
  pointer-events: none;
  opacity: .36;
  background-image: radial-gradient(rgba(255, 255, 255, .5) .55px, transparent .55px);
  background-size: 48px 48px;
  mask-image: radial-gradient(80rem 60rem at 50% 0, #000, transparent 74%);
}

button { font: inherit; }
a { color: inherit; }
button:focus-visible { outline: 2px solid var(--indigo); outline-offset: 3px; }
::selection { color: #fff; background: rgba(117, 108, 255, .42); }

.game-shell {
  width: min(1120px, calc(100% - 48px));
  min-height: 100vh;
  margin: 0 auto;
}

.topbar {
  position: relative;
  z-index: 10;
  height: 68px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  border-bottom: 1px solid var(--border);
}

.wordmark {
  justify-self: start;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0;
  border: 0;
  color: var(--text);
  background: transparent;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -.025em;
  cursor: pointer;
}

.zimac-glyph {
  width: 31px;
  height: 31px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  color: #fff;
  background: linear-gradient(145deg, var(--indigo), var(--pink));
  box-shadow: 0 0 24px rgba(117, 108, 255, .4), inset 0 1px 0 rgba(255, 255, 255, .25);
  font-size: 16px;
}

.wordmark-by {
  margin-left: 1px;
  color: var(--faint);
  font-size: 11px;
  font-weight: 550;
  letter-spacing: 0;
}
.wordmark-by span {
  background: linear-gradient(90deg, var(--pink), var(--indigo));
  background-clip: text;
  color: transparent;
}

.puzzle-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font: 700 10px/1.2 var(--mono);
  letter-spacing: .13em;
}
.meta-divider { width: 1px; height: 17px; background: var(--border-strong); }

.round-button {
  justify-self: end;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 11px;
  color: var(--muted);
  background: rgba(255, 255, 255, .035);
  font-weight: 700;
  cursor: pointer;
  transition: color .2s, border-color .2s, background .2s, transform .16s;
}
.round-button:hover { color: var(--text); border-color: var(--border-strong); background: rgba(255, 255, 255, .075); transform: translateY(-1px); }

.intro { max-width: 820px; margin: 0 auto; padding: 72px 16px 44px; text-align: center; }
.eyebrow {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .17em;
}
.eyebrow span { width: 22px; height: 1px; background: var(--border-strong); }
.intro h1 {
  margin: 20px 0 16px;
  font-size: clamp(48px, 7vw, 76px);
  font-weight: 650;
  line-height: .99;
  letter-spacing: -.055em;
}
.gradient-text {
  background: linear-gradient(105deg, #fff 4%, var(--pink) 55%, var(--indigo));
  background-clip: text;
  color: transparent;
}
.intro p { max-width: 590px; margin: 0 auto; color: var(--muted); font-size: 17px; line-height: 1.65; }

.play-surface {
  position: relative;
  width: min(960px, 100%);
  margin: 0 auto;
  padding: 26px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 24px;
  background:
    linear-gradient(160deg, rgba(25, 29, 43, .96), rgba(13, 16, 25, .98)),
    var(--surface-2);
  box-shadow: 0 36px 100px rgba(0, 0, 0, .34), inset 0 1px 0 rgba(255, 255, 255, .035);
}
.play-surface::before {
  content: "";
  position: absolute;
  top: -180px;
  right: -140px;
  width: 430px;
  height: 430px;
  border-radius: 50%;
  background: rgba(117, 108, 255, .085);
  filter: blur(1px);
  pointer-events: none;
}

.progress { position: relative; margin: 0 0 28px; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.progress-labels, .progress-row { display: flex; align-items: center; justify-content: space-between; }
.progress-labels { margin-bottom: 10px; color: var(--faint); font: 700 9px/1 var(--mono); letter-spacing: .14em; }
.progress-track { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; flex: 1; margin-right: 42px; }
.progress-track span { height: 4px; border-radius: 999px; background: var(--border); transition: background .35s, box-shadow .35s; }
.progress-track .coral { background: var(--coral); box-shadow: 0 0 11px rgba(241, 107, 183, .45); }
.progress-track .saffron { background: var(--saffron); box-shadow: 0 0 11px rgba(255, 194, 74, .38); }
.progress-track .cobalt { background: var(--cobalt); box-shadow: 0 0 11px rgba(117, 108, 255, .45); }
.progress-track .sage { background: var(--sage); box-shadow: 0 0 11px rgba(49, 215, 194, .38); }
.mistake-dots { display: flex; gap: 8px; }
.mistake-dots span { width: 9px; height: 9px; display: block; border: 1px solid var(--muted); border-radius: 50%; background: var(--muted); transition: .2s; }
.mistake-dots span.spent { border-color: var(--border-strong); background: transparent; }

.section-heading { display: flex; align-items: baseline; justify-content: space-between; margin: 0 0 13px; }
.section-heading h2 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: -.015em; }
.section-heading > span { color: var(--faint); font: 700 9px/1 var(--mono); letter-spacing: .14em; }

.chain-section { position: relative; margin-bottom: 30px; }
.chain { display: grid; grid-template-columns: repeat(4, 1fr); gap: 31px; }
.chain-piece { position: relative; min-width: 0; }
.group-card {
  min-height: 122px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 17px;
  border: 1px dashed var(--border-strong);
  border-radius: 14px;
  color: var(--faint);
  background: rgba(9, 11, 18, .28);
  text-align: center;
}
.group-card.visible {
  display: block;
  color: var(--text);
  border-style: solid;
  background: linear-gradient(180deg, rgba(28, 32, 47, .96), rgba(17, 20, 30, .96));
  box-shadow: 0 12px 34px rgba(0, 0, 0, .2), inset 0 1px 0 rgba(255, 255, 255, .04);
  text-align: left;
  animation: settle .35s var(--ease) both;
}
.group-card.visible.coral { border-color: rgba(241, 107, 183, .56); box-shadow: inset 0 2px 0 var(--coral), 0 12px 34px rgba(0, 0, 0, .2); }
.group-card.visible.saffron { border-color: rgba(255, 194, 74, .5); box-shadow: inset 0 2px 0 var(--saffron), 0 12px 34px rgba(0, 0, 0, .2); }
.group-card.visible.cobalt { border-color: rgba(117, 108, 255, .58); box-shadow: inset 0 2px 0 var(--cobalt), 0 12px 34px rgba(0, 0, 0, .2); }
.group-card.visible.sage { border-color: rgba(49, 215, 194, .48); box-shadow: inset 0 2px 0 var(--sage), 0 12px 34px rgba(0, 0, 0, .2); }
.group-card.hidden-card span, .group-number { font: 700 9px/1 var(--mono); letter-spacing: .12em; }
.group-number { color: var(--faint); }
.group-card h3 { margin: 12px 0 11px; font-size: 15px; font-weight: 650; line-height: 1.2; }
.group-card p { margin: 0; color: var(--muted); font: 650 8px/1.55 var(--mono); letter-spacing: .045em; }

.hinge-link { position: absolute; z-index: 3; left: calc(100% + 1px); top: 52px; width: 29px; display: flex; flex-direction: column; align-items: center; color: var(--border-strong); }
.hinge-link i { width: 1px; height: 7px; display: block; background: currentColor; }
.hinge-link b { min-width: 25px; height: 18px; padding: 4px 4px 0; border: 1px solid currentColor; border-radius: 5px; color: var(--muted); background: var(--bg-2); font: 700 7px/1 var(--mono); text-align: center; }
.hinge-link.known { color: var(--teal); }
.hinge-link.known b { min-width: 45px; color: var(--text); border-color: rgba(49, 215, 194, .58); background: var(--surface); box-shadow: 0 0 18px rgba(49, 215, 194, .18); }

.board-section { position: relative; }
.word-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.word-tile {
  position: relative;
  min-width: 0;
  height: 78px;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: #d9dbe4;
  background: linear-gradient(180deg, rgba(24, 28, 41, .96), rgba(16, 19, 29, .96));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .025), 0 9px 22px rgba(0, 0, 0, .13);
  font-size: clamp(12px, 1.6vw, 14px);
  font-weight: 700;
  letter-spacing: .02em;
  cursor: pointer;
  transition: transform .16s var(--ease), border-color .2s, background .2s, box-shadow .2s;
}
.word-tile:hover { z-index: 1; transform: translateY(-2px); border-color: var(--border-strong); background: linear-gradient(180deg, #1d2232, #151925); box-shadow: 0 13px 28px rgba(0, 0, 0, .2); }
.word-tile.selected {
  color: #fff;
  border-color: rgba(255, 255, 255, .16);
  background: linear-gradient(145deg, var(--indigo), #887dff 58%, var(--pink));
  box-shadow: 0 12px 30px rgba(117, 108, 255, .34), inset 0 1px 0 rgba(255, 255, 255, .25);
  transform: translateY(-2px);
}
.word-tile.active-hinge { border-color: rgba(49, 215, 194, .62); background: linear-gradient(180deg, rgba(49, 215, 194, .1), rgba(16, 19, 29, .96)); box-shadow: 0 0 24px rgba(49, 215, 194, .1); }
.word-tile.active-hinge.selected { background: linear-gradient(145deg, var(--indigo), var(--pink)); }
.hinge-tag { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); color: var(--teal); font: 800 7px/1 var(--mono); letter-spacing: .14em; }
.word-tile.selected .hinge-tag { color: #fff; }

.status-message { height: 22px; margin: 15px 0 9px; color: var(--muted); font-size: 13px; text-align: center; }
.controls { display: flex; align-items: center; justify-content: center; gap: 9px; }
.controls .hint-button { margin-left: 5px; }
.text-button, .primary-button {
  min-height: 43px;
  padding: 0 17px;
  border-radius: 11px;
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
  transition: transform .16s, color .2s, border-color .2s, background .2s, box-shadow .2s;
}
.text-button { border: 1px solid var(--border); color: var(--muted); background: rgba(255, 255, 255, .025); }
.text-button:hover:not(:disabled) { color: var(--text); border-color: var(--border-strong); background: rgba(255, 255, 255, .065); }
.text-button:disabled { opacity: .35; cursor: not-allowed; }
.primary-button {
  border: 1px solid rgba(255, 255, 255, .15);
  color: #fff;
  background: linear-gradient(145deg, var(--indigo), #887dff 58%, var(--pink));
  box-shadow: 0 10px 30px rgba(117, 108, 255, .29), inset 0 1px 0 rgba(255, 255, 255, .24);
}
.primary-button:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 14px 40px rgba(117, 108, 255, .44); }
.primary-button:disabled { color: var(--faint); border-color: var(--border); background: var(--surface); box-shadow: none; cursor: not-allowed; }
.primary-button span { margin-left: 15px; }

.after-game { position: relative; padding: 32px 0 12px; text-align: center; }
.after-game p { margin: 0 0 18px; color: var(--muted); font-size: 16px; }
.after-game > div { display: flex; justify-content: center; gap: 10px; }

footer { min-height: 86px; display: flex; align-items: center; justify-content: space-between; color: var(--faint); font-size: 11px; }
footer button { padding: 7px 0; border: 0; color: var(--muted); background: none; font: 600 11px/1 var(--sans); cursor: pointer; }
footer button:hover { color: var(--text); }
footer a { color: var(--muted); text-underline-offset: 3px; }
footer a:hover { color: var(--text); }

.modal-backdrop { position: fixed; z-index: 30; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(3, 4, 8, .72); backdrop-filter: blur(12px) saturate(125%); animation: fade .2s ease both; }
.modal {
  position: relative;
  width: min(480px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  padding: 38px;
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  color: var(--text);
  background: linear-gradient(155deg, #1a1e2c, #10131d 72%);
  box-shadow: 0 36px 100px rgba(0, 0, 0, .58), inset 0 1px 0 rgba(255, 255, 255, .06);
  animation: lift .3s var(--ease) both;
}
.modal-close { position: absolute; top: 12px; right: 13px; width: 38px; height: 38px; border: 1px solid transparent; border-radius: 10px; color: var(--muted); background: transparent; font-size: 26px; font-weight: 300; cursor: pointer; }
.modal-close:hover { color: var(--text); border-color: var(--border); background: rgba(255, 255, 255, .04); }
.modal-kicker { margin-bottom: 12px; color: var(--purple); font: 750 9px/1 var(--mono); letter-spacing: .15em; }
.modal h2 { margin: 0 0 13px; font-size: 34px; font-weight: 650; line-height: 1.07; letter-spacing: -.035em; }
.modal > p { color: var(--muted); font-size: 14px; line-height: 1.6; }
.how-modal ol { list-style: none; padding: 5px 0 0; margin: 0; counter-reset: rule; }
.how-modal li { counter-increment: rule; position: relative; padding: 14px 0 14px 42px; border-top: 1px solid var(--border); }
.how-modal li::before { content: "0" counter(rule); position: absolute; left: 0; top: 17px; color: var(--purple); font: 700 10px/1 var(--mono); }
.how-modal li b, .how-modal li span { display: block; }
.how-modal li b { margin-bottom: 3px; font-size: 14px; font-weight: 650; }
.how-modal li span { color: var(--muted); font-size: 12px; line-height: 1.48; }
.mini-example { display: flex; align-items: center; justify-content: center; margin: 18px 0 21px; }
.mini-example span, .mini-example b { padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: 8px; font: 700 8px/1 var(--mono); }
.mini-example b { color: #fff; border-color: rgba(255, 255, 255, .14); background: linear-gradient(145deg, var(--indigo), var(--pink)); box-shadow: 0 7px 20px rgba(117, 108, 255, .25); }
.mini-example i { width: 14px; height: 1px; background: var(--border-strong); }
.full-button { width: 100%; margin-top: 8px; }

.result-modal { text-align: center; }
.result-modal .modal-kicker { margin-top: 25px; }
.result-mark { display: flex; align-items: center; justify-content: center; padding-top: 10px; }
.result-mark span { width: 24px; height: 24px; border: 3px solid var(--text); border-radius: 50%; }
.result-mark span:nth-of-type(1) { border-color: var(--coral); }
.result-mark span:nth-of-type(2) { border-color: var(--saffron); }
.result-mark span:nth-of-type(3) { border-color: var(--cobalt); }
.result-mark span:nth-of-type(4) { border-color: var(--sage); }
.result-mark i { width: 19px; height: 3px; background: var(--border-strong); }
.result-mark.broken i:nth-of-type(2) { transform: rotate(-20deg) translateY(8px); background: var(--pink); }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); margin: 25px 0 19px; overflow: hidden; border: 1px solid var(--border); border-radius: 14px; background: rgba(9, 11, 18, .35); }
.result-stats div { padding: 15px 5px; }
.result-stats div + div { border-left: 1px solid var(--border); }
.result-stats b, .result-stats span { display: block; }
.result-stats b { font-size: 27px; font-weight: 650; line-height: 1; }
.result-stats span { margin-top: 6px; color: var(--faint); font: 700 8px/1 var(--mono); letter-spacing: .11em; }

.error-page { display: grid; min-height: 100vh; place-items: center; padding: 24px; }
.error-card {
  width: min(560px, 100%);
  padding: 54px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: linear-gradient(160deg, rgba(25, 29, 43, .96), rgba(13, 16, 25, .98));
  box-shadow: 0 36px 100px rgba(0, 0, 0, .34);
  text-align: center;
}
.error-card .zimac-glyph { margin: 0 auto 28px; }
.error-card h1 { margin: 14px 0; font-size: clamp(38px, 7vw, 58px); line-height: 1; letter-spacing: -.05em; }
.error-card > p:not(.modal-kicker) { margin: 0 auto 28px; color: var(--muted); }
.error-card .primary-button { display: inline-flex; align-items: center; text-decoration: none; }

@keyframes settle { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } }
@keyframes lift { from { opacity: 0; transform: translateY(14px) scale(.985); } }

@media (max-width: 760px) {
  .game-shell { width: min(100% - 24px, 620px); }
  .topbar { height: 62px; }
  .puzzle-meta span:first-child, .meta-divider, .wordmark-by { display: none; }
  .intro { padding: 52px 8px 34px; }
  .intro h1 { margin-top: 17px; font-size: clamp(43px, 12vw, 58px); }
  .intro p { font-size: 15px; }
  .play-surface { padding: 17px; border-radius: 19px; }
  .progress { margin-bottom: 24px; }
  .progress-track { margin-right: 25px; }
  .chain { grid-template-columns: 1fr; gap: 30px; }
  .group-card { min-height: 101px; }
  .hinge-link { left: 50%; top: calc(100% + 1px); transform: translateX(-50%); }
  .word-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .word-tile { height: 68px; font-size: clamp(10px, 3vw, 13px); }
  .controls { flex-wrap: wrap; }
  .controls .primary-button { order: -1; width: 100%; }
  .controls .hint-button { margin-left: 0; }
  .modal { padding: 35px 24px 25px; border-radius: 18px; }
  footer { min-height: 92px; gap: 20px; }
  footer span { max-width: 220px; }
}

@media (max-width: 390px) {
  .word-grid { grid-template-columns: repeat(2, 1fr); }
  .intro p { font-size: 14px; }
  .puzzle-meta { font-size: 9px; }
}

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