/* Word Recall — styles. A bright, retro menu and three machines: a wooden TV,
   a typewriter and a yellow handheld. */
:root {
  --bg: #fdf6e3;
  --panel: #ffffff;
  --text: #2a2420;
  --muted: #6b625a;
  --line: #e4dccb;
  --teal: #1b8f8c;
  --teal-dark: #136b69;
  --go: #e2622c;
  --go-dark: #b84a1c;
  --mustard: #f2b134;
  --right: #2fa35a;
  --wrong: #d0402e;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text); display: flex; flex-direction: column; min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button {
  font: inherit; font-weight: 700; border: 2px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: 12px; padding: 8px 16px; cursor: pointer; touch-action: manipulation;
}
button:disabled { opacity: .45; cursor: default; }
button.go { background: var(--go); border-color: var(--go-dark); color: #fff; font-size: 18px; padding: 10px 22px; }
button.go:not(:disabled):hover { background: var(--go-dark); }
button.secondary { background: #fff; }
button.danger { color: var(--wrong); border-color: #f0c4be; }
button.icon { width: 42px; height: 42px; padding: 0; border-radius: 50%; font-size: 20px; }
button.plain { border: none; background: none; }
.small { color: var(--muted); font-size: 13px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 14px; background: var(--teal); color: #fff;
}
.brand { font-size: 22px; font-weight: 800; letter-spacing: .3px; display: flex; align-items: center; gap: 8px; }
.brand-mark {
  font-family: "Courier New", Courier, monospace; font-size: 20px; background: #fff; color: var(--teal);
  border-radius: 8px; padding: 1px 6px; line-height: 1.2;
}
.top-right { display: flex; gap: 8px; align-items: center; }
.player-chip { background: rgba(255, 255, 255, .16); color: #fff; border-color: rgba(255, 255, 255, .5); padding: 6px 14px; }
.topbar button.icon { background: rgba(255, 255, 255, .16); color: #fff; border-color: rgba(255, 255, 255, .5); }
/* 70s stripes under the bar */
.topbar, .stripes, .update-note { flex-shrink: 0; }
.stripes { height: 9px; background: linear-gradient(var(--mustard) 0 3px, var(--go) 3px 6px, #8a4b2a 6px 9px); }

.update-note {
  display: flex; gap: 10px; align-items: center; justify-content: center; padding: 8px; background: #fff4d6;
  border-bottom: 1px solid #f0d58a; font-weight: 600;
}

/* ---------- home ---------- */
.home { max-width: 860px; width: 100%; margin: 0 auto; padding: 14px 14px 24px; display: flex; flex-direction: column; gap: 12px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; }
.home h2 { margin: 0 0 10px; font-size: 18px; color: var(--teal-dark); }
.players { display: flex; flex-wrap: wrap; gap: 10px; }
.player {
  display: flex; align-items: center; gap: 8px; padding: 8px 14px 8px 8px; border-radius: 30px; border: 3px solid var(--line);
}
.player-emoji { font-size: 30px; line-height: 1; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; background: #f6f1e4; }
.player.on { border-color: var(--pc, var(--teal)); background: color-mix(in srgb, var(--pc, var(--teal)) 10%, #fff); }
.player.add { color: var(--muted); border-style: dashed; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mode { text-align: left; display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; border-width: 3px; }
.mode-name { font-size: 18px; }
.mode-desc { font-weight: 500; color: var(--muted); font-size: 14px; }
.mode.on { border-color: var(--teal); background: #e6f4f3; }
.machines { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.mach-pick { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 6px 8px; border-width: 3px; }
.mach-pick svg { width: 100%; max-width: 120px; height: auto; max-height: 96px; }
.mach-name { font-size: 16px; }
.mach-pick.on { border-color: var(--go); background: #fff1e8; }
.levels { display: flex; flex-wrap: wrap; gap: 10px; }
.level { display: flex; flex-direction: column; align-items: center; min-width: 84px; padding: 8px 12px; border-width: 3px; }
.level-n { font-size: 30px; line-height: 1.1; }
.level-word { font-size: 13px; color: var(--muted); font-weight: 600; }
.level-stars { color: #f2b705; letter-spacing: 1px; font-size: 16px; }
.level.on { border-color: var(--go); background: #fff1e8; }
.home-go { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.home-go .go { font-size: 22px; padding: 12px 36px; }

/* ---------- a round ---------- */
.play { flex: 1; display: grid; grid-template-rows: auto 1fr auto; gap: 8px; padding: 8px 12px 12px; min-height: 0; }
.play-bar { display: flex; align-items: center; gap: 12px; min-height: 44px; }
.prompt { flex: 1; font-size: 20px; font-weight: 800; color: var(--teal-dark); }
.gauge { display: flex; align-items: center; gap: 8px; }
.gauge-art { width: 170px; height: 34px; display: flex; align-items: center; }
.g-svg { width: 100%; height: 100%; display: block; }
.gauge-text { font-weight: 800; min-width: 3ch; text-align: right; font-variant-numeric: tabular-nums; }
.bar { width: 100%; height: 12px; background: #e6dfcc; border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--right); border-radius: 6px; transition: width .1s linear; }
.bar-fill.low { background: var(--wrong); }

.stage { position: relative; display: flex; justify-content: center; align-items: center; min-height: 0; }
.machine { --k: min(56px, calc((100cqw - 30px) / 10.8)); width: min(100%, 860px); display: flex; flex-direction: column; container-type: inline-size; }
.mach-top { display: flex; flex-direction: column; align-items: stretch; }

/* the screen and the letters on it */
.screen {
  position: relative; container-type: inline-size; display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: clamp(110px, 24vh, 190px); padding: 14px 12px 22px; overflow: hidden;
}
.slots { display: flex; justify-content: center; align-items: flex-end; gap: 1cqw; position: relative; z-index: 1; }
.slot {
  --w: min(13cqw, calc(90cqw / var(--n)), 84px);
  position: relative; width: var(--w); height: calc(var(--w) * 1.3); display: grid; place-items: center;
  font-size: calc(var(--w) * 1.0); font-weight: 800; line-height: 1; border-radius: 8px; cursor: default;
}
.slot.gap { width: calc(var(--w) * .5); }
.slot.pending > * { visibility: hidden; }
.slot.blank, .slot.typed { cursor: pointer; }
.slot.blank::after, .slot.typed::after, .slot.active::after {
  content: ""; position: absolute; left: 10%; right: 10%; bottom: 2px; height: 4px; border-radius: 2px; background: currentColor; opacity: .55;
}
.slot.active { background: rgba(255, 216, 77, .35); }
.slot.active::after { opacity: 1; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .15; } }
.slot.right { background: rgba(47, 163, 90, .22); animation: pop .3s ease-out; }
.slot.wrong { background: rgba(208, 64, 46, .2); animation: pop .3s ease-out; }
.slot .was {
  position: absolute; bottom: calc(var(--w) * -.42); left: 50%; transform: translateX(-50%); font-size: calc(var(--w) * .34);
  color: var(--wrong); text-decoration: line-through; font-family: system-ui, sans-serif; font-weight: 800;
  background: #fff; border-radius: 6px; padding: 0 4px; line-height: 1.2;
}
@keyframes pop { from { transform: scale(.6); } to { transform: scale(1); } }
.slot.vanish { animation: vanish .45s steps(6) forwards; }
@keyframes vanish { 0% { opacity: 1; } 20% { opacity: .2; } 40% { opacity: .9; } 60% { opacity: .1; } 80% { opacity: .5; } 100% { opacity: 0; } }
.slot .dots { width: 78%; height: auto; display: block; }
.dot-on { fill: #23301d; }
.dot-off { fill: rgba(35, 48, 29, .07); }
.slot.right .dot-on { fill: #13612f; }
.slot.wrong .dot-on { fill: #a3241a; }

/* what happens on the screen when time runs out */
.screen-fx { position: absolute; inset: 0; z-index: 3; display: grid; place-items: center; animation: fxin .35s ease-out; }
@keyframes fxin { from { opacity: 0; } to { opacity: 1; } }
.fx-svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.fx-text {
  position: relative; font-weight: 800; font-size: clamp(16px, 4cqw, 26px); background: rgba(255, 255, 255, .92); color: #222;
  padding: 6px 14px; border-radius: 12px; text-align: center;
}
.fx-dark { position: absolute; inset: 0; background: #1e2618; animation: fxdark 1.2s ease-in forwards; }
@keyframes fxdark { 0% { opacity: 0; } 30% { opacity: .5; } 45% { opacity: .2; } 100% { opacity: .95; } }

/* the keys */
.keys { display: flex; flex-direction: column; align-items: center; gap: calc(var(--k) * .14); container-type: inline-size; }
.key-row { display: flex; gap: calc(var(--k) * .14); }
.key {
  width: var(--k); height: calc(var(--k) * .92); padding: 0; display: grid; place-items: center; font-size: calc(var(--k) * .44);
  font-weight: 800; border-radius: 10px;
}
.key.wide { width: calc(var(--k) * 1.5); }
.key:not(:disabled):active { transform: translateY(2px); }
.keys.off .key:disabled { opacity: .55; }
.machine.done .key { opacity: .3; }
.machine.done .screen { padding-bottom: 38px; }

/* the result card over the keys */
.result {
  position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); z-index: 10;
  background: rgba(255, 255, 255, .97); border-radius: 18px; padding: 8px 22px 10px; text-align: center;
  box-shadow: 0 6px 22px rgba(0, 0, 0, .3); min-width: min(92%, 360px); border: 3px solid var(--mustard);
}
.result-stars { font-size: 38px; line-height: 1.1; letter-spacing: 4px; }
.star { color: #ddd6c6; display: inline-block; }
.star.won { color: #f2b705; animation: star .5s both; animation-delay: var(--d); }
@keyframes star { 0% { transform: scale(0) rotate(-90deg); } 70% { transform: scale(1.3); } 100% { transform: scale(1); } }
.result-text { font-size: 19px; font-weight: 800; }
.result-detail { color: var(--muted); font-weight: 600; font-size: 14px; }

.actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; min-height: 48px; }

/* ---------- the television: a wooden cabinet, a glowing screen, a dial ---------- */
.machine[data-machine="tv"] {
  position: relative; padding: 14px; margin-bottom: 14px; border-radius: 26px; border: 4px solid #6e3a16;
  background:
    repeating-linear-gradient(91deg, rgba(255, 255, 255, .06) 0 3px, transparent 3px 19px),
    repeating-linear-gradient(89deg, rgba(90, 40, 10, .1) 0 2px, transparent 2px 31px),
    linear-gradient(180deg, #d0843f, #b8692c);
  box-shadow: 0 8px 18px rgba(80, 40, 10, .3);
}
.machine[data-machine="tv"]::before, .machine[data-machine="tv"]::after {
  content: ""; position: absolute; bottom: -16px; width: 22px; height: 14px; background: #5a3418; border-radius: 0 0 6px 6px;
}
.machine[data-machine="tv"]::before { left: 12%; }
.machine[data-machine="tv"]::after { right: 12%; }
.machine[data-machine="tv"] .mach-top { flex-direction: row; gap: 14px; }
.machine[data-machine="tv"] .screen {
  flex: 1; border-radius: 34px / 46px; border: 9px solid #2e2016; color: #fff;
  background: radial-gradient(ellipse at 50% 45%, #8fb0c4 0%, #6a8a9e 55%, #4b6577 100%);
  box-shadow: inset 0 0 30px rgba(0, 0, 0, .35);
}
.machine[data-machine="tv"] .screen::after {
  content: ""; position: absolute; inset: 0; z-index: 2; pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, .09) 0 2px, transparent 2px 4px);
}
.machine[data-machine="tv"] .glow { text-shadow: 0 0 8px rgba(255, 255, 255, .75), 0 0 18px rgba(170, 220, 255, .6); }
.machine[data-machine="tv"] .slot.right { background: rgba(80, 220, 120, .35); }
.machine[data-machine="tv"] .slot.wrong { background: rgba(255, 90, 70, .4); }
.screen.tuning::before {
  content: ""; position: absolute; inset: 0; z-index: 2; pointer-events: none; animation: tune .45s steps(5) forwards;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 .9 0 0 0 0 .9 0 0 0 0 .9 0 0 0 1.6 -.3'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E"), #6a8a9e;
}
@keyframes tune { 0% { opacity: 1; background-position: 0 0; } 50% { background-position: 40px 70px; } 100% { opacity: 0; background-position: 90px 20px; } }
.tv-side { width: clamp(70px, 14cqw, 120px); display: flex; flex-direction: column; align-items: center; justify-content: space-between; gap: 8px; }
.tv-speaker {
  width: 100%; flex: 1; min-height: 50px; border-radius: 50%; border: 4px solid #6e3a16;
  background: repeating-linear-gradient(0deg, #b9a27a 0 3px, #efe1c2 3px 7px);
}
.tv-dial { width: 78%; height: auto; }
.tv-knob { width: 22px; height: 22px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #777, #1b1b1b); }
.machine[data-machine="tv"] .keys {
  margin-top: 12px; padding: 10px; border-radius: 14px; border: 3px solid #4a4a4a;
  background: repeating-linear-gradient(90deg, #747474 0 2px, #6a6a6a 2px 4px);
}
.machine[data-machine="tv"] .key {
  background: linear-gradient(#fbf5e4, #e8dcbc); border: 2px solid #5a4a30; color: #3a2a18; box-shadow: 0 3px 0 #5a4a30;
}
.machine[data-machine="tv"] .key.wide { background: linear-gradient(#f3b07a, #e2622c); color: #fff; }

/* ---------- the typewriter: paper, a roller, a black body with round keys ---------- */
.machine[data-machine="typewriter"] .screen {
  width: 84%; margin: 0 auto; color: #1d1d1d; border-radius: 4px 4px 0 0; padding-bottom: 26px;
  font-family: "Courier New", Courier, monospace;
  background: repeating-linear-gradient(180deg, #fff 0 30px, #eef3fb 30px 31px), #fff;
  box-shadow: 0 0 0 1px #ddd, 0 -2px 10px rgba(0, 0, 0, .08);
}
.machine[data-machine="typewriter"] .slot { font-weight: 700; }
.machine[data-machine="typewriter"] .ink { display: inline-block; }
.screen.new-sheet .slots { animation: sheet .45s ease-in-out; }
@keyframes sheet { 0% { transform: none; opacity: 1; } 50% { transform: translateY(-120%); opacity: 0; } 51% { transform: translateY(80%); opacity: 0; } 100% { transform: none; opacity: 1; } }
.machine[data-machine="typewriter"] .slot.vanish::before {
  content: ""; position: absolute; inset: 8% 4%; background: #fffdf6; border-radius: 40% 50% 45% 55%;
  box-shadow: 0 0 0 2px #f1ece0; animation: whiteout .45s ease-out forwards;
}
@keyframes whiteout { from { transform: scale(0); } to { transform: scale(1); } }
.machine[data-machine="typewriter"] .slot.vanish { animation: none; }
.tw-platen {
  position: relative; height: 26px; margin: -6px 2% 0; border-radius: 13px; z-index: 2;
  background: linear-gradient(#4a4a4a, #111 60%, #2a2a2a);
}
.tw-knob {
  position: absolute; left: -16px; top: -4px; width: 34px; height: 34px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #bbb, #444 70%);
}
.tw-knob.right { left: auto; right: -16px; }
.machine[data-machine="typewriter"] .keys {
  margin: 0 0; padding: 16px 10px 18px; border-radius: 10px 10px 26px 26px;
  background: linear-gradient(#3a3a3a, #1f1f1f); border-top: 4px solid #9a9a9a;
  clip-path: polygon(2% 0, 98% 0, 100% 100%, 0 100%);
}
.machine[data-machine="typewriter"] .key {
  height: var(--k); border-radius: 50%; color: #fff; font-family: "Courier New", Courier, monospace;
  background: radial-gradient(circle at 40% 35%, #333, #0c0c0c); border: 3px solid #cfcfcf; box-shadow: 0 3px 0 #000;
}
.machine[data-machine="typewriter"] .key.wide { width: var(--k); background: radial-gradient(circle at 40% 35%, #a33, #5a0d0d); }

/* ---------- the handheld: yellow plastic, an LCD screen, rubber keys ---------- */
.machine[data-machine="handheld"] {
  padding: 16px 18px 20px; border-radius: 26px 26px 70px 26px; border: 3px solid #d1a600;
  background: linear-gradient(160deg, #ffe34d, #ffd400 50%, #f5c800); box-shadow: 0 8px 18px rgba(120, 90, 0, .3);
}
.machine[data-machine="handheld"] .mach-top { background: #5b5b66; border-radius: 12px 12px 30px 12px; padding: 14px 16px 6px; }
.machine[data-machine="handheld"] .screen {
  color: #23301d; border-radius: 4px; font-family: ui-monospace, monospace;
  background: linear-gradient(160deg, #cfe0b0, #b9cd96); box-shadow: inset 0 2px 6px rgba(0, 0, 0, .35);
}
.machine[data-machine="handheld"] .slot.active { background: rgba(35, 48, 29, .12); }
.hh-label { display: flex; align-items: center; gap: 8px; color: #dfe0e8; font-weight: 800; font-style: italic; font-size: 13px; padding: 6px 2px 2px; letter-spacing: 1px; }
.hh-led { width: 9px; height: 9px; border-radius: 50%; background: #ff3b30; box-shadow: 0 0 6px #ff3b30; }
.hh-model { margin-left: auto; font-size: 11px; color: #b5b6c4; }
.machine[data-machine="handheld"] .keys { margin-top: 16px; }
.machine[data-machine="handheld"] .key {
  border-radius: 12px; background: linear-gradient(#4a4a5c, #2f2f3c); color: #f4f4f8; border: none;
  box-shadow: 0 3px 0 #1b1b24; font-family: ui-monospace, monospace;
}
.machine[data-machine="handheld"] .key.wide { background: linear-gradient(#d24c84, #a82a5e); box-shadow: 0 3px 0 #6e1a3c; }

/* ---------- dialogs ---------- */
.dialog { max-width: 460px; width: calc(100% - 28px); border: none; box-shadow: 0 10px 40px rgba(0, 0, 0, .3); }
.dialog.wide { max-width: 860px; }
.dialog::backdrop { background: rgba(30, 20, 10, .45); }
.dialog h2 { margin: 0 0 12px; color: var(--teal-dark); }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 700; margin-bottom: 12px; }
.field.check { flex-direction: row; align-items: center; gap: 10px; }
.field input[type=text], .field select { font: inherit; font-weight: 500; padding: 8px 10px; border: 2px solid var(--line); border-radius: 10px; }
.field input[type=checkbox] { width: 22px; height: 22px; }
.field-label { font-weight: 700; margin-bottom: 6px; }
.emoji-pick { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin-bottom: 14px; }
.emoji-pick button { font-size: 26px; padding: 4px 0; border-radius: 10px; }
.emoji-pick button.on { border-color: var(--teal); background: #e6f4f3; }
.dialog-buttons { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.spacer { flex: 1; }
.help li { margin-bottom: 8px; line-height: 1.45; }
.scores { border-collapse: collapse; width: 100%; font-size: 14px; }
.scores th, .scores td { padding: 6px 5px; border-bottom: 1px solid var(--line); text-align: center; }
.scores .who { text-align: left; white-space: nowrap; font-weight: 700; }
.mini-stars { color: #f2b705; font-size: 11px; letter-spacing: 0; white-space: nowrap; }
#scores { overflow-x: auto; }

/* Short screens (a tablet held sideways): a smaller screen and keys. */
@media (max-height: 700px) {
  .screen { min-height: 96px; padding-top: 8px; padding-bottom: 16px; }
  .slot { --w: min(13cqw, calc(90cqw / var(--n)), 64px); }
  .machine { --k: min(46px, calc((100cqw - 30px) / 10.8)); width: min(100%, 760px); }
  .machine[data-machine="tv"] { padding: 10px; }
  .machine[data-machine="tv"] .keys { margin-top: 8px; padding: 8px; }
  .machine[data-machine="typewriter"] .keys { padding: 12px 10px 12px; }
  .machine[data-machine="handheld"] { padding: 12px 14px 14px; }
  .machine[data-machine="handheld"] .mach-top { padding: 10px 12px 4px; }
  .machine[data-machine="handheld"] .keys { margin-top: 10px; }
  .tv-speaker { min-height: 30px; }
  .mach-pick svg { max-height: 64px; }
  .home { gap: 10px; padding-top: 10px; }
  .panel { padding: 10px 14px; }
  .home h2 { margin-bottom: 8px; }
}

/* Phones and narrow screens */
@media (max-width: 560px) {
  .modes { grid-template-columns: 1fr; }
  .brand { font-size: 18px; }
  .prompt { font-size: 16px; }
  .gauge-art { width: 110px; }
  .tv-side { display: none; }
}

/* A tablet held sideways: the menu in two columns, so Start is on screen. */
@media (min-aspect-ratio: 4/3) and (max-height: 820px) and (min-width: 800px) {
  .home { max-width: 1060px; display: grid; grid-template-columns: 1fr 1fr; align-content: start; }
  .home-go { grid-column: 1 / -1; }
  .level { min-width: 0; flex: 1; padding: 6px 4px; }
  .level-n { font-size: 26px; }
  .levels { gap: 8px; }
}
