:root {
  --bg: #14102a; --panel: #1f1a3d; --panel2: #2a2452; --text: #f1f0fa; --muted: #b0aad0;
  --accent: #f3d36b; --moon: #dfe8ff; --line: #3d3670; --good: #6ee08a; --bad: #ff6b7d;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; display: flex; flex-direction: column; height: 100dvh;
  background: var(--bg); color: var(--text); overflow: hidden;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
}
a { color: var(--accent); text-underline-offset: 3px; }
a:focus-visible, button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button { font: inherit; color: inherit; }

.bar {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); font-size: 14px; flex: none;
}
.bar .home { color: var(--muted); text-decoration: none; }
.bar .home:hover { color: var(--text); }
.bar .account { color: var(--muted); text-align: right; }
.bar .account strong { color: var(--text); }
@media (max-width: 520px) { .bar .account .long { display: none; } .bar { font-size: 13px; } }

#stage { position: relative; flex: 1; min-height: 0; overflow: hidden; }
#screen { position: absolute; inset: 0; width: 100%; height: 100%; display: block; image-rendering: auto; }

.foot {
  display: flex; justify-content: center; align-items: center; gap: 16px; flex: none;
  padding: 6px 16px; padding-bottom: max(6px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line);
}
.foot .keys { color: var(--muted); font-size: 12px; }
@media (max-width: 700px), (pointer: coarse) { .foot .keys { display: none; } }

/* Buy me a coffee: the same badge on every game (see ADDING_A_GAME.md). */
.bmc {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  background: #ffdd00; color: #0d0c22;
  font: 600 14px/1.2 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  text-decoration: none; white-space: nowrap;
}
.bmc:hover { background: #ffe74d; }
.bmc:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.bmc svg { width: 18px; height: 18px; flex: none; }

/* Title */
.title {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 24px 16px; gap: 12px;
}
.title h1 {
  font-family: Georgia, "Times New Roman", serif; font-size: clamp(40px, 9vw, 84px); margin: 0;
  color: var(--moon); text-shadow: 0 0 24px rgba(200, 220, 255, 0.6), 0 4px 0 #0a0818; letter-spacing: 1px;
}
.title .tag { max-width: 560px; color: var(--muted); margin: 0; font-size: 16px; line-height: 1.5; text-shadow: 0 1px 2px #000; }
.titlebtns { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; min-width: 240px; }
.title .hint { color: var(--muted); font-size: 13px; max-width: 420px; margin: 4px 0 0; }

.btn {
  display: block; width: 100%; padding: 12px 18px; border-radius: 12px; border: 2px solid var(--line);
  background: var(--panel2); color: var(--text); font-size: 16px; font-weight: 600; cursor: pointer; text-align: left;
}
.btn:hover:not(:disabled), .btn.sel { border-color: var(--accent); background: #352d66; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: #4a3fa0; border-color: #7a6ae0; text-align: center; }
.btn .sub { display: block; font-size: 12px; font-weight: 400; color: var(--muted); margin-top: 2px; }
.btn .right { float: right; font-weight: 400; color: var(--muted); font-size: 14px; }

/* HUD */
#hud { position: absolute; top: 8px; left: 8px; right: 8px; display: flex; gap: 8px; align-items: center; pointer-events: none; }
.hudbtn {
  pointer-events: auto; padding: 8px 12px; border-radius: 10px; border: 2px solid rgba(255,255,255,0.25);
  background: rgba(20, 16, 42, 0.75); color: var(--text); font-weight: 600; font-size: 14px; cursor: pointer;
}
#place { margin-left: auto; padding: 6px 12px; border-radius: 10px; background: rgba(20,16,42,0.6); font-size: 14px; color: var(--moon); }

/* Touch controls */
#touch { position: absolute; left: 0; right: 0; bottom: 8px; pointer-events: none; }
.dpad { position: absolute; left: 12px; bottom: 0; width: 150px; height: 150px; pointer-events: auto; }
.dpad button, .abtn {
  position: absolute; width: 50px; height: 50px; border-radius: 12px; border: 2px solid rgba(255,255,255,0.3);
  background: rgba(20, 16, 42, 0.6); color: #fff; font-size: 20px; touch-action: none;
}
.dpad [data-dir=up] { left: 50px; top: 0; }
.dpad [data-dir=down] { left: 50px; top: 100px; }
.dpad [data-dir=left] { left: 0; top: 50px; }
.dpad [data-dir=right] { left: 100px; top: 50px; }
.abtn { right: 20px; bottom: 30px; width: 70px; height: 70px; border-radius: 50%; pointer-events: auto; font-weight: 700; font-size: 24px; background: rgba(74, 63, 160, 0.8); }

/* Dialogue & panels */
#ui { position: absolute; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
.say {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 12px; width: min(720px, calc(100% - 24px));
  background: rgba(20, 16, 42, 0.95); border: 2px solid var(--moon); border-radius: 14px; padding: 14px 18px 22px;
  font-size: 17px; line-height: 1.5; box-shadow: 0 6px 24px rgba(0,0,0,0.5); cursor: pointer; min-height: 90px;
}
.say .who { font-weight: 700; color: var(--accent); margin-bottom: 4px; font-size: 15px; }
.say .more { position: absolute; right: 14px; bottom: 6px; color: var(--muted); font-size: 13px; animation: bob 1s infinite; }
@keyframes bob { 50% { transform: translateY(3px); } }

.panel {
  position: absolute; inset: 12px; max-width: 760px; margin: 0 auto; display: flex; flex-direction: column;
  background: rgba(24, 20, 50, 0.97); border: 2px solid var(--line); border-radius: 16px; box-shadow: 0 8px 32px rgba(0,0,0,0.6);
  overflow: hidden;
}
.panel.small { inset: auto 12px 12px; max-height: calc(100% - 24px); }
.panel header { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); flex: none; }
.panel header h2 { margin: 0; font-size: 19px; flex: 1; }
.panel header .x { border: none; background: var(--panel2); border-radius: 8px; padding: 6px 12px; cursor: pointer; font-weight: 600; }
.panel .body { padding: 12px 16px 16px; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; user-select: text; }
.panel .body p { color: var(--muted); line-height: 1.5; margin: 6px 0 12px; }
.panel .tabs { display: flex; gap: 6px; padding: 8px 12px 0; flex-wrap: wrap; flex: none; }
.panel .tabs button { border: 1px solid var(--line); background: var(--panel); border-radius: 8px 8px 0 0; padding: 8px 12px; cursor: pointer; }
.panel .tabs button.on { background: var(--panel2); border-color: var(--accent); }

.list { display: flex; flex-direction: column; gap: 8px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.card { background: var(--panel); border: 2px solid var(--line); border-radius: 12px; padding: 10px; }
.card.click { cursor: pointer; }
.card.click:hover, .card.sel { border-color: var(--accent); }
.card h3 { margin: 0 0 4px; font-size: 16px; }
.card .meta { color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; }
.row canvas { flex: none; }
.bar-hp { height: 8px; border-radius: 4px; background: #0a0818; overflow: hidden; margin-top: 4px; }
.bar-hp > i { display: block; height: 100%; background: var(--good); }
.bar-hp.xp > i { background: #7ab8ff; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; color: #120e24; margin: 2px 4px 2px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip { border: 2px solid var(--line); background: var(--panel); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: 14px; }
.chip.on { border-color: var(--accent); background: #3a3270; }
.chip:disabled { opacity: 0.4; cursor: default; }
.preview { background: #120e28; border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-top: 10px; }
.preview h3 { margin: 0 0 6px; color: var(--moon); }
.secret { color: var(--muted); font-style: italic; }
h4 { margin: 14px 0 6px; color: var(--accent); font-size: 14px; text-transform: uppercase; letter-spacing: 1px; }

/* Battle */
.bmenu {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 10px; width: min(760px, calc(100% - 16px));
  background: rgba(20, 16, 42, 0.95); border: 2px solid var(--moon); border-radius: 14px; padding: 10px; max-height: 55%;
  display: flex; flex-direction: column; gap: 8px;
}
.bmenu .q { font-size: 15px; color: var(--moon); padding: 2px 4px; }
.bmenu .opts { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 6px; overflow-y: auto; }
.bmenu .opts .btn { padding: 9px 12px; font-size: 15px; }
.blog {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 10px; width: min(760px, calc(100% - 16px));
  background: rgba(20, 16, 42, 0.92); border: 2px solid var(--moon); border-radius: 14px; padding: 12px 16px; font-size: 16px;
  min-height: 64px; line-height: 1.45; cursor: pointer;
}
.blog .more { position: absolute; right: 14px; bottom: 6px; color: var(--muted); font-size: 13px; animation: bob 1s infinite; }
.intent { color: var(--muted); font-size: 12px; }

#toast {
  position: absolute; top: 54px; left: 50%; transform: translateX(-50%); pointer-events: none;
  background: rgba(20,16,42,0.92); border: 1px solid var(--accent); border-radius: 10px; padding: 8px 14px;
  font-size: 15px; opacity: 0; transition: opacity 0.3s; max-width: calc(100% - 24px); text-align: center;
}
#toast.on { opacity: 1; }
.fade { position: absolute; inset: 0; background: #000; pointer-events: none; opacity: 0; transition: opacity 0.25s; }

.codeinput {
  width: 100%; font: 700 32px/1.2 ui-monospace, monospace; letter-spacing: 12px; text-align: center; text-transform: uppercase;
  padding: 10px; border-radius: 12px; border: 2px solid var(--line); background: #120e28; color: var(--text);
}
.codeinput:focus { outline: 3px solid var(--accent); }

/* Health and magic, small and out of the way. */
#vitals {
  display: flex; flex-direction: column; gap: 3px; padding: 5px 8px; border-radius: 10px;
  background: rgba(20, 16, 42, 0.6); pointer-events: none; font: 600 10px/1 system-ui, sans-serif; color: var(--muted);
}
.vital { display: flex; align-items: center; gap: 5px; }
.vital .lbl { width: 16px; }
.vital .track { width: 70px; height: 5px; border-radius: 3px; background: rgba(0, 0, 0, 0.5); overflow: hidden; }
.vital i { display: block; height: 100%; width: 100%; background: #6ee08a; transition: width 0.3s; }
.vital.mp i { background: #7ab8ff; }
.vital .num { min-width: 44px; color: var(--text); font-variant-numeric: tabular-nums; }
@media (max-width: 420px) { .vital .track { width: 44px; } }

/* Whatever the keyboard has selected stands out. */
.card:focus-visible, .chip:focus-visible, .btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.card:focus { border-color: var(--accent); }
