:root {
  color-scheme: light;
  --cabinet: #124b53;
  --cabinet-deep: #0b363c;
  --panel: #d8e2df;
  --chalk: #f7faf8;
  --ink: #15262a;
  --muted: #52666a;
  --correct: #79b9ae;
  --wrong: #b64235;
  --brass: #e6b84c;
  --line: rgba(21, 38, 42, 0.2);
  --rail-height: 64px;
  --z-rail: 20;
  --z-dialog: 40;
  --z-toast: 50;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--panel);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  background: var(--panel);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
select {
  font: inherit;
}

button,
a,
select {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button {
  color: inherit;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

:focus-visible {
  outline: 3px solid var(--cabinet-deep);
  outline-offset: 2px;
  box-shadow: 0 0 0 6px var(--chalk);
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: var(--rail-height) minmax(0, 1fr);
}

.utility-rail {
  position: relative;
  z-index: var(--z-rail);
  display: grid;
  grid-template-columns: minmax(44px, 1fr) auto minmax(160px, 1fr);
  align-items: center;
  min-height: var(--rail-height);
  padding: 0 18px;
  background: var(--chalk);
  border-bottom: 1px solid var(--line);
}

.back-link {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 10px;
  color: var(--ink);
  font-weight: 750;
  text-decoration: none;
  border-radius: 8px;
}

.back-link:hover {
  background: rgba(18, 75, 83, 0.08);
}

.back-arrow {
  font-size: 1.25rem;
  line-height: 1;
}

.brand-lockup {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 11px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  background: var(--cabinet);
  color: var(--chalk);
  border-radius: 6px;
  font: 900 0.92rem/1 ui-monospace, Consolas, monospace;
}

.brand-copy {
  min-width: 0;
}

.brand-copy strong,
.brand-copy span {
  display: block;
}

.brand-copy strong {
  font-size: 0.94rem;
  line-height: 1.15;
  text-wrap: balance;
}

.brand-copy span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.1;
}

.rail-actions {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 8px;
}

.rail-button,
.icon-button,
.round-button,
.dialog-close {
  min-height: 44px;
  border: 0;
  cursor: pointer;
}

.rail-button {
  padding: 0 15px;
  border-radius: 8px;
  background: var(--cabinet);
  color: var(--chalk);
  font-weight: 800;
}

.rail-button:hover {
  background: var(--cabinet-deep);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  padding: 0;
  border-radius: 8px;
  background: transparent;
}

.icon-button:hover {
  background: rgba(18, 75, 83, 0.1);
}

.icon-button svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
}

.game-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(330px, 38%) minmax(0, 1fr);
}

.plotter-panel {
  position: relative;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(230px, 1fr) auto;
  padding: clamp(22px, 3vw, 42px);
  background: var(--cabinet);
  color: var(--chalk);
}

.plotter-panel::after {
  content: "";
  position: absolute;
  inset: auto -70px -92px auto;
  width: 220px;
  height: 220px;
  border: 34px solid rgba(247, 250, 248, 0.06);
  border-radius: 50%;
  pointer-events: none;
}

.plotter-head {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.panel-label {
  margin: 0 0 6px;
  color: rgba(247, 250, 248, 0.74);
  font-size: 0.77rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.plotter-head h1 {
  margin: 0;
  max-width: 16ch;
  font-size: clamp(1.35rem, 2.4vw, 2.1rem);
  line-height: 1.05;
  letter-spacing: -0.03em;
  text-wrap: balance;
}

.error-counter {
  flex: 0 0 auto;
  display: flex;
  align-items: baseline;
  gap: 5px;
  color: var(--chalk);
  font: 800 1.2rem/1 ui-monospace, Consolas, monospace;
}

.error-counter span:first-child {
  font-size: 2rem;
}

.plotter-stage {
  position: relative;
  z-index: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 10px 0 4px;
}

.plotter-svg {
  display: block;
  width: min(100%, 410px);
  height: min(100%, 390px);
  min-height: 220px;
}

.plotter-structure {
  fill: none;
  stroke: rgba(247, 250, 248, 0.9);
  stroke-width: 8;
  stroke-linecap: square;
  stroke-linejoin: round;
}

.plotter-detail {
  fill: none;
  stroke: rgba(247, 250, 248, 0.34);
  stroke-width: 3;
}

.figure-part {
  fill: none;
  stroke: var(--brass);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transition:
    stroke-dashoffset 220ms cubic-bezier(0.16, 1, 0.3, 1),
    opacity 100ms linear;
}

.figure-part.is-drawn {
  opacity: 1;
  stroke-dashoffset: 0;
}

.plotter-pen {
  fill: var(--brass);
  transition: transform 220ms cubic-bezier(0.16, 1, 0.3, 1);
}

.plotter-stage.is-wrong .plotter-pen {
  transform: translateY(7px);
}

.strike-bank {
  position: relative;
  z-index: 1;
  padding-top: 18px;
  border-top: 1px solid rgba(247, 250, 248, 0.24);
}

.strike-copy {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
  font-size: 0.82rem;
  font-weight: 700;
}

.strike-copy span:last-child {
  color: rgba(247, 250, 248, 0.72);
}

.strike-lamps {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: clamp(8px, 1.2vw, 14px);
  margin: 0;
  padding: 0;
  list-style: none;
}

.strike-lamp {
  position: relative;
  aspect-ratio: 1;
  max-width: 54px;
  border: 2px solid rgba(247, 250, 248, 0.44);
  border-radius: 50%;
  background: var(--cabinet-deep);
}

.strike-lamp::after {
  content: "";
  position: absolute;
  inset: 22%;
  border-radius: 50%;
  background: rgba(247, 250, 248, 0.18);
  transition: background 180ms ease-out, transform 180ms ease-out;
}

.strike-lamp.is-lit {
  border-color: #f2a096;
}

.strike-lamp.is-lit::after {
  background: var(--wrong);
  transform: scale(1.12);
}

.word-console {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  padding: clamp(24px, 4.4vw, 64px);
  background: var(--panel);
}

.console-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: clamp(18px, 3vh, 30px);
  border-bottom: 1px solid var(--line);
}

.hint-block {
  min-width: 0;
}

.hint-label,
.wrong-label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.hint-value {
  margin: 0;
  max-width: 56ch;
  font-size: clamp(1rem, 1.5vw, 1.25rem);
  font-weight: 750;
  line-height: 1.35;
  text-wrap: pretty;
}

.remaining-copy {
  flex: 0 0 auto;
  display: flex;
  align-items: baseline;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

.remaining-copy strong {
  color: var(--ink);
  font: 900 1.65rem/1 ui-monospace, Consolas, monospace;
}

.puzzle-zone {
  min-height: 0;
  display: grid;
  align-content: center;
  gap: 24px;
  padding: clamp(26px, 5vh, 58px) 0;
}

.mode-ticket {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin: 0;
  color: var(--cabinet);
  font-size: 0.78rem;
  font-weight: 850;
}

.mode-ticket::before {
  content: "";
  width: 9px;
  height: 9px;
  background: var(--brass);
  border-radius: 50%;
}

.word-slots {
  --letters: 10;
  display: grid;
  grid-template-columns: repeat(var(--letters), minmax(0, 1fr));
  gap: clamp(5px, 0.8vw, 11px);
  width: 100%;
  max-width: min(820px, calc(var(--letters) * 72px));
}

.letter-slot {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  aspect-ratio: 0.82;
  overflow: hidden;
  border-bottom: 4px solid var(--ink);
  background: rgba(247, 250, 248, 0.66);
  font: 900 clamp(1.15rem, 3.1vw, 2.55rem)/1 ui-monospace, Consolas, monospace;
  text-transform: uppercase;
}

.letter-slot.is-hidden {
  color: transparent;
}

.letter-slot.is-hidden::after {
  content: "";
  width: 24%;
  height: 3px;
  background: rgba(21, 38, 42, 0.35);
}

.letter-slot.is-revealed {
  animation: flap-in 240ms cubic-bezier(0.16, 1, 0.3, 1);
}

.letter-slot.is-answer {
  background: rgba(182, 66, 53, 0.14);
  border-color: var(--wrong);
}

.feedback {
  min-height: 54px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  font-size: clamp(0.94rem, 1.45vw, 1.15rem);
  font-weight: 780;
  line-height: 1.35;
}

.feedback::before {
  content: "";
  flex: 0 0 10px;
  width: 10px;
  height: 10px;
  background: var(--brass);
  border-radius: 50%;
}

.feedback[data-tone="correct"]::before,
.feedback[data-tone="win"]::before {
  background: var(--correct);
}

.feedback[data-tone="wrong"]::before,
.feedback[data-tone="lose"]::before {
  background: var(--wrong);
}

.feedback[data-tone="win"],
.feedback[data-tone="lose"] {
  min-height: 60px;
  padding: 12px 16px;
  border: 2px solid currentColor;
  border-radius: 8px;
}

.key-bank {
  padding: clamp(18px, 3vh, 28px) 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.keyboard {
  display: grid;
  grid-template-columns: repeat(13, minmax(42px, 1fr));
  gap: 8px;
  width: 100%;
  max-width: 900px;
}

.letter-key {
  position: relative;
  min-width: 0;
  min-height: 48px;
  padding: 0;
  border: 1px solid rgba(21, 38, 42, 0.42);
  border-radius: 7px;
  background: var(--chalk);
  color: var(--ink);
  cursor: pointer;
  font: 850 1rem/1 ui-monospace, Consolas, monospace;
  transition:
    background 160ms ease-out,
    color 160ms ease-out,
    transform 120ms ease-out;
}

.letter-key:hover:not(:disabled) {
  background: #eef4f1;
  transform: translateY(-2px);
}

.letter-key:active:not(:disabled) {
  transform: translateY(1px);
}

.letter-key.is-correct {
  border-color: var(--correct);
  background: var(--correct);
}

.letter-key.is-wrong {
  border-color: var(--wrong);
  background: var(--wrong);
  color: var(--chalk);
}

.letter-key:disabled {
  cursor: default;
}

.letter-key:disabled:not(.is-correct):not(.is-wrong) {
  color: rgba(21, 38, 42, 0.48);
  background: rgba(247, 250, 248, 0.52);
}

.console-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding-top: clamp(18px, 3vh, 30px);
}

.wrong-rack {
  min-width: 0;
}

.wrong-letters {
  min-height: 1.3em;
  color: var(--wrong);
  font: 850 0.98rem/1.3 ui-monospace, Consolas, monospace;
  letter-spacing: 0.18em;
  overflow-wrap: anywhere;
}

.round-button {
  flex: 0 0 auto;
  min-width: 160px;
  padding: 0 22px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--chalk);
  font-weight: 850;
}

.round-button:hover {
  background: var(--cabinet);
}

.version-info {
  position: fixed;
  z-index: var(--z-rail);
  right: 8px;
  bottom: 6px;
  color: rgba(21, 38, 42, 0.52);
  font: 700 0.62rem/1 ui-monospace, Consolas, monospace;
  pointer-events: none;
}

.settings-dialog {
  width: min(92vw, 480px);
  max-height: min(84vh, 620px);
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: var(--chalk);
  color: var(--ink);
}

.settings-dialog::backdrop {
  background: rgba(11, 54, 60, 0.68);
}

.settings-panel {
  padding: 24px;
}

.settings-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.settings-head h2 {
  margin: 0;
  font-size: 1.3rem;
  letter-spacing: -0.02em;
}

.settings-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.dialog-close {
  display: grid;
  place-items: center;
  width: 44px;
  padding: 0;
  border-radius: 8px;
  background: rgba(18, 75, 83, 0.08);
  font-size: 1.25rem;
}

.settings-row {
  display: grid;
  gap: 8px;
  padding: 22px 0;
}

.settings-row + .settings-row {
  border-top: 1px solid var(--line);
}

.settings-row label,
.settings-row strong {
  font-size: 0.9rem;
  font-weight: 800;
}

.settings-row select {
  width: 100%;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid rgba(21, 38, 42, 0.38);
  border-radius: 7px;
  background: white;
  color: var(--ink);
  font-size: 1rem;
}

.settings-version {
  color: var(--muted);
  font: 750 0.88rem/1.4 ui-monospace, Consolas, monospace;
}

@keyframes flap-in {
  0% {
    transform: perspective(220px) rotateX(-76deg);
    opacity: 0.25;
  }
  100% {
    transform: perspective(220px) rotateX(0);
    opacity: 1;
  }
}

@media (max-width: 820px) {
  :root {
    --rail-height: 56px;
  }

  .utility-rail {
    grid-template-columns: 44px minmax(0, 1fr) auto;
    padding: 0 8px;
  }

  .back-link {
    width: 44px;
    padding: 0;
    justify-content: center;
  }

  .back-text,
  .brand-copy span,
  .rail-button {
    display: none;
  }

  .brand-lockup {
    justify-self: start;
    margin-left: 8px;
  }

  .game-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(205px, 31vh) auto;
  }

  .plotter-panel {
    grid-template-columns: minmax(0, 1fr) minmax(190px, 45%);
    grid-template-rows: auto 1fr;
    gap: 6px 18px;
    min-height: 205px;
    padding: 17px 18px;
  }

  .plotter-head {
    grid-column: 1;
    align-self: start;
  }

  .plotter-head h1 {
    font-size: 1.24rem;
  }

  .error-counter {
    position: absolute;
    top: 18px;
    right: 18px;
  }

  .error-counter span:first-child {
    font-size: 1.5rem;
  }

  .plotter-stage {
    grid-column: 2;
    grid-row: 1 / 3;
    padding: 0;
  }

  .plotter-svg {
    min-height: 175px;
    height: 100%;
  }

  .strike-bank {
    grid-column: 1;
    align-self: end;
    padding-top: 12px;
  }

  .strike-copy {
    margin-bottom: 8px;
  }

  .strike-lamps {
    gap: 7px;
  }

  .word-console {
    min-height: calc(69vh - var(--rail-height));
    padding: 22px 18px calc(30px + env(safe-area-inset-bottom));
  }

  .console-head {
    padding-bottom: 16px;
  }

  .puzzle-zone {
    gap: 16px;
    padding: 22px 0;
  }

  .word-slots {
    gap: 5px;
  }

  .letter-slot {
    min-height: 45px;
    border-bottom-width: 3px;
    font-size: clamp(1rem, 6.2vw, 1.65rem);
  }

  .keyboard {
    grid-template-columns: repeat(7, minmax(44px, 1fr));
    gap: 7px;
  }

  .letter-key {
    min-height: 46px;
  }
}

@media (max-width: 430px) {
  .brand-mark {
    width: 28px;
    height: 28px;
  }

  .brand-copy strong {
    max-width: 16ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .plotter-panel {
    grid-template-columns: minmax(0, 1fr) 145px;
  }

  .panel-label {
    font-size: 0.69rem;
  }

  .plotter-head h1 {
    max-width: 11ch;
    font-size: 1.08rem;
  }

  .strike-copy span:last-child {
    display: none;
  }

  .remaining-copy span {
    display: none;
  }

  .feedback {
    min-height: 46px;
  }

  .key-bank {
    padding: 15px 0;
  }

  .console-footer {
    align-items: flex-end;
    gap: 12px;
  }

  .round-button {
    min-width: 132px;
    padding: 0 14px;
  }
}

@media (orientation: landscape) and (max-height: 560px) {
  :root {
    --rail-height: 48px;
  }

  .utility-rail {
    min-height: 48px;
    padding-inline: 8px;
  }

  .back-link,
  .icon-button {
    min-height: 40px;
    height: 40px;
  }

  .game-layout {
    grid-template-columns: minmax(245px, 34%) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    height: calc(100dvh - var(--rail-height));
  }

  .plotter-panel {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr) auto;
    min-height: 0;
    padding: 13px 18px;
  }

  .plotter-head {
    grid-column: 1;
    grid-row: 1;
  }

  .plotter-head h1 {
    font-size: 1rem;
  }

  .panel-label,
  .strike-copy {
    display: none;
  }

  .error-counter {
    position: static;
  }

  .plotter-stage {
    grid-column: 1;
    grid-row: 2;
    min-height: 0;
  }

  .plotter-svg {
    min-height: 0;
    height: 100%;
  }

  .strike-bank {
    grid-column: 1;
    grid-row: 3;
    padding-top: 7px;
  }

  .strike-lamps {
    gap: 7px;
  }

  .word-console {
    min-height: 0;
    height: 100%;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    padding: 11px 18px 14px;
    overflow: hidden;
  }

  .console-head {
    align-items: center;
    padding-bottom: 8px;
  }

  .hint-label {
    display: inline;
    margin: 0 5px 0 0;
  }

  .hint-value {
    display: inline;
    font-size: 0.86rem;
  }

  .puzzle-zone {
    gap: 7px;
    padding: 8px 0;
  }

  .mode-ticket {
    font-size: 0.68rem;
  }

  .word-slots {
    max-width: min(680px, calc(var(--letters) * 58px));
  }

  .letter-slot {
    min-height: 34px;
    max-height: 48px;
    font-size: clamp(0.92rem, 3vw, 1.5rem);
  }

  .feedback {
    min-height: 24px;
    font-size: 0.78rem;
  }

  .feedback[data-tone="win"],
  .feedback[data-tone="lose"] {
    min-height: 34px;
    padding: 5px 9px;
  }

  .key-bank {
    padding: 7px 0;
  }

  .keyboard {
    grid-template-columns: repeat(9, minmax(33px, 1fr));
    gap: 4px;
  }

  .letter-key {
    min-height: 34px;
    font-size: 0.82rem;
  }

  .console-footer {
    padding-top: 8px;
  }

  .wrong-label {
    display: none;
  }

  .wrong-letters {
    font-size: 0.8rem;
  }

  .round-button {
    min-height: 36px;
    min-width: 126px;
    padding: 0 12px;
    font-size: 0.78rem;
  }

  .version-info {
    display: none;
  }
}

@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;
  }

  .figure-part {
    stroke-dasharray: none;
    stroke-dashoffset: 0;
  }
}
