:root {
  --ink: #17322c;
  --cream: #f5f0e5;
  --paper: #fffdf7;
  --lime: #d7f43b;
  --orange: #ff6b35;
  --blue: #5cc8ff;
  --line: #c8c5b9;
  --tile-size: min(58px, 5.6vh, calc((100vw - 46px) / 8));
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--cream); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }

.topbar { height: 60px; padding: 0 max(18px, calc((100vw - 1120px) / 2)); display: flex; align-items: center; justify-content: space-between; border-bottom: 2px solid var(--ink); background: var(--paper); }
.brand { display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; font-size: 20px; letter-spacing: .025em; font-weight: 950; }
.brand b { color: var(--orange); }
.brand-mark { display: grid; grid-template-columns: repeat(2, 22px); gap: 2px; transform: rotate(-3deg); }
.brand-mark i { display: grid; place-items: center; height: 25px; background: var(--ink); color: white; font-style: normal; font-size: 13px; }
.brand-mark i:last-child { background: var(--orange); }
.top-actions { display: flex; gap: 8px; }
.icon-button { width: 36px; height: 36px; border: 2px solid var(--ink); border-radius: 50%; background: transparent; color: var(--ink); font-weight: 900; font-size: 16px; cursor: pointer; }
.icon-button:hover { background: var(--lime); }

main { max-width: 1120px; margin: auto; padding: 15px 18px 18px; }
.hero { display: flex; justify-content: space-between; align-items: center; gap: 20px; min-height: 62px; }
.eyebrow { font-size: 10px; font-weight: 950; letter-spacing: .065em; margin: 0 0 5px; color: #46625b; }
.hero h1 { font-size: clamp(27px, 3.6vw, 43px); line-height: .98; letter-spacing: -.045em; margin: 0; }
.hero h1 br { display: block; }
.hero h1 em { font-style: normal; color: var(--orange); }
.timer-card { border: 2px solid var(--ink); background: var(--paper); padding: 7px 13px; min-width: 105px; box-shadow: 3px 3px 0 var(--ink); }
.timer-card span { display: block; font-size: 9px; font-weight: 900; letter-spacing: .15em; }
.timer-card strong { font-variant-numeric: tabular-nums; font-size: 23px; }

.mode-tabs { display: flex; gap: 3px; margin-top: 10px; border-bottom: 2px solid var(--ink); }
.mode-tab { padding: 9px 21px; border: 0; background: transparent; font-weight: 850; color: #6f7d79; cursor: pointer; font-size: 14px; }
.mode-tab.active { background: var(--ink); color: white; }
.mode-tab span { font-size: 7px; color: var(--orange); vertical-align: middle; margin-left: 3px; }

.game-shell { display: grid; grid-template-columns: calc(var(--tile-size) * 8 + 13px) minmax(245px, 1fr); grid-template-areas: "status status" "board rack" "board actions"; align-items: start; justify-content: center; column-gap: clamp(22px, 5vw, 74px); row-gap: 12px; background: var(--paper); border: 2px solid var(--ink); border-top: 0; padding: 13px 20px 15px; }
.status-row { grid-area: status; display: flex; justify-content: space-between; gap: 16px; font-size: 12px; min-height: 18px; }
.completed-share { border: 0; border-bottom: 2px solid var(--orange); padding: 0 0 2px; background: transparent; color: var(--ink); font: inherit; font-size: 12px; font-weight: 900; cursor: pointer; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--orange); margin-right: 7px; }
.board-wrap { grid-area: board; display: flex; justify-content: center; padding: 0; }
.board { width: calc(var(--tile-size) * 8 + 13px); height: calc(var(--tile-size) * 8 + 13px); display: grid; grid-template-columns: repeat(8, var(--tile-size)); grid-template-rows: repeat(8, var(--tile-size)); background: var(--ink); border: 2px solid var(--ink); gap: 1px; padding: 1px; touch-action: manipulation; }
.cell { width: var(--tile-size); height: var(--tile-size); border: 0; background: var(--paper); position: relative; display: grid; place-items: center; padding: 0; cursor: pointer; }
.cell:hover { background: #f1eee5; }
.cell:focus-visible { outline: 3px solid var(--blue); z-index: 2; }
.cell.filled { background: var(--lime); }

.tile { width: var(--tile-size); height: var(--tile-size); min-width: var(--tile-size); min-height: var(--tile-size); border: 2px solid var(--ink); background: var(--lime); color: var(--ink); display: grid; place-items: center; padding: 0; font-size: calc(var(--tile-size) * .48); line-height: 1; font-weight: 950; box-shadow: 3px 3px 0 var(--ink); user-select: none; -webkit-user-select: none; touch-action: none; cursor: grab; }
.tile:active { cursor: grabbing; }
.tile.selected { outline: 4px solid var(--orange); outline-offset: -5px; }
.tile.vowel { background: var(--blue); }
.cell .tile { width: 100%; height: 100%; min-width: 100%; min-height: 100%; border: 0; box-shadow: none; }
.cell.invalid .tile { background: #ff9d88; animation: shake .3s; }
.cell.drag-target { outline: 4px solid var(--orange); outline-offset: -4px; }
.drag-ghost { position: fixed; z-index: 9999; pointer-events: none; opacity: .88; transform: rotate(4deg) scale(1.04); box-shadow: 6px 7px 0 rgba(23,50,44,.45); }

.rack-section { grid-area: rack; align-self: end; justify-self: center; border: 0; padding: 0; width: max-content; }
.rack-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 7px; font-weight: 900; font-size: 11px; letter-spacing: .07em; }
.rack-wrap { position: relative; width: max-content; }
.rack { display: grid; grid-template-columns: repeat(4, var(--tile-size)); grid-auto-rows: var(--tile-size); gap: 6px; width: calc(var(--tile-size) * 4 + 30px); min-height: calc(var(--tile-size) * 4 + 30px); padding: 6px; border: 1px dashed var(--line); background: #faf7ef; }
.rack.concealed .tile { color: transparent; background: #d8d7d1; border-color: #a7aaa4; box-shadow: 3px 3px 0 #a7aaa4; pointer-events: none; }
.shuffle-button { border: 0; border-bottom: 2px solid var(--orange); padding: 2px 0; background: transparent; color: var(--ink); font: inherit; font-size: 11px; font-weight: 900; cursor: pointer; }
.shuffle-button:hover:not(:disabled) { color: var(--orange); }
.shuffle-button:disabled { opacity: .35; cursor: not-allowed; }
.reveal-button { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); min-width: 150px; background: var(--ink); color: white; box-shadow: 4px 4px 0 var(--orange); }
.reveal-button.hidden { display: none; }
.game-actions { grid-area: actions; align-self: start; display: flex; justify-content: center; gap: 9px; }
.game-shell.completed { grid-template-columns: calc(var(--tile-size) * 8 + 13px); grid-template-areas: "status" "board"; justify-content: center; }
.game-shell.completed .status-row { width: calc(var(--tile-size) * 8 + 13px); align-items: center; }
.game-shell.completed .rack-section, .game-shell.completed .game-actions { display: none; }
.game-shell.completed .cell .tile { background: #287653; color: white; pointer-events: none; }
.game-shell.completed .cell.filled { background: #287653; }
.game-shell.completed .status-dot { background: #287653; }
.button { min-height: 42px; padding: 0 17px; border: 2px solid var(--ink); font: inherit; font-size: 13px; font-weight: 900; cursor: pointer; }
.button.primary { background: var(--ink); color: white; box-shadow: 3px 3px 0 var(--orange); }
.button.primary:hover:not(:disabled) { background: #285247; }
.button.ghost { background: transparent; color: var(--ink); }
.button:disabled { opacity: .38; cursor: not-allowed; box-shadow: none; }

.result-panel { text-align: center; background: var(--paper); border: 2px solid var(--ink); border-top: 0; padding: 35px 22px; }
.hidden { display: none; }
.result-burst { width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 14px; background: var(--lime); border: 2px solid var(--ink); font-size: 27px; box-shadow: 4px 4px 0 var(--ink); }
.result-panel h2 { font-size: clamp(54px, 9vw, 85px); letter-spacing: -.06em; margin: 0; font-variant-numeric: tabular-nums; }
.result-copy { color: #5a6965; }
.result-actions { display: flex; justify-content: center; gap: 10px; margin-top: 20px; }
.share-status { min-height: 20px; color: #58706a; font-size: 13px; }
.rules-strip { display: grid; grid-template-columns: repeat(3, 1fr); border: 2px solid var(--ink); border-top: 0; }
.rules-strip > div { display: grid; justify-items: center; align-content: center; gap: 6px; min-height: 75px; padding: 9px 16px; text-align: center; background: var(--cream); border-right: 1px solid var(--ink); }
.rules-strip > div:last-child { border-right: 0; }
.rules-strip span { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--ink); color: var(--paper); font-family: Georgia, serif; font-size: 12px; font-weight: 800; }
.rules-strip p { margin: 0; font-size: 11px; line-height: 1.35; }

dialog { max-width: 520px; width: calc(100% - 30px); border: 2px solid var(--ink); padding: 30px; background: var(--paper); color: var(--ink); box-shadow: 10px 10px 0 var(--ink); }
dialog::backdrop { background: rgba(12,28,24,.58); }
dialog h2 { font-size: 31px; line-height: 1.05; margin: 0 40px 20px 0; }
dialog ol { padding-left: 22px; line-height: 1.5; }
dialog li { margin: 9px 0; }
.dialog-close { position: absolute; right: 14px; top: 12px; border: 0; background: transparent; font-size: 30px; cursor: pointer; }
.dialog-note { padding: 13px; background: var(--cream); font-size: 13px; line-height: 1.45; border-left: 4px solid var(--orange); }
dialog .button { width: 100%; margin-top: 8px; }

@keyframes shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }

@media (max-width: 700px) {
  :root { --tile-size: min(54px, 5.25vh, calc((100vw - 32px) / 8)); }
  .topbar { height: 54px; padding: 0 12px; }
  .brand { font-size: 15px; }
  .brand-mark { grid-template-columns: repeat(2, 19px); }
  .brand-mark i { height: 22px; }
  .top-actions .icon-button:last-child { display: none; }
  .icon-button { width: 32px; height: 32px; }
  main { padding: 9px 8px 10px; }
  .hero { min-height: 54px; }
  .hero h1 { font-size: clamp(23px, 7vw, 33px); }
  .timer-card { min-width: 90px; padding: 5px 9px; box-shadow: 2px 2px 0 var(--ink); }
  .timer-card strong { font-size: 19px; }
  .mode-tabs { margin-top: 6px; }
  .mode-tab { flex: 1; padding: 7px 10px; }
  .game-shell { grid-template-columns: 1fr; grid-template-areas: "status" "board" "rack" "actions"; justify-items: center; gap: 8px; padding: 9px 6px 10px; }
  .status-row { width: 100%; font-size: 10px; }
  .rack-section { min-width: 0; width: calc(var(--tile-size) * 8 + 7px); }
  .rack-heading { margin-bottom: 4px; }
  .rack-heading > span { display: none; }
  .rack { grid-template-columns: repeat(8, var(--tile-size)); grid-auto-rows: var(--tile-size); gap: 1px; width: calc(var(--tile-size) * 8 + 7px); min-height: calc(var(--tile-size) * 2 + 1px); padding: 0; border: 0; background: transparent; }
  .rack .tile { box-shadow: none; }
  .game-actions { width: 100%; }
  .game-actions .button { flex: 1; min-height: 37px; }
  .rules-strip { display: none; }
  .result-actions { flex-direction: column; }
  .result-actions .button { width: 100%; }
}

@media (max-height: 720px) and (min-width: 701px) {
  main { padding-top: 9px; }
  .hero { min-height: 52px; }
  .mode-tabs { margin-top: 5px; }
  .rules-strip > div { min-height: 62px; padding-block: 6px; }
}
