:root {
  color-scheme: dark;
  --bg: #0b0b0e;
  --panel: #15151a;
  --line: #2a2a31;
  --text: #f1f1f4;
  --dim: #8c8c96;
  --accent: #3d7bff;
  --gold: #ffcc40;
  --ok: #5ad1c8;
  --bad: #ff5a52;
  --lock: #ffd933;
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

body.playing { overflow: hidden; }

[hidden] { display: none !important; }

a { color: var(--accent); }

button, select {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 16px;
  cursor: pointer;
}
button:disabled { opacity: 0.4; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

.view {
  max-width: 560px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
}
.view.wide { max-width: 1240px; }

.back {
  display: inline-block;
  color: var(--dim);
  text-decoration: none;
  margin-bottom: 8px;
  padding: 4px 0;
}

h1, h2, h3 { margin: 0; }
h2 { font-size: 28px; margin-bottom: 16px; }

.hero { padding: 12vh 0 32px; }
.hero h1 {
  font-size: clamp(44px, 12vw, 72px);
  letter-spacing: -0.03em;
  background: linear-gradient(180deg, #fff 30%, #9fb8ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero p { color: var(--dim); font-size: 18px; line-height: 1.5; margin: 12px 0 0; }

.choices { display: grid; gap: 14px; }
@media (min-width: 640px) { .choices { grid-template-columns: 1fr 1fr; } }
.choice {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 28px 22px;
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.15s, transform 0.15s;
}
.choice:hover { border-color: var(--accent); transform: translateY(-2px); }
.choice-title { font-size: 30px; font-weight: 700; }
.choice-sub { color: var(--dim); }
.aside { color: var(--dim); margin-top: 28px; text-align: center; }

.label { display: block; color: var(--dim); font-size: 14px; margin-bottom: 6px; }
textarea {
  width: 100%;
  font: inherit;
  font-size: 18px;
  line-height: 1.5;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  resize: vertical;
}
textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.meta { display: flex; justify-content: space-between; color: var(--dim); font-size: 14px; margin: 8px 2px 18px; font-variant-numeric: tabular-nums; }
.meta .over { color: var(--bad); font-weight: 600; }
#start { width: 100%; padding: 16px; font-size: 19px; border-radius: 14px; }
.hint { color: var(--dim); font-size: 14px; line-height: 1.5; }

#player { position: fixed; inset: 0; background: #000; z-index: 10; touch-action: none; }
#chart { display: block; }
.stop {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  padding: 0 18px;
  border-radius: 999px;
  background: rgba(40, 40, 46, 0.85);
  border-color: #444;
  color: #ddd;
}

.viewfinder {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  max-height: 70vh;
  margin: 0 auto;
  background: #000;
  border-radius: 16px;
  overflow: hidden;
}
.viewfinder video, .viewfinder canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.viewfinder video { object-fit: contain; }
.status {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  color: var(--dim);
  font-weight: 600;
  font-size: 15px;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.status.lock, .state.lock { color: var(--lock); }
.status.ok, .state.ok { color: var(--ok); }

.error { background: var(--panel); border: 1px solid var(--bad); border-radius: 12px; padding: 4px 16px; margin-top: 14px; line-height: 1.5; }

.progress { margin-top: 18px; }
.waiting { color: var(--dim); }
.blocks { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.blocks li {
  display: grid;
  grid-template-columns: 7.5em 1fr auto;
  align-items: baseline;
  font-weight: 700;
  font-size: 18px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}
.blocks li.got { color: var(--text); }
.blocks .judge { color: var(--gold); letter-spacing: 0.02em; }
.blocks .btime { color: var(--dim); font-weight: 400; font-size: 14px; }
.blocks .reading { font-weight: 400; }
.preview { font-size: 21px; line-height: 1.5; margin: 22px 0 0; word-break: break-word; overflow-wrap: anywhere; }
.preview .missing { color: #55555e; }
.done { margin-top: 18px; }
.done p { margin: 4px 0; }
.complete { color: var(--ok); font-weight: 700; font-size: 22px; }
.mismatch { color: var(--bad); font-weight: 700; font-size: 22px; }
.pair { font-size: 18px; }
.pair strong { font-variant-numeric: tabular-nums; letter-spacing: 0.06em; }
.took { color: var(--dim); }
.actions { display: flex; gap: 10px; margin-top: 14px; }

.demo-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 16px; }
.demo-head h2 { margin: 0; }
.demo-controls { display: flex; gap: 8px; }
.demo-grid { display: grid; gap: 24px; grid-template-columns: minmax(0, 390px) minmax(0, 432px) minmax(240px, 1fr); align-items: start; }
.panel h3 { font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--dim); }
.panel-sub { margin: 6px 0 12px; font-weight: 600; font-variant-numeric: tabular-nums; display: flex; gap: 16px; }
.panel-sub strong { font-weight: 700; }
#demo-chart { width: 100%; display: block; background: #000; }
.simcam { position: relative; width: 100%; aspect-ratio: 216 / 384; background: #1a1a1a; }
.simcam canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.state { color: var(--dim); }
.panel .progress { margin-top: 0; }

@media (max-width: 900px) {
  .demo-grid { grid-template-columns: 1fr 1fr; gap: 14px; }
  .demo-grid > .panel:last-child { grid-column: 1 / -1; }
  .panel-sub { flex-direction: column; gap: 2px; font-size: 14px; }
  .blocks li { font-size: 16px; }
}

@media (min-width: 901px) {
  #demo-chart { width: min(100%, calc((100vh - 190px) * 390 / 844)); }
  .simcam { width: min(100%, calc((100vh - 190px) * 216 / 384)); }
}
