:root {
  --bg: #f6f3ee;
  --ink: #1b1f24;
  --muted: #5b6470;
  --card: #ffffff;
  --line: #e3ddd3;
  --accent: #ff7a2f;
  --accent-ink: #ffffff;
  --focus: #1d70d6;
  --radius: 18px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; padding-inline: 16px; padding-block: 0 40px; color: var(--ink); background: var(--bg); min-height: 100vh; }
[hidden] { display: none !important; }

.topbar {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-block: 16px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 40px; height: 40px; border-radius: 14px;
  background: radial-gradient(circle at 35% 40%, #1b1f24 0 3px, transparent 4px),
              radial-gradient(circle at 65% 40%, #1b1f24 0 3px, transparent 4px), var(--accent);
}
h1 { font-size: 1.35rem; margin: 0; letter-spacing: -0.01em; }
.tag { margin: 2px 0 0; color: var(--muted); font-size: 0.92rem; }
.links { display: flex; gap: 8px; }

button, .ghost, select, input[type='text'] {
  font: inherit;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: var(--card);
  color: var(--ink);
  padding: 10px 16px;
  cursor: pointer;
  text-decoration: none;
}
button:hover, .ghost:hover { border-color: #cfc6b8; }
button.primary, .primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}
:focus-visible { outline: 4px solid var(--focus); outline-offset: 2px; }

main { max-width: 1100px; margin: 0 auto; }

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  background: #bfe3ff;
  box-shadow: 0 10px 30px rgba(27, 31, 36, 0.12);
}
#game { width: 100%; height: 100%; display: block; }

.hud {
  position: absolute; inset: 12px 12px auto 12px;
  display: flex; justify-content: space-between; align-items: flex-start; pointer-events: none;
}
.target {
  display: flex; align-items: center; gap: 10px;
  background: rgba(255, 255, 255, 0.94);
  border-radius: 999px;
  padding: 6px 8px 6px 18px;
  font-weight: 800;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}
.find { font-size: clamp(0.9rem, 2vw, 1.2rem); color: var(--muted); }
.target-label {
  min-width: 2.2em; height: 2.2em; padding: 0 0.6em;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px;
  font-size: clamp(1.2rem, 3.4vw, 2rem);
  background: #14213d; color: #fff;
}
.stars {
  background: rgba(255, 255, 255, 0.94);
  border-radius: 999px;
  padding: 8px 16px;
  font-weight: 800;
  font-size: clamp(1rem, 2.6vw, 1.5rem);
}
.stars::before { content: '\2605  '; color: #f4b400; }

.preview-wrap {
  position: absolute; right: 12px; bottom: 12px;
  width: clamp(120px, 22%, 220px);
  border-radius: 12px; overflow: hidden;
  border: 3px solid rgba(255, 255, 255, 0.85);
  background: #111;
}
#preview { width: 100%; display: block; aspect-ratio: 4 / 3; }
.preview-stats {
  position: absolute; left: 6px; top: 4px;
  font: 600 11px/1.3 ui-monospace, Menlo, monospace; color: #fff; text-shadow: 0 1px 2px #000;
}

.toast {
  position: absolute; left: 50%; top: 18%; transform: translateX(-50%);
  background: rgba(20, 33, 61, 0.9); color: #fff;
  padding: 10px 18px; border-radius: 999px; font-weight: 700;
  font-size: clamp(0.95rem, 2.4vw, 1.3rem);
  opacity: 0; transition: opacity 0.25s;
  pointer-events: none; text-align: center; max-width: 90%;
}
.toast.show { opacity: 1; }

.touch-controls {
  position: absolute; left: 12px; bottom: 12px; display: flex; gap: 10px;
}
.tc {
  width: clamp(54px, 9vw, 76px); height: clamp(54px, 9vw, 76px);
  border-radius: 50%; font-size: 1.4rem; font-weight: 800;
  background: rgba(255, 255, 255, 0.9);
  touch-action: none;
}
.tc.jump { width: auto; padding: 0 22px; border-radius: 999px; background: var(--accent); color: #fff; border-color: var(--accent); }

.overlay {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: rgba(246, 243, 238, 0.82);
  backdrop-filter: blur(4px);
  padding: 16px;
  overflow: auto;
}
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: clamp(16px, 3vw, 28px);
  max-width: 620px; width: 100%;
  box-shadow: 0 14px 40px rgba(27, 31, 36, 0.16);
}
.card h2 { margin: 0 0 8px; font-size: clamp(1.2rem, 3vw, 1.7rem); }
.card p { margin: 0 0 12px; line-height: 1.5; }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin: 16px 0; }
.big { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 16px 18px; text-align: left; }
.big strong { font-size: 1.1rem; }
.big span { font-size: 0.9rem; opacity: 0.85; }
.fine { color: var(--muted); font-size: 0.85rem; }
.linkish { border: none; background: none; padding: 0; color: var(--focus); text-decoration: underline; font-size: inherit; }
.status { min-height: 1.4em; font-weight: 600; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }

.cal-bar { position: relative; height: 28px; border-radius: 999px; background: #eee6da; margin: 18px 0 8px; }
.cal-range { position: absolute; top: 0; bottom: 0; left: 50%; width: 0; background: #ffd2b5; border-radius: 999px; }
.cal-dot { position: absolute; top: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); left: calc(50% - 11px); }
.countdown { font-size: 1.4rem; font-weight: 800; min-height: 1.6em; }

.summary { display: grid; grid-template-columns: auto auto; gap: 6px 18px; margin: 8px 0 16px; }
.summary dt { color: var(--muted); }
.summary dd { margin: 0; font-weight: 700; }

.help {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px; margin-top: 20px;
}
.help > div { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.help h3 { margin: 0 0 8px; font-size: 1rem; }
.help ul { margin: 0; padding-left: 18px; line-height: 1.6; }
.help p { margin: 0; line-height: 1.55; color: var(--muted); }
kbd { border: 1px solid var(--line); border-bottom-width: 3px; border-radius: 6px; padding: 0 6px; font: 600 0.85em ui-monospace, monospace; background: var(--card); color: inherit; }

dialog {
  border: none; border-radius: var(--radius); padding: 0;
  width: min(560px, calc(100% - 32px)); max-height: calc(100% - 32px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
dialog::backdrop { background: rgba(27, 31, 36, 0.45); }
.settings-form { padding: 20px 22px; display: grid; gap: 12px; }
.settings-form h2 { margin: 0; }
fieldset { border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px 14px; display: grid; gap: 8px; }
legend { font-weight: 700; padding: 0 6px; }
.settings-form label { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.settings-form label:has(input[type='radio']), .settings-form label:has(input[type='checkbox']) { justify-content: flex-start; }
input[type='range'] { width: min(220px, 100%); accent-color: var(--accent); }
input[type='radio'], input[type='checkbox'] { width: 20px; height: 20px; accent-color: var(--accent); }

body.contrast { --bg: #000; --ink: #fff; --muted: #d0d0d0; --card: #111; --line: #fff; --accent: #ffd400; --accent-ink: #000; }
body.contrast .target, body.contrast .stars { background: #000; color: #fff; border: 3px solid #fff; }
body.contrast .overlay { background: rgba(0, 0, 0, 0.88); }
body.contrast .tc { background: #000; color: #fff; border: 3px solid #fff; }
body.contrast .tc.jump { background: #ffd400; color: #000; border-color: #ffd400; }
body.contrast .target-label { border: 2px solid #fff; }

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}
@media (max-width: 640px) {
  /* The stage is too short for cards on a phone, so overlays take the screen. */
  .overlay { position: fixed; z-index: 20; align-items: start; }
  /* Touch buttons sit under the game instead of covering it. */
  .stage { aspect-ratio: auto; }
  #game { height: auto; aspect-ratio: 16 / 9; }
  .touch-controls { position: static; justify-content: center; padding: 10px; background: var(--card); }
  .hud { inset: 6px 6px auto 6px; }
  .target { padding: 3px 4px 3px 10px; gap: 6px; }
  .preview-wrap { width: 34%; right: 6px; bottom: 6px; }
}
