/* Learn Morse web — same look as the iOS app. Light: bright brand colors. Dark: near-black, soft accents. */
:root {
  --game-red: #EF4136;
  --practice-blue: #145DA0;
  --cream: #F1E4D4;
  --game-bg: #EF4136;
  --practice-bg: #145DA0;
  --letters-bg: #8E3FB0;
  --card: #F1E4D4;
  --key: #F1E4D4;
  --card-text: #3A2340;
  --scrim: rgba(0, 0, 0, .15);
  --track: rgba(0, 0, 0, .10);
  --hint-tile: #EF4136;
  --practice-tile: #145DA0;
  --letters-tile: #C55AF0;
  --correct-fill: #23A67A;
  --correct-text: #F1E4D4;
  --wrong-fill: #FFFFFF;
  --wrong-text: #D9473B;
  --good: #2FB67C;
  --warn: #F0A35A;
  --stat: #FFD166;
  --typed-right: #7CFFB2;
  --typed-wrong: #FF6B6B;
  --brick-0: #4A8DE8; --brick-1: #B34FE0; --brick-2: #23A67A; --brick-3: #E8892E;
  --shadow: rgba(0, 0, 0, .18);
  --on-cream: #3A2340;      /* text on cream fills (selected segment) */
  --on-accent: #F1E4D4;     /* text on accent-filled buttons */
  --font: "Nunito", ui-rounded, "SF Pro Rounded", system-ui, -apple-system, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --game-red: #D9776C; --practice-blue: #8AAAD0; --cream: #D8CCBD;
    --game-bg: #0D0B0B; --practice-bg: #0A0B0E; --letters-bg: #0C0B0D;
    --card: #1A1817; --key: rgba(255, 255, 255, .075); --card-text: #D8CCBD;
    --scrim: rgba(255, 255, 255, .06); --track: rgba(255, 255, 255, .10);
    --hint-tile: #121110; --practice-tile: #141B25; --letters-tile: #1D1722;
    --correct-fill: #15302A; --correct-text: #86C9AA; --wrong-fill: #351C1A; --wrong-text: #E08A80;
    --good: #6FAF92; --warn: #C49261; --stat: #D4BC7E; --typed-right: #86C9AA; --typed-wrong: #E08A80;
    --brick-0: #2A4466; --brick-1: #4B3159; --brick-2: #1F4A3C; --brick-3: #5E4227;
    --shadow: rgba(0, 0, 0, .5);
    --on-cream: #1A1110; --on-accent: #1A1110;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --game-red: #D9776C; --practice-blue: #8AAAD0; --cream: #D8CCBD;
    --game-bg: #0D0B0B; --practice-bg: #0A0B0E; --letters-bg: #0C0B0D;
    --card: #1A1817; --key: rgba(255, 255, 255, .075); --card-text: #D8CCBD;
    --scrim: rgba(255, 255, 255, .06); --track: rgba(255, 255, 255, .10);
    --hint-tile: #121110; --practice-tile: #141B25; --letters-tile: #1D1722;
    --correct-fill: #15302A; --correct-text: #86C9AA; --wrong-fill: #351C1A; --wrong-text: #E08A80;
    --good: #6FAF92; --warn: #C49261; --stat: #D4BC7E; --typed-right: #86C9AA; --typed-wrong: #E08A80;
    --brick-0: #2A4466; --brick-1: #4B3159; --brick-2: #1F4A3C; --brick-3: #5E4227;
    --shadow: rgba(0, 0, 0, .5);
    --on-cream: #1A1110; --on-accent: #1A1110;
    color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font); font-weight: 700; color: var(--cream);
  background: var(--game-bg); overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--cream); outline-offset: 2px; }
.screen {
  min-height: 100dvh; display: flex; flex-direction: column;
  padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.screen.game { background: var(--game-bg); --tint: var(--game-red); }
.screen.practice { background: var(--practice-bg); --tint: var(--practice-blue); }
/* Sizes follow the window: big on tablets and desktops, compact on phones and short windows. */
.screen.game, .screen.practice {
  --L: clamp(34px, min(8.5dvh, 15vw), 96px);    /* letters in the word row */
  --H: clamp(56px, 24dvh, 300px);               /* hint picture */
  --K: clamp(56px, 13dvh, 150px);               /* dot/dash key height */
  --bar: clamp(36px, 5.5dvh, 52px);             /* input bar height */
}
.screen.letters { background: var(--letters-bg); }
.press { transition: transform .1s; }
.press:active { transform: scale(.95); }

/* Top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 48px; }
.topbar .title { text-align: center; }
.topbar .title b { display: block; font-size: 17px; font-weight: 900; }
.topbar .title small { font-size: 13px; opacity: .75; }
.circle {
  width: 44px; height: 44px; border-radius: 50%; background: var(--scrim); color: var(--cream);
  display: grid; place-items: center; flex: none;
}
.circle svg { width: 20px; height: 20px; }

/* Morse pattern */
.pattern { display: inline-flex; align-items: center; gap: calc(var(--s) * .6); }
.pattern i { display: block; height: var(--s); width: var(--s); border-radius: 999px; background: currentColor; }
.pattern i.dash { width: calc(var(--s) * 3); }
.pattern .gap { display: block; width: var(--s); }

/* Home */
.home { background: var(--game-bg); }
.home-inner { width: 100%; max-width: 560px; margin: auto; display: flex; flex-direction: column; gap: 24px; padding: 8px 0 20px; }
.brand { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.brand .pattern { color: var(--cream); opacity: .6; }
.brand h1 { margin: 0; font-size: clamp(40px, 12vw, 56px); font-weight: 900; line-height: 1; }
.brand h1 small { display: block; font-size: .42em; font-weight: 800; opacity: .8; margin-top: .25em; }
.brand p { margin: 0; font-size: 17px; opacity: .8; }
.segmented { display: flex; background: var(--scrim); border-radius: 999px; padding: 3px; max-width: 320px; width: 100%; margin: 0 auto; }
.segmented button { flex: 1; padding: 8px 0; border-radius: 999px; font-size: 15px; color: var(--cream); }
.segmented button[aria-pressed="true"] { background: var(--cream); color: var(--on-cream); }
.toggle-row {
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  background: var(--scrim); border-radius: 999px; padding: 8px 10px 8px 18px; max-width: 320px; width: 100%; margin: 0 auto;
}
.toggle-row svg { width: 20px; height: 20px; vertical-align: -4px; margin-right: 8px; }
.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { appearance: none; -webkit-appearance: none; margin: 0; width: 51px; height: 31px; border-radius: 999px; background: rgba(0,0,0,.25); cursor: pointer; transition: background .2s; }
.switch input:checked { background: #23A67A; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.2); transition: transform .2s; }
.switch input:checked::after { transform: translateX(20px); }
.card { background: var(--card); color: var(--game-red); border-radius: 30px; padding: 22px; display: flex; flex-direction: column; gap: 18px; }
.progress-head { display: flex; align-items: center; gap: 18px; }
.ring { width: 84px; height: 84px; position: relative; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 10; }
.ring .bg { stroke: var(--game-red); opacity: .15; }
.ring .fg { stroke: var(--game-red); stroke-linecap: round; transition: stroke-dashoffset .5s; }
.ring span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 28px; font-weight: 900; }
.progress-head b { display: block; font-size: 20px; font-weight: 900; }
.progress-head small { font-size: 15px; opacity: .7; }
.primary {
  width: 100%; padding: 16px; border-radius: 999px; background: var(--game-red); color: var(--on-accent);
  font-size: 18px; font-weight: 900; display: flex; justify-content: center; align-items: center; gap: 8px;
}
.primary.secondary { background: color-mix(in srgb, var(--game-red) 12%, transparent); color: var(--game-red); }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.tile {
  text-align: left; min-height: 150px; border-radius: 26px; padding: 18px; color: var(--cream);
  display: flex; flex-direction: column; gap: 4px; box-shadow: 0 5px 0 var(--shadow);
}
.tile .ico { width: 44px; height: 44px; border-radius: 50%; background: rgba(255,255,255,.18); display: grid; place-items: center; margin-bottom: auto; }
.tile .ico svg { width: 22px; height: 22px; }
.tile b { font-size: 18px; font-weight: 900; margin-top: 12px; }
.tile small { font-size: 13px; opacity: .75; }

.credit { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; font-size: 14px; padding-top: 4px; }
.credit span { opacity: .75; }
.credit a { color: var(--cream); font-weight: 800; text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1.5px; padding: 4px 8px; }
@media (hover: hover) { .credit a:hover { opacity: .85; } }

/* Progress lights */
.lights { display: flex; width: 100%; max-width: 760px; margin: 0 auto; }
.lights span { flex: 1; text-align: center; font-weight: 900; position: relative; line-height: 1.3; }
.lights span.cur::after { content: ""; position: absolute; left: 50%; bottom: -4px; width: .6em; height: 3px; border-radius: 2px; background: currentColor; transform: translateX(-50%); }

/* Learn */
.learn-main { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 10px; min-height: 0; }
.track { position: relative; overflow: hidden; height: calc(var(--L) * 1.9); margin: 0 calc(-1 * max(16px, env(safe-area-inset-left))); }
.track-inner { position: absolute; top: 0; bottom: 0; left: 0; display: flex; align-items: center; gap: calc(var(--L) * .45); transition: transform .5s cubic-bezier(.2, .8, .2, 1); will-change: transform; }
.track-inner.no-anim { transition: none; }
.brick {
  display: flex; gap: calc(var(--L) * .08); padding: calc(var(--L) * .18) calc(var(--L) * .3);
  border-radius: calc(var(--L) * .3); flex: none; transition: opacity .3s;
}
.brick.current { box-shadow: 0 calc(var(--L) * .07) 0 var(--shadow); }
.brick.past { opacity: .5; }
.letter {
  font-size: var(--L); font-weight: 900; line-height: 1.05; min-width: calc(var(--L) * .62); text-align: center;
  color: rgba(255,255,255,.85); position: relative; transition: transform .35s, color .35s;
}
.letter.done { color: rgba(255,255,255,.4); transform: translateY(calc(var(--L) * .12)) scale(.8); }
.letter.current { color: var(--cream); transform: scale(1.08); }
.letter.current::after { content: ""; position: absolute; left: 50%; bottom: calc(var(--L) * -.06); width: calc(var(--L) * .5); height: calc(var(--L) * .07); border-radius: 99px; background: var(--cream); transform: translateX(-50%); }
.shake { animation: shake .45s; }
@keyframes shake { 0%,100% { translate: 0 } 20% { translate: -12px } 40% { translate: 12px } 60% { translate: -8px } 80% { translate: 8px } }
.hint-area { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; min-height: calc(var(--H) + 60px); cursor: pointer; }
.hint-area img { width: var(--H); height: var(--H); object-fit: contain; animation: pop .35s; }
@keyframes pop { from { transform: scale(.8); opacity: 0 } }
.hint-area .pattern { color: var(--cream); }
.hint-btn { background: var(--scrim); color: var(--cream); opacity: .9; padding: 10px 16px; border-radius: 999px; font-size: 15px; display: inline-flex; gap: 8px; align-items: center; }
.hint-btn svg { width: 16px; height: 16px; }

/* Morse board */
.board { width: 100%; max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; gap: clamp(8px, 1.6dvh, 14px); }
.kbd-hint { display: none; text-align: center; font-size: 13px; opacity: .6; font-weight: 700; }
.kbd-hint kbd { font: inherit; background: var(--scrim); border-radius: 6px; padding: 1px 7px; }
.inputbar { height: var(--bar, 44px); border-radius: 999px; background: var(--scrim); display: grid; place-items: center; font-size: 15px; transition: background .15s; }
.inputbar .placeholder { opacity: .55; }
.inputbar.ok { background: var(--correct-fill); color: var(--correct-text); font-weight: 900; font-size: 16px; }
.inputbar.bad { background: var(--wrong-fill); color: var(--wrong-text); font-weight: 900; font-size: 16px; }
.keys { display: flex; gap: 12px; }
.key {
  flex: 1; height: var(--K); border-radius: 24px; background: var(--key); color: var(--tint);
  display: grid; place-items: center; box-shadow: 0 5px 0 var(--shadow); touch-action: none;
  transition: transform .08s;
}
.key.down { transform: translateY(3px) scale(.95); }
.key .dot { width: 30px; height: 30px; border-radius: 50%; background: currentColor; }
.key .dash { width: 84px; height: 26px; border-radius: 99px; background: currentColor; }
.key.del { flex: 0 0 64px; background: var(--scrim); color: var(--cream); box-shadow: none; }
.key.del svg { width: 26px; height: 26px; }

/* Overlays */
.newletter {
  position: fixed; left: 50%; top: max(76px, calc(env(safe-area-inset-top) + 66px)); transform: translateX(-50%);
  background: var(--card); color: var(--game-red); border-radius: 24px; padding: 16px 28px 16px 16px;
  display: flex; align-items: center; gap: 16px; box-shadow: 0 8px 20px rgba(0,0,0,.2); z-index: 5;
  animation: drop .4s cubic-bezier(.2, .9, .3, 1.2); width: max-content; max-width: calc(100vw - 40px);
}
@keyframes drop { from { transform: translate(-50%, -30px); opacity: 0 } }
.newletter img { width: 64px; height: 64px; object-fit: contain; }
.newletter small { display: block; font-size: 13px; text-transform: uppercase; opacity: .7; letter-spacing: .03em; }
.newletter .row { display: flex; align-items: center; gap: 14px; font-size: 40px; font-weight: 900; }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: grid; place-items: center; padding: 24px; z-index: 10; animation: fade .3s; }
@keyframes fade { from { opacity: 0 } }
.overlay .card { max-width: 420px; width: 100%; text-align: center; align-items: center; color: var(--game-red); }
.overlay h2 { margin: 0; font-size: 34px; font-weight: 900; }
.overlay p { margin: 0; font-size: 17px; opacity: .8; }
.trophy { font-size: 64px; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { transform: scale(1.08) } }
.linkbtn { font-size: 16px; font-weight: 800; color: inherit; padding: 6px; }

/* Practice */
.practice-main { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; text-align: center; }
.stats-row { display: flex; gap: 24px; justify-content: center; color: var(--stat); font-size: 20px; font-weight: 900; }
.counter { opacity: .75; font-size: 17px; }
.phrase { font-size: clamp(30px, 9vw, 60px); font-weight: 900; line-height: 1.2; max-width: 100%; overflow-wrap: anywhere; }
.phrase span { opacity: .45; }
.phrase span.ok { color: var(--typed-right); opacity: 1; }
.phrase span.bad { color: var(--typed-wrong); opacity: 1; text-decoration: line-through; }
.phrase span.cur { opacity: 1; color: var(--cream); text-decoration: underline; text-underline-offset: .15em; text-decoration-thickness: .08em; }
.expected { background: var(--wrong-fill); color: var(--wrong-text); border-radius: 999px; padding: 8px 16px; display: inline-flex; gap: 12px; align-items: center; font-size: 17px; }
.results { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; text-align: center; }
.results h2 { margin: 0; font-size: 30px; font-weight: 900; }
.stat-boxes { display: flex; gap: 14px; }
.stat-box { width: 100px; height: 90px; border-radius: 20px; background: var(--scrim); display: flex; flex-direction: column; justify-content: center; }
.stat-box b { font-size: 30px; font-weight: 900; }
.stat-box small { font-size: 13px; opacity: .7; }
.results .buttons { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 380px; }
.results .primary { background: var(--cream); color: var(--practice-blue); }

/* Letters */
.letters-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; padding: 12px 0 24px; max-width: 1000px; width: 100%; margin: 0 auto; }
.lcard { background: var(--card); color: var(--card-text); border-radius: 22px; padding: 12px; display: flex; flex-direction: column; gap: 8px; text-align: left; }
.lcard .pic { background: var(--hint-tile); border-radius: 16px; aspect-ratio: 1; display: grid; place-items: center; }
.lcard .pic img { width: 82%; height: 82%; object-fit: contain; }
.lcard .pic .big { font-size: 64px; font-weight: 900; color: var(--cream); }
.lcard .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.lcard .row b { font-size: 28px; font-weight: 900; }
.lcard .pattern { color: var(--card-text); }
.lcard.locked { opacity: .45; }
.scorebar { display: flex; gap: 3px; }
.scorebar i { flex: 1; height: 6px; border-radius: 3px; background: var(--track); }
.scorebar i.on { background: var(--good); }
.scorebar.neg i.on { background: var(--warn); }
.lcard small { font-size: 12px; opacity: .65; }

/* Dialog (settings / about) */
dialog {
  border: 0; padding: 0; border-radius: 24px; width: min(480px, calc(100vw - 24px)); max-height: calc(100dvh - 40px);
  background: var(--card); color: var(--card-text); font-family: var(--font);
}
dialog::backdrop { background: rgba(0,0,0,.4); }
.dlg:focus { outline: none; }
.dlg { padding: 18px 20px 22px; display: flex; flex-direction: column; gap: 14px; }
.dlg header { display: flex; justify-content: space-between; align-items: center; }
.dlg h2 { margin: 0; font-size: 22px; font-weight: 900; }
.dlg h3 { margin: 6px 0 0; font-size: 13px; text-transform: uppercase; opacity: .6; letter-spacing: .04em; }
.dlg .done { color: var(--game-red); font-weight: 900; font-size: 17px; padding: 6px 10px; }
.dlg .group { background: color-mix(in srgb, var(--card-text) 6%, transparent); border-radius: 16px; overflow: hidden; }
.dlg .item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; font-weight: 700; font-size: 16px; }
.dlg .item + .item { border-top: 1px solid color-mix(in srgb, var(--card-text) 10%, transparent); }
.dlg .item .switch input { background: color-mix(in srgb, var(--card-text) 22%, transparent); }
.dlg .item .switch input:checked { background: #23A67A; }
.dlg button.item { width: 100%; color: var(--game-red); text-align: left; }
.dlg button.item.danger { color: #D9473B; }
.dlg .note { font-size: 13px; opacity: .65; margin: 0; font-weight: 600; }
.dlg input[type=range] { width: 100%; accent-color: var(--game-red); }
.dlg textarea { width: 100%; min-height: 80px; border-radius: 12px; padding: 10px; font: 13px ui-monospace, monospace; background: transparent; color: inherit; border: 1px solid color-mix(in srgb, var(--card-text) 25%, transparent); }
.dlg ol { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.dlg p { margin: 0; font-weight: 600; line-height: 1.4; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--card-text); color: var(--card); padding: 10px 18px; border-radius: 999px; z-index: 20; font-size: 15px; animation: fade .2s; }

@media (min-width: 700px) {
  .tile { min-height: 170px; }
}
/* Mouse and keyboard (PC): hover feedback and the keyboard shortcuts under the keys. */
@media (hover: hover) and (pointer: fine) {
  .press:hover, .key:hover, .lcard:hover { filter: brightness(1.06); }
  .kbd-hint { display: block; }
  .key { cursor: pointer; }
}
/* Short windows: landscape phones, small laptop windows. */
@media (max-height: 560px) {
  .screen.game .lights, .kbd-hint { display: none; }
  .topbar { min-height: 40px; }
  .circle { width: 38px; height: 38px; }
  .learn-main { gap: 4px; }
  .hint-area { gap: 6px; min-height: calc(var(--H) + 30px); }
  .practice-main { gap: 8px; }
  .phrase { font-size: clamp(24px, 7dvh, 40px); }
  .newletter { top: 50px; padding: 8px 18px 8px 10px; }
  .newletter img { width: 44px; height: 44px; }
  .newletter .row { font-size: 28px; }
}
/* Wide screens: keep the game in a comfortable column. */
@media (min-width: 1100px) {
  .learn-main, .practice-main { max-width: 1000px; width: 100%; margin-left: auto; margin-right: auto; }
}
.theme-seg { display: flex; gap: 4px; background: color-mix(in srgb, var(--card-text) 8%, transparent); border-radius: 12px; padding: 3px; }
.theme-seg button { flex: 1; padding: 8px 0; border-radius: 9px; font-weight: 800; font-size: 15px; color: var(--card-text); }
.theme-seg button[aria-pressed="true"] { background: var(--game-red); color: var(--on-accent); }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
