:root {
  --bg: #05070f;
  --ink: #eef1fb;
  --muted: #9aa6c8;
  --card: rgba(12, 17, 38, 0.94);
  --line: rgba(255, 255, 255, 0.12);
  --gold: #ffd166;
  --gold-ink: #2a1d00;
  --red: #ff6b6b;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ui);
}

#wrap {
  max-width: 992px;
  margin: 0 auto;
  padding: 16px;
}

#stage {
  position: relative;
  width: 100%;
  aspect-ratio: 960 / 600;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), 0 0 0 1px var(--line);
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  cursor: text;
}

#kb {
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  border: 0;
  padding: 0;
  font-size: 16px; /* stops iOS zooming on focus */
}

#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(4, 7, 18, 0.55);
  backdrop-filter: blur(2px);
  overflow: auto;
}

#overlay.hidden { display: none; }

@media (max-width: 720px) {
  #overlay { position: fixed; z-index: 10; align-items: flex-start; }
}

.card {
  width: 100%;
  max-width: 540px;
  margin: auto;
  padding: 26px 28px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
}

.card.wide { max-width: 760px; }

.card h1 {
  margin: 0 0 4px;
  font-size: clamp(34px, 6vw, 48px);
  letter-spacing: 0.04em;
  font-weight: 800;
  background: linear-gradient(180deg, #fff6d6, var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.card h2 { margin: 0 0 10px; font-size: 24px; }
.card p { color: var(--muted); line-height: 1.5; margin: 8px 0; }
.card .tag { font-size: 16px; color: #c9d2ee; }

.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.stack { display: grid; gap: 10px; margin-top: 18px; }

button {
  font: 600 16px var(--ui);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 16px;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s, border-color 0.15s;
}
button:hover { background: rgba(255, 255, 255, 0.12); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
button.primary { background: var(--gold); color: var(--gold-ink); border-color: transparent; }
button.primary:hover { background: #ffdc85; }
button.sel { border-color: var(--gold); background: rgba(255, 209, 102, 0.14); }

.diffs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.diffs button { padding: 10px 6px; display: grid; gap: 2px; }
.diffs small { font-weight: 400; color: var(--muted); font-size: 12px; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 14px; }
.stat { background: rgba(255, 255, 255, 0.05); border-radius: 10px; padding: 10px 12px; }
.stat b { display: block; font-size: 22px; color: var(--ink); }
.stat span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }

table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 14px; }
th, td { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
td.num { font-variant-numeric: tabular-nums; }

/* Practice mode */
.lessons { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.lessons button { padding: 7px 10px; font-size: 13px; }
.drill {
  font: 500 clamp(18px, 3vw, 26px) / 1.6 var(--mono);
  background: rgba(0, 0, 0, 0.3);
  border-radius: 12px;
  padding: 14px 16px;
  margin-top: 14px;
  word-break: break-all;
}
.drill .done { color: #6f7ca3; }
.drill .cur { background: var(--gold); color: var(--gold-ink); border-radius: 3px; }
.drill .cur.bad { background: var(--red); color: #fff; }
.drill .todo { color: var(--ink); }
.pmeta { display: flex; gap: 16px; margin-top: 8px; color: var(--muted); font-size: 14px; }

.kbd { margin-top: 14px; display: grid; gap: 5px; justify-content: center; }
.kbd .krow { display: flex; gap: 5px; justify-content: center; }
.kbd .key {
  width: clamp(24px, 5.2vw, 40px);
  height: clamp(26px, 5.2vw, 40px);
  display: grid;
  place-items: center;
  border-radius: 7px;
  font: 600 13px var(--mono);
  color: #dfe5f7;
  background: color-mix(in srgb, var(--f) 22%, #111833);
  border: 1px solid color-mix(in srgb, var(--f) 45%, transparent);
}
.kbd .key.space { width: clamp(140px, 36vw, 260px); }
.kbd .key.next { background: var(--f); color: #0b0f1e; transform: translateY(-2px); box-shadow: 0 0 14px var(--f); }
.legend { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 10px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }

.foot {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  justify-content: center;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 13px;
}
kbd {
  font: 600 12px var(--mono);
  padding: 2px 6px;
  border-radius: 5px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
}

/* ---------- Keyfarer additions ---------- */
.card h3 { margin: 18px 0 4px; font-size: 16px; }
.row.tight { margin-top: 10px; gap: 8px; }
button.danger { border-color: var(--red); color: #ffd0d0; background: rgba(255, 107, 107, 0.14); }
.scroll-x { overflow-x: auto; }

.slots { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
@media (max-width: 640px) { .slots { grid-template-columns: 1fr; } }
.slot {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.slot.empty { border-style: dashed; justify-content: space-between; }
.slot-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.slot-head b { font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot-head span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.slot p { font-size: 13px; margin: 4px 0 0; }
.slot .row button { flex: 1; padding: 9px 10px; font-size: 14px; }

.field { display: grid; gap: 6px; margin-top: 12px; color: var(--muted); font-size: 14px; }
.field input {
  font: 600 18px var(--ui);
  color: var(--ink);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
}
.field input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.diffs.five { grid-template-columns: repeat(5, minmax(0, 1fr)); }
@media (max-width: 640px) { .diffs.five { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* star map */
.card.map-card { max-width: 900px; padding: 18px 20px; }
.map-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.map-head b { color: var(--ink); }
.diffsel select {
  font: 600 14px var(--ui);
  color: var(--ink);
  background: #10172f;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 8px;
  margin-left: 6px;
}
@keyframes dash { to { stroke-dashoffset: -36; } }
@keyframes glow { from { filter: drop-shadow(0 0 2px rgba(255, 209, 102, 0.4)); } to { filter: drop-shadow(0 0 10px rgba(255, 209, 102, 0.9)); } }

.branch { margin: 10px 0 0; font-size: 14px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { padding: 6px 10px; font-size: 13px; border-radius: 999px; }
.info { display: flex; flex-wrap: wrap; gap: 12px 18px; justify-content: space-between; align-items: flex-end; margin-top: 10px; }
.info > div:first-child { flex: 1 1 340px; }
.info h2 { margin: 0 0 4px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.info p { margin: 4px 0; font-size: 14px; }
.info .meta { font-size: 13px; }
.info-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.pill { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; padding: 3px 8px; border-radius: 999px; background: rgba(255, 209, 102, 0.18); color: var(--gold); }
.pill.red { background: rgba(255, 107, 107, 0.18); color: var(--red); }

/* training keyboard extras */
.kbd .key.wide { width: clamp(36px, 8vw, 62px); font-size: 11px; }

/* map layout: details beside the map on wide screens */
.card.map-card { max-width: 940px; }
.map-body { display: grid; grid-template-columns: minmax(0, 1.75fr) minmax(220px, 1fr); gap: 16px; margin-top: 8px; align-items: start; }
.map-body svg.map { margin-top: 0; }
.map-body .info { flex-direction: column; align-items: stretch; margin-top: 0; }
.map-body .info > div:first-child { flex: none; }
.map-body .info h2 { font-size: 21px; }
@media (max-width: 760px) { .map-body { grid-template-columns: 1fr; } }
