/* =========================================================================
   Morse Code Coach — styles
   Night-sea theme: deep navy surfaces, lamp-amber accent, teal secondary.
   ========================================================================= */
:root {
  --bg: #050a18;
  --bg-2: #0a1428;
  --surface: #0f1d38;
  --surface-2: #142544;
  --line: rgba(160, 190, 255, 0.14);
  --text: #e6ecfb;
  --muted: #94a3c4;
  --amber: #ffcf5c;
  --amber-2: #ff9f3c;
  --teal: #5ce1ff;
  --green: #7dffa1;
  --red: #ff6b6b;
  --purple: #b48cff;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  --radius: 18px;
  --font: 'Outfit', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-body: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--text);
  background: radial-gradient(1200px 600px at 20% -10%, #1a2f5c 0%, transparent 60%),
              radial-gradient(900px 500px at 100% 10%, #2a1f4d 0%, transparent 55%),
              var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: var(--font); line-height: 1.15; margin: 0 0 0.5em; letter-spacing: -0.01em; }
p { margin: 0 0 1em; }
a { color: var(--teal); }
kbd { font-family: var(--mono); font-size: 0.85em; background: var(--surface-2); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; padding: 0.05em 0.45em; }
button { font-family: inherit; }
.muted { color: var(--muted); }
.good { color: var(--green); }
.bad { color: var(--red); }
.okay { color: var(--amber); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.container { width: min(1120px, 100% - 2rem); margin: 0 auto; }

/* ---------------- Header ---------------- */
.site-header {
  position: sticky; top: 0; z-index: 30;
  backdrop-filter: blur(14px);
  background: rgba(5, 10, 24, 0.75);
  border-bottom: 1px solid var(--line);
}
.site-header .container { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 60px; }
.logo { display: flex; align-items: center; gap: 0.6rem; text-decoration: none; color: var(--text); font-family: var(--font); font-weight: 700; font-size: 1.15rem; }
.logo-mark { width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg, var(--amber), var(--amber-2)); display: grid; place-items: center; color: #1a1200; font-family: var(--mono); font-size: 0.7rem; font-weight: 800; box-shadow: 0 0 20px rgba(255, 207, 92, 0.45); }
.site-nav { display: flex; gap: 0.2rem; flex-wrap: wrap; }
.site-nav a { color: var(--muted); text-decoration: none; padding: 0.45rem 0.7rem; border-radius: 999px; font-size: 0.92rem; }
.site-nav a:hover { color: var(--text); background: var(--surface-2); }
.site-nav a.cta { background: var(--amber); color: #1a1200; font-weight: 700; }
@media (max-width: 720px) { .site-nav a:not(.cta) { display: none; } }

/* ---------------- App shell ---------------- */
.app { position: relative; margin: 1.5rem auto 3rem; padding: 1rem; border-radius: 26px; background: linear-gradient(180deg, rgba(20, 37, 68, 0.6), rgba(10, 20, 40, 0.6)); border: 1px solid var(--line); box-shadow: var(--shadow); overflow: hidden; }
.app::before { content: ''; position: absolute; inset: -2px; background: radial-gradient(600px 200px at 50% -20%, rgba(255, 207, 92, 0.18), transparent 70%); pointer-events: none; }
.app-title { text-align: center; padding: 0.8rem 0 0.4rem; }
.app-title h1 { font-size: clamp(1.7rem, 4vw, 2.6rem); margin: 0; background: linear-gradient(90deg, #fff 0%, var(--amber) 60%, var(--amber-2) 100%); -webkit-background-clip: text; background-clip: text; color: transparent; }
.app-title p { color: var(--muted); margin: 0.2rem 0 0; }

.hud { display: grid; grid-template-columns: auto 1fr auto; gap: 1rem; align-items: center; padding: 0.8rem 1rem; margin: 0.8rem 0 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); position: relative; z-index: 1; }
.hud-id { display: flex; align-items: center; gap: 0.7rem; }
.hud-avatar { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-family: var(--font); font-weight: 800; font-size: 1.2rem; color: #1a1200; background: linear-gradient(135deg, var(--amber), var(--amber-2)); box-shadow: 0 0 18px rgba(255, 207, 92, 0.35); }
.hud-name { font-family: var(--font); font-weight: 700; font-size: 1.05rem; }
.hud-rank { font-size: 0.82rem; color: var(--muted); }
.hud-xp-bar { height: 10px; border-radius: 999px; background: var(--bg-2); overflow: hidden; border: 1px solid var(--line); }
.hud-xp-fill { height: 100%; background: linear-gradient(90deg, var(--teal), var(--amber)); border-radius: 999px; transition: width 0.6s cubic-bezier(.2,.8,.2,1); box-shadow: 0 0 12px rgba(92, 225, 255, 0.5); }
.hud-xp-text { display: flex; justify-content: space-between; font-size: 0.78rem; color: var(--muted); margin-top: 0.25rem; }
.hud-meta { display: flex; gap: 0.4rem; align-items: center; }
.hud-pill { background: var(--surface-2); border: 1px solid var(--line); padding: 0.3rem 0.6rem; border-radius: 999px; font-size: 0.85rem; white-space: nowrap; }
.hud-btn { background: var(--surface-2); border: 1px solid var(--line); color: var(--text); width: 38px; height: 38px; border-radius: 50%; cursor: pointer; font-size: 1.1rem; }
.hud-btn:hover { background: var(--line); }
@media (max-width: 640px) { .hud { grid-template-columns: 1fr auto; } .hud-xp { grid-column: 1 / -1; } }

.screen { position: relative; z-index: 1; display: grid; gap: 1rem; }
.fade-in { animation: fadeIn 0.35s ease both; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.3rem; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.9rem; }
.card-head h3 { margin: 0; font-size: 1.2rem; }
.card-head .muted { font-size: 0.85rem; }

/* Buttons */
.btn { border: 1px solid var(--line); background: var(--surface-2); color: var(--text); padding: 0.65rem 1.1rem; border-radius: 12px; font-weight: 600; cursor: pointer; transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.2s; font-size: 0.95rem; }
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary { background: linear-gradient(135deg, var(--amber), var(--amber-2)); color: #1a1200; border: none; box-shadow: 0 6px 20px rgba(255, 159, 60, 0.3); }
.btn-primary:hover { box-shadow: 0 10px 28px rgba(255, 159, 60, 0.45); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: rgba(255, 107, 107, 0.15); border-color: rgba(255, 107, 107, 0.4); color: var(--red); }
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.85rem; }
.btn-lg { padding: 0.9rem 1.6rem; font-size: 1.05rem; }

/* Hero */
.hero { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1.5rem; background: linear-gradient(135deg, rgba(255, 207, 92, 0.08), rgba(92, 225, 255, 0.06)), var(--surface); }
.hero h2 { font-size: clamp(1.4rem, 3vw, 2rem); }
.hero p { color: var(--muted); }
.hero p b { color: var(--amber); font-family: var(--mono); }
.hero-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.hero-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; align-content: center; }
.stat { background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; padding: 0.7rem 0.9rem; display: flex; flex-direction: column; }
.stat-n { font-family: var(--font); font-size: 1.5rem; font-weight: 800; color: var(--amber); }
.stat-l { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
@media (max-width: 760px) { .hero { grid-template-columns: 1fr; } }

/* Course path */
.path { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 0.55rem; }
.path-node { position: relative; display: flex; flex-direction: column; align-items: center; gap: 0.15rem; padding: 0.6rem 0.4rem; border-radius: 14px; border: 1px solid var(--line); background: var(--bg-2); color: var(--text); cursor: pointer; transition: transform 0.15s, box-shadow 0.2s; }
.path-node:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(0,0,0,0.35); }
.path-node.done { border-color: rgba(125, 255, 161, 0.4); background: linear-gradient(180deg, rgba(125, 255, 161, 0.12), var(--bg-2)); }
.path-node.current { border-color: var(--amber); background: linear-gradient(180deg, rgba(255, 207, 92, 0.18), var(--bg-2)); animation: pulse 2s infinite; }
.path-node.locked { opacity: 0.45; cursor: not-allowed; }
.pn-num { font-size: 0.72rem; color: var(--muted); }
.pn-chars { font-family: var(--mono); font-weight: 700; font-size: 1.05rem; letter-spacing: 0.1em; }
.pn-best { font-size: 0.75rem; color: var(--green); }
.path-node.current .pn-best { color: var(--amber); }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 207, 92, 0.35); } 50% { box-shadow: 0 0 0 8px rgba(255, 207, 92, 0); } }

/* Modes */
.modes { display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 0.7rem; }
.mode-card { text-align: left; display: flex; flex-direction: column; gap: 0.2rem; padding: 1rem; border-radius: 16px; border: 1px solid var(--line); background: var(--bg-2); color: var(--text); cursor: pointer; transition: transform 0.15s, border-color 0.2s, box-shadow 0.2s; }
.mode-card:hover:not(:disabled) { transform: translateY(-3px); border-color: var(--teal); box-shadow: 0 12px 30px rgba(92, 225, 255, 0.15); }
.mode-card:disabled { opacity: 0.45; cursor: not-allowed; }
.mode-icon { font-size: 1.8rem; }
.mode-name { font-family: var(--font); font-weight: 700; font-size: 1.1rem; }
.mode-tag { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--teal); }
.mode-desc { font-size: 0.85rem; color: var(--muted); }

/* Character grid */
.char-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 0.45rem; }
.char-cell { display: flex; flex-direction: column; align-items: center; padding: 0.5rem 0.2rem; border-radius: 12px; border: 1px solid var(--line); background: var(--bg-2); color: var(--text); cursor: pointer; transition: transform 0.12s; }
.char-cell:hover { transform: scale(1.06); }
.cc-ch { font-family: var(--font); font-weight: 800; font-size: 1.2rem; }
.cc-code { font-family: var(--mono); font-size: 0.72rem; color: var(--muted); letter-spacing: 0.08em; }
.char-cell.k0 { border-color: rgba(92, 225, 255, 0.35); }
.char-cell.k1 { border-color: rgba(255, 107, 107, 0.6); background: rgba(255, 107, 107, 0.12); }
.char-cell.k2 { border-color: rgba(255, 207, 92, 0.6); background: rgba(255, 207, 92, 0.12); }
.char-cell.k3 { border-color: rgba(125, 255, 161, 0.6); background: rgba(125, 255, 161, 0.12); }
.char-cell.learning { border-style: dashed; border-color: var(--amber); }
.char-cell.locked { opacity: 0.35; }
.char-cell.flash { background: var(--amber); color: #1a1200; }
.char-cell.flash .cc-code { color: #1a1200; }
.legend { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: 0.8rem; font-size: 0.8rem; color: var(--muted); }
.legend span { display: flex; align-items: center; gap: 0.35rem; }
.swatch { width: 12px; height: 12px; border-radius: 4px; border: 1px solid var(--line); display: inline-block; }
.swatch.k3 { background: rgba(125, 255, 161, 0.5); } .swatch.k2 { background: rgba(255, 207, 92, 0.5); } .swatch.k1 { background: rgba(255, 107, 107, 0.5); } .swatch.k0 { border-color: var(--teal); } .swatch.learning { border: 1px dashed var(--amber); }

/* Badges */
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 0.5rem; }
.badge { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 0.2rem; padding: 0.7rem 0.4rem; border-radius: 14px; border: 1px solid var(--line); background: var(--bg-2); opacity: 0.35; filter: grayscale(1); }
.badge.earned { opacity: 1; filter: none; border-color: rgba(255, 207, 92, 0.5); background: linear-gradient(180deg, rgba(255, 207, 92, 0.15), var(--bg-2)); }
.badge-icon { font-size: 1.6rem; }
.badge-name { font-size: 0.78rem; font-weight: 600; }

/* Lesson chrome */
.lesson-bar { display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; flex-wrap: wrap; }
.lesson-title { font-family: var(--font); font-weight: 700; font-size: 1.05rem; }
.lesson-step { font-size: 0.85rem; color: var(--muted); }
.progress { height: 8px; background: var(--bg-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--teal), var(--green)); transition: width 0.4s ease; }

/* Symbols */
.sym { display: inline-flex; align-items: center; gap: 4px; vertical-align: middle; }
.sym i { display: inline-block; background: var(--amber); border-radius: 999px; box-shadow: 0 0 8px rgba(255, 207, 92, 0.6); }
.sym .dot { width: 8px; height: 8px; }
.sym .dash { width: 22px; height: 8px; }
.sym.md .dot { width: 11px; height: 11px; } .sym.md .dash { width: 30px; height: 11px; } .sym.md { gap: 6px; }
.sym.lg .dot { width: 16px; height: 16px; } .sym.lg .dash { width: 46px; height: 16px; } .sym.lg { gap: 9px; }

/* Intro */
.intro h2 { text-align: center; }
.intro-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; margin: 1rem 0; }
.intro-card { position: relative; display: flex; flex-direction: column; align-items: center; gap: 0.5rem; padding: 1.4rem 1rem; border-radius: 20px; border: 1px solid var(--line); background: linear-gradient(180deg, var(--surface-2), var(--bg-2)); color: var(--text); cursor: pointer; transition: transform 0.15s; }
.intro-card:hover { transform: translateY(-3px); }
.ic-char { font-family: var(--font); font-size: 4rem; font-weight: 800; line-height: 1; color: var(--amber); text-shadow: 0 0 30px rgba(255, 207, 92, 0.5); }
.ic-sound { font-family: var(--mono); color: var(--teal); font-size: 0.95rem; }
.ic-tip { font-size: 0.85rem; color: var(--muted); }
.lamp-dot { position: absolute; top: 12px; right: 12px; width: 14px; height: 14px; border-radius: 50%; background: #2c3a55; transition: background 0.05s, box-shadow 0.05s; }
.lamp-dot.on { background: var(--amber); box-shadow: 0 0 16px 4px rgba(255, 207, 92, 0.8); }
.intro-actions { text-align: center; margin-top: 0.6rem; }
.hint { text-align: center; color: var(--muted); font-size: 0.9rem; margin-top: 1rem; }

/* Drill */
.drill { text-align: center; }
.drill-stage { display: flex; flex-direction: column; align-items: center; gap: 1rem; padding: 1rem 0; }
.big-lamp { width: 120px; height: 120px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #3a4a68, #1a2540); border: 3px solid #2c3a55; transition: background 0.04s, box-shadow 0.04s; }
.big-lamp.on { background: radial-gradient(circle at 35% 35%, #fff6d0, var(--amber) 55%, var(--amber-2)); box-shadow: 0 0 60px 20px rgba(255, 207, 92, 0.55), 0 0 120px 40px rgba(255, 159, 60, 0.25); border-color: #fff2b3; }
.drill-answer { font-family: var(--font); font-size: 3rem; font-weight: 800; min-height: 1.2em; line-height: 1; }
.drill-answer.good { color: var(--green); } .drill-answer.bad { color: var(--red); }
.drill-feedback { min-height: 2.2em; margin: 0.4rem 0; font-size: 1rem; }
.drill-actions { display: flex; justify-content: center; align-items: center; gap: 0.8rem; flex-wrap: wrap; margin: 0.4rem 0 0.9rem; }
.streak-pill { background: var(--bg-2); border: 1px solid var(--line); padding: 0.3rem 0.7rem; border-radius: 999px; font-size: 0.85rem; }
.streak-pill.hot { border-color: var(--amber-2); color: var(--amber); box-shadow: 0 0 14px rgba(255, 159, 60, 0.35); }
.drill-keys { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.35rem; }
.key-chip { min-width: 40px; padding: 0.45rem 0.6rem; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-2); color: var(--text); font-family: var(--mono); font-weight: 700; cursor: pointer; }
.key-chip:hover { background: var(--surface-2); border-color: var(--teal); }

.send-target { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; padding: 0.5rem 0; }
.st-char { font-family: var(--font); font-size: 4rem; font-weight: 800; line-height: 1; color: var(--amber); }
.send-buffer { min-height: 34px; display: flex; justify-content: center; align-items: center; margin: 0.4rem 0; }

/* Straight key */
.key-wrap { display: flex; flex-direction: column; align-items: center; gap: 0.6rem; margin-top: 0.6rem; }
.key-base { position: relative; width: 200px; height: 70px; background: linear-gradient(180deg, #3b2a1a, #221609); border-radius: 12px; border: 1px solid #5a3f22; box-shadow: inset 0 4px 12px rgba(0,0,0,0.5), 0 8px 20px rgba(0,0,0,0.4); }
.key-arm { position: absolute; left: 30px; right: 30px; top: 18px; height: 8px; background: linear-gradient(180deg, #d9d2c2, #8a8272); border-radius: 4px; transform-origin: 20% 50%; transform: rotate(-8deg); transition: transform 0.05s; }
.key-knob { position: absolute; right: 26px; top: 0; width: 34px; height: 34px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #4a4a4a, #111); border: 2px solid #666; transform: translateY(-4px); transition: transform 0.05s; }
.key-pivot { position: absolute; left: 44px; top: 10px; width: 14px; height: 24px; background: #b8ad96; border-radius: 3px; }
.key-base.down .key-arm { transform: rotate(0deg); }
.key-base.down .key-knob { transform: translateY(6px); }
.key-base.down { box-shadow: inset 0 4px 12px rgba(0,0,0,0.5), 0 0 30px rgba(255, 207, 92, 0.35); }
.key-btn { display: flex; flex-direction: column; align-items: center; gap: 0.1rem; padding: 0.9rem 2rem; border-radius: 16px; border: 2px solid var(--amber); background: rgba(255, 207, 92, 0.08); color: var(--amber); font-family: var(--font); font-weight: 800; letter-spacing: 0.1em; cursor: pointer; user-select: none; -webkit-user-select: none; touch-action: none; }
.key-btn small { font-weight: 400; letter-spacing: 0; color: var(--muted); font-family: var(--font-body); }
.key-btn.down { background: var(--amber); color: #1a1200; box-shadow: 0 0 30px rgba(255, 207, 92, 0.6); }
.key-btn.down small { color: #4a3600; }

/* Answer form */
.answer-form { display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: center; margin: 0.6rem 0; }
.answer-input { flex: 1 1 280px; max-width: 560px; font-family: var(--mono); font-size: 1.15rem; letter-spacing: 0.1em; text-transform: uppercase; padding: 0.7rem 0.9rem; border-radius: 12px; border: 1px solid var(--line); background: var(--bg-2); color: var(--text); outline: none; }
.answer-input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(92, 225, 255, 0.2); }
.diff { font-family: var(--mono); font-size: 1.2rem; letter-spacing: 0.08em; margin: 0.4rem 0; word-break: break-word; }
.diff.lg { font-size: 1.35rem; }
.d-ok { color: var(--green); }
.d-wrong { color: var(--red); text-decoration: underline wavy; }
.d-miss { color: var(--amber); opacity: 0.8; border-bottom: 2px dotted var(--amber); }
.d-extra { color: var(--muted); text-decoration: line-through; }
.d-sp { display: inline-block; width: 0.6em; }

/* Summary */
.summary { text-align: center; }
.summary-ring { --p: 0; width: 150px; height: 150px; margin: 0.5rem auto 1rem; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--ring, var(--green)) calc(var(--p) * 1%), var(--bg-2) 0); position: relative; }
.summary-ring::before { content: ''; position: absolute; inset: 12px; border-radius: 50%; background: var(--surface); }
.summary-ring span { position: relative; font-family: var(--font); font-size: 2rem; font-weight: 800; }
.summary-ring.fail { --ring: var(--red); }
.summary-xp { font-family: var(--font); font-size: 2rem; font-weight: 800; color: var(--amber); margin: 0.4rem 0 0.8rem; text-shadow: 0 0 30px rgba(255, 207, 92, 0.5); }
.summary-actions { display: flex; gap: 0.6rem; justify-content: center; flex-wrap: wrap; }
.chip { display: inline-block; font-family: var(--mono); background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; padding: 0.15rem 0.5rem; font-size: 0.85rem; }

/* Practice */
.incoming { display: flex; justify-content: space-between; gap: 0.6rem; flex-wrap: wrap; font-size: 0.85rem; margin-bottom: 0.8rem; }
.inc-label { color: var(--teal); text-transform: uppercase; letter-spacing: 0.1em; font-weight: 700; }
.inc-from { color: var(--muted); }
.stage-wrap { border-radius: 16px; overflow: hidden; border: 1px solid var(--line); background: var(--bg-2); }
.scene { display: block; width: 100%; height: min(420px, 46vw); }
.star { fill: #fff; opacity: 0.8; animation: twinkle 3s infinite ease-in-out; }
@keyframes twinkle { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }
.wave { animation: waves 6s infinite ease-in-out; }
.wave.w2 { animation-duration: 8s; animation-direction: reverse; }
@keyframes waves { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(-40px); } }
.scene .lamp { fill: #3b4a66; transition: fill 0.03s; }
.scene .light-glow, .scene .beam { opacity: 0; transition: opacity 0.03s; }
.scene.on .lamp { fill: #fff8dc; }
.scene.on .light-glow { opacity: 1; }
.scene.on .beam { opacity: 0.9; }
.scene .window { fill: #2a3a55; }
.scene.on .window { fill: #ffd98a; }
.scene-sound { position: relative; height: 220px; display: grid; place-items: center; background: radial-gradient(circle at 50% 50%, #142a4a, #06101f); }
.scene-sound .speaker { font-size: 3.5rem; position: relative; z-index: 1; filter: grayscale(1) opacity(0.5); transition: filter 0.05s, transform 0.05s; }
.scene-sound.on .speaker { filter: none; transform: scale(1.12); }
.scene-sound .ring { position: absolute; width: 90px; height: 90px; border-radius: 50%; border: 2px solid var(--teal); opacity: 0; }
.scene-sound.on .ring { animation: ripple 0.9s ease-out infinite; }
.scene-sound .r2 { animation-delay: 0.3s !important; } .scene-sound .r3 { animation-delay: 0.6s !important; }
@keyframes ripple { from { transform: scale(0.6); opacity: 0.9; } to { transform: scale(3); opacity: 0; } }

.stream { position: relative; height: 200px; background: linear-gradient(180deg, #0a1a33, #050d1c); overflow: hidden; }
.stream-lane { position: absolute; left: 0; right: 0; top: 50%; height: 60px; transform: translateY(-50%); border-top: 1px dashed rgba(92, 225, 255, 0.2); border-bottom: 1px dashed rgba(92, 225, 255, 0.2); }
.stream-label { position: absolute; right: 12px; bottom: 8px; font-size: 0.75rem; color: var(--muted); }
.stream::after { content: ''; position: absolute; right: 0; top: 0; bottom: 0; width: 3px; background: rgba(255, 207, 92, 0.35); }
.stream-strip { position: absolute; left: 100%; top: 0; height: 100%; transform: translateX(0); will-change: transform; }
.st-item { position: absolute; top: 50%; }
.st-dot { width: 16px; height: 16px; margin-top: -8px; border-radius: 8px; background: var(--amber); box-shadow: 0 0 12px rgba(255, 207, 92, 0.8); }
.st-dash { width: 48px; height: 16px; margin-top: -8px; border-radius: 8px; background: var(--amber); box-shadow: 0 0 12px rgba(255, 207, 92, 0.8); }
.st-sep { width: 2px; height: 40px; margin-top: -20px; background: rgba(92, 225, 255, 0.35); }
.st-space { width: 4px; height: 56px; margin-top: -28px; background: var(--teal); box-shadow: 0 0 10px var(--teal); }

.read-stage { padding: 1.4rem 1rem; display: flex; flex-wrap: wrap; align-items: center; gap: 1rem 1.2rem; justify-content: center; min-height: 120px; }
.read-word { display: inline-flex; flex-wrap: wrap; gap: 0.9rem; padding: 0.4rem 0.6rem; border-radius: 10px; background: rgba(255,255,255,0.03); }
.read-sep { color: var(--teal); font-family: var(--mono); font-size: 1.4rem; }

.play-row { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; justify-content: center; margin: 0.9rem 0 0.2rem; }
.chk { display: inline-flex; align-items: center; gap: 0.4rem; color: var(--muted); font-size: 0.9rem; cursor: pointer; }
.practice-next { text-align: center; margin-top: 0.4rem; }
.reveal { margin-top: 0.5rem; font-family: var(--font); font-size: 1.05rem; }

.send-text { font-family: var(--mono); font-size: 1.5rem; letter-spacing: 0.12em; text-align: center; margin: 0.4rem 0; line-height: 1.8; word-break: break-word; }
.stc { display: inline-block; padding: 0 0.05em; border-bottom: 3px solid transparent; }
.stc.cur { border-bottom-color: var(--amber); background: rgba(255, 207, 92, 0.12); border-radius: 4px; }
.stc.ok { color: var(--green); } .stc.bad { color: var(--red); }
.send-hint { text-align: center; min-height: 1.8em; color: var(--muted); }
.send-live { font-family: var(--mono); font-size: 1.25rem; letter-spacing: 0.1em; text-align: center; min-height: 2em; padding: 0.5rem; border-radius: 10px; background: var(--bg-2); border: 1px solid var(--line); word-break: break-word; }

/* XP float, toasts, confetti */
.xp-float { position: absolute; right: 24px; top: 90px; z-index: 5; background: var(--amber); color: #1a1200; font-weight: 800; padding: 0.35rem 0.8rem; border-radius: 999px; animation: floatUp 1.6s ease-out forwards; pointer-events: none; font-size: 0.9rem; box-shadow: 0 4px 16px rgba(255, 207, 92, 0.5); }
@keyframes floatUp { from { opacity: 0; transform: translateY(10px); } 15% { opacity: 1; } to { opacity: 0; transform: translateY(-60px); } }
#toast-root { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: flex; flex-direction: column; gap: 0.5rem; max-width: 360px; }
.toast { background: var(--surface-2); border: 1px solid var(--line); border-left: 4px solid var(--teal); border-radius: 14px; padding: 0.8rem 1rem; box-shadow: var(--shadow); opacity: 0; transform: translateX(20px); transition: all 0.35s ease; font-size: 0.9rem; }
.toast.show { opacity: 1; transform: none; }
.toast.level { border-left-color: var(--amber); }
.toast.badge { border-left-color: var(--purple); }
.toast-big { font-family: var(--font); font-weight: 800; font-size: 1.1rem; }
.confetti { position: absolute; top: -10px; width: 10px; height: 14px; border-radius: 2px; z-index: 4; animation: confetti 2s ease-in forwards; pointer-events: none; }
@keyframes confetti { to { transform: translateY(110vh) rotate(720deg); opacity: 0; } }

/* Modal */
#modal-root { display: none; }
#modal-root.open { display: block; }
.modal-back { position: fixed; inset: 0; background: rgba(2, 6, 16, 0.75); backdrop-filter: blur(6px); z-index: 50; display: grid; place-items: center; padding: 1rem; overflow: auto; }
.modal { width: min(560px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 1.5rem; box-shadow: var(--shadow); animation: fadeIn 0.25s ease; }
.modal h3 { font-size: 1.4rem; }
.modal-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.8rem; }
.settings-grid { display: grid; gap: 0.7rem; }
.settings-grid label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; color: var(--muted); }
.settings-grid label.chk { flex-direction: row; align-items: center; }
.settings-grid input[type="text"] { font: inherit; padding: 0.55rem 0.7rem; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-2); color: var(--text); }
.settings-grid input[type="range"] { accent-color: var(--amber); }
.settings-grid output { color: var(--amber); font-weight: 700; }
details.danger { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: 0.6rem; }
details.danger summary { cursor: pointer; color: var(--muted); }
details.danger textarea { width: 100%; font-family: var(--mono); font-size: 0.75rem; background: var(--bg-2); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 0.5rem; }

/* ---------------- Article / SEO content ---------------- */
.guide { padding: 1rem 0 4rem; }
.guide-inner { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 2.5rem; align-items: start; }
.guide-inner > * { min-width: 0; }
.toc { position: sticky; top: 76px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 1rem; font-size: 0.9rem; }
.toc h2 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin-bottom: 0.5rem; }
.toc ol { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.25rem; }
.toc a { color: var(--text); text-decoration: none; display: block; padding: 0.25rem 0.4rem; border-radius: 8px; }
.toc a:hover { background: var(--surface-2); color: var(--amber); }
@media (max-width: 900px) { .guide-inner { grid-template-columns: 1fr; } .toc { position: static; } }
.prose { max-width: 78ch; font-size: 1.04rem; }
.prose h2 { font-size: clamp(1.5rem, 3vw, 2rem); margin-top: 2.4rem; padding-top: 0.6rem; border-top: 1px solid var(--line); }
.prose h2:first-child { margin-top: 0; border-top: 0; }
.prose h3 { font-size: 1.25rem; margin-top: 1.6rem; color: var(--amber); }
.prose h4 { font-size: 1.05rem; margin-top: 1.2rem; }
.prose p, .prose li { color: #cfd8f0; }
.prose strong { color: var(--text); }
.prose ul, .prose ol { padding-left: 1.3rem; }
.prose li { margin-bottom: 0.35rem; }
.prose blockquote { margin: 1.2rem 0; padding: 0.8rem 1.2rem; border-left: 4px solid var(--amber); background: var(--surface); border-radius: 0 12px 12px 0; font-style: italic; }
.prose code { font-family: var(--mono); background: var(--surface-2); padding: 0.1em 0.4em; border-radius: 6px; font-size: 0.9em; letter-spacing: 0.05em; }
.callout { background: linear-gradient(135deg, rgba(255, 207, 92, 0.12), rgba(92, 225, 255, 0.08)); border: 1px solid rgba(255, 207, 92, 0.35); border-radius: 16px; padding: 1rem 1.2rem; margin: 1.2rem 0; }
.callout strong { color: var(--amber); }
.table-wrap { overflow-x: auto; margin: 1rem 0; border: 1px solid var(--line); border-radius: 14px; }
table { border-collapse: collapse; width: 100%; font-size: 0.95rem; }
th, td { text-align: left; padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--surface-2); font-family: var(--font); font-weight: 700; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
tbody tr:hover { background: rgba(255,255,255,0.03); }
td.ch { font-family: var(--font); font-weight: 800; font-size: 1.2rem; color: var(--amber); width: 3ch; }
td.code { font-family: var(--mono); letter-spacing: 0.15em; white-space: nowrap; }
.morse-table td:nth-child(3) { white-space: nowrap; }
.play { border: 1px solid var(--line); background: var(--bg-2); color: var(--teal); border-radius: 8px; padding: 0.2rem 0.55rem; cursor: pointer; font-size: 0.85rem; white-space: nowrap; }
.play:hover { background: var(--surface-2); }
.play.playing { background: var(--amber); color: #1a1200; border-color: var(--amber); }
.try-box { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 1rem; margin: 1rem 0; }
.try-box .row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.try-box input { flex: 1 1 240px; font-family: var(--mono); font-size: 1.05rem; text-transform: uppercase; letter-spacing: 0.1em; padding: 0.6rem 0.8rem; border-radius: 10px; border: 1px solid var(--line); background: var(--bg-2); color: var(--text); }
.try-out { margin-top: 0.8rem; display: flex; flex-wrap: wrap; gap: 0.7rem 0.9rem; align-items: center; min-height: 32px; }
.try-ch { display: inline-flex; padding: 0.2rem 0.4rem; border-radius: 8px; background: var(--bg-2); }
.faq details { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); padding: 0.2rem 1rem; margin-bottom: 0.6rem; }
.faq summary { cursor: pointer; font-family: var(--font); font-weight: 700; padding: 0.6rem 0; color: var(--text); }
.faq summary::marker { color: var(--amber); }
.faq details p { margin: 0.2rem 0 0.8rem; }
.timeline { list-style: none; padding: 0; margin: 1rem 0; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 0 1rem 1.4rem; }
.timeline li::before { content: ''; position: absolute; left: -7px; top: 0.45em; width: 12px; height: 12px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 10px rgba(255, 207, 92, 0.6); }
.timeline b { color: var(--amber); font-family: var(--mono); margin-right: 0.4rem; }
.mode-guide { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0.8rem; margin: 1rem 0; }
.mode-guide div { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 0.9rem 1rem; }
.mode-guide h4 { margin: 0 0 0.3rem; }
.mode-guide p { font-size: 0.92rem; margin: 0; }

/* Byline, at-a-glance, sources */
.byline { font-size: 0.9rem; color: var(--muted); margin: 0 0 1.2rem; padding-bottom: 0.8rem; border-bottom: 1px solid var(--line); }
.byline a { color: var(--amber); }
.glance th { width: 30%; color: var(--amber); text-transform: none; letter-spacing: 0; font-size: 0.95rem; background: transparent; }
.sources li { font-size: 0.95rem; }
.sources a { color: var(--teal); }

/* Ad slots: hidden until js/ads.js enables them; heights reserved to avoid layout shift */
.ad-slot { display: none; }
html.ads-enabled .ad-slot { display: block; position: relative; min-height: 280px; margin: 1.5rem auto; border: 1px dashed var(--line); border-radius: 14px; overflow: hidden; background: rgba(255,255,255,0.02); }
html.ads-enabled .ad-slot.ad-sidebar { min-height: 600px; margin: 1rem 0 0; }
html.ads-enabled .ad-slot.ad-inline { min-height: 250px; }
.ad-label { position: absolute; top: 4px; left: 8px; font-size: 0.65rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); opacity: 0.7; }
.ad-slot ins { width: 100%; }

.site-footer { border-top: 1px solid var(--line); padding: 2rem 0 3rem; color: var(--muted); font-size: 0.9rem; }
.site-footer .container { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.site-footer a { color: var(--muted); }

@media (max-width: 520px) {
  .app { padding: 0.7rem; border-radius: 18px; }
  .card { padding: 1rem; }
  .send-text { font-size: 1.15rem; letter-spacing: 0.08em; }
  .diff.lg { font-size: 1.1rem; }
  .ic-char { font-size: 3rem; }
  .big-lamp { width: 96px; height: 96px; }
}

@media (prefers-reduced-motion: reduce) {
  .star, .wave, .path-node.current, .confetti { animation: none !important; }
  .st-item { transition-duration: 7s; }
}
