:root {
  --ink: #0b0c10;
  --paper: #efe6d2;
  --dim: #a99f8a;
  --shu: #d9432b;
  --gold: #e8c46a;
  --listen: #7fb8ff;
  --peek: #e8c46a;
  --line: rgba(239, 230, 210, .22);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #000; color: var(--paper);
  font-family: "Zen Old Mincho", "Yu Mincho", serif; -webkit-font-smoothing: antialiased; }
button, input, select { font-family: inherit; }
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#hudfx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 3; }

.hidden { display: none !important; }

/* ---------- 画面 ---------- */
.screen { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; z-index: 10;
  padding: 16px; overflow-y: auto; }
.screen.show { display: flex; }
.screen.dim { background: rgba(0, 0, 0, .55); backdrop-filter: blur(2px); }
#title { background: radial-gradient(ellipse at 50% 28%, rgba(40, 52, 80, .35), rgba(0, 0, 0, .8) 60%), rgba(0, 0, 0, .35); }

.title-box { width: min(560px, 100%); text-align: center; margin: auto; }
.kicker { margin: 0; color: var(--dim); letter-spacing: .3em; font-size: 14px; }
.logo { margin: 6px 0 0; font-family: "Yuji Syuku", serif; font-weight: 400; font-size: clamp(64px, 17vw, 128px);
  line-height: 1.05; letter-spacing: .06em; color: var(--paper);
  text-shadow: 0 0 24px rgba(160, 200, 255, .25), 4px 4px 0 rgba(217, 67, 43, .55); }
.logo-en { margin: 0 0 8px; letter-spacing: .6em; color: var(--dim); font-size: 13px; }
.earphone { display: inline-block; margin: 6px 0 14px; padding: 4px 14px; border: 1px solid var(--line);
  border-radius: 999px; font-size: 14px; color: var(--paper); background: rgba(0, 0, 0, .35); }
.name-row { display: flex; justify-content: center; align-items: center; gap: 8px; margin: 4px 0 14px; font-size: 15px; }
.name-row input, .join-row input { background: rgba(0, 0, 0, .5); border: 1px solid var(--line); color: var(--paper);
  padding: 8px 12px; border-radius: 6px; font-size: 16px; width: 200px; }
.menu { display: flex; flex-direction: column; gap: 10px; align-items: stretch; width: min(380px, 100%); margin: 0 auto; }
.menu-title { margin: 0 0 2px; font-family: "Yuji Syuku", serif; font-size: 22px; }
.row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 6px; }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; width: auto; text-transform: uppercase; letter-spacing: .2em; }

.btn { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  cursor: pointer; text-decoration: none; color: var(--paper); background: rgba(12, 12, 16, .72);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 18px; font-size: 17px; font-weight: 700;
  transition: border-color .15s, background .15s, transform .08s; }
.btn:hover { border-color: var(--shu); background: rgba(60, 18, 12, .6); }
.btn:active { transform: translateY(1px); }
.btn small { font-size: 12px; color: var(--dim); font-weight: 400; }
.btn.big { font-size: 22px; padding: 14px 18px; font-family: "Yuji Syuku", serif; font-weight: 400; }
.btn.small { font-size: 14px; padding: 7px 12px; }
.btn.tiny { font-size: 13px; padding: 5px 10px; border-radius: 6px; }
.btn.ghost { background: transparent; }
.btn.on { border-color: var(--gold); color: var(--gold); }
.btn:disabled { opacity: .4; cursor: default; }
.settings { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; margin-top: 18px; font-size: 13px; color: var(--dim); }
.settings input { vertical-align: middle; width: 110px; accent-color: var(--shu); }
.net-msg { min-height: 1.4em; margin: 4px 0; color: var(--gold); font-size: 14px; }

.panel { width: min(460px, 100%); background: rgba(8, 8, 12, .85); border: 1px solid var(--line); border-radius: 12px;
  padding: 22px 20px; text-align: center; margin: auto; box-shadow: 0 10px 40px rgba(0, 0, 0, .6); }
.panel h2 { margin: 0 0 10px; font-family: "Yuji Syuku", serif; font-weight: 400; font-size: 34px; }
.code-line { font-size: 15px; }
.code-line b { font-size: 26px; letter-spacing: .2em; color: var(--gold); margin: 0 6px; }
.lobby-list { list-style: none; padding: 0; margin: 10px 0; text-align: left; }
.lobby-list li { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.lobby-list .dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.lobby-list .tag { margin-left: auto; font-size: 12px; color: var(--dim); }
.lobby-list li.empty { color: var(--dim); }

/* ---------- HUD ---------- */
.hud { position: fixed; inset: 0; pointer-events: none; display: none; z-index: 5; }
.hud.show { display: block; }
.hud-top { position: absolute; top: 12px; left: 0; right: 0; display: flex; justify-content: center; gap: 18px; align-items: center; }
.scores { display: flex; gap: 10px; }
.score { display: flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: rgba(0, 0, 0, .55);
  border: 1px solid var(--line); font-size: 14px; }
.score .dot { width: 10px; height: 10px; border-radius: 50%; }
.score b { font-size: 16px; color: var(--gold); }
.score.dead { opacity: .45; text-decoration: line-through; }
.score.me { border-color: var(--paper); }
.timer { font-size: 22px; font-weight: 900; min-width: 48px; text-align: center; color: var(--dim); }
.center-msg { position: absolute; top: 34%; left: 0; right: 0; text-align: center; font-family: "Yuji Syuku", serif;
  font-size: clamp(48px, 12vw, 110px); color: var(--paper); text-shadow: 0 0 30px rgba(0, 0, 0, .9); opacity: 0;
  transition: opacity .25s; }
.center-msg.show { opacity: 1; }
.center-msg.red { color: var(--shu); }
.sub-msg { position: absolute; top: calc(34% + clamp(64px, 14vw, 130px)); left: 0; right: 0; text-align: center;
  font-size: 18px; color: var(--dim); }
.hud-bottom { position: absolute; bottom: 38px; left: 0; right: 0; display: flex; justify-content: center; gap: 22px; align-items: flex-end; flex-wrap: wrap; padding: 0 16px; }
.gauge { width: 190px; font-size: 13px; }
.gauge .key, .stones .key { display: inline-block; font-size: 11px; border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; margin-right: 6px; color: var(--dim); }
.gauge .bar { height: 7px; margin-top: 4px; background: rgba(255, 255, 255, .1); border-radius: 4px; overflow: hidden; }
.gauge .bar i { display: block; height: 100%; width: 100%; background: var(--listen); transition: width .1s linear; }
#g-peek .bar i { background: var(--peek); }
.gauge.active .lbl { color: #fff; text-shadow: 0 0 8px var(--listen); }
#g-peek.active .lbl { text-shadow: 0 0 8px var(--peek); }
.gauge.low .bar i { opacity: .45; }
.stones { font-size: 13px; }
.stones b { font-size: 18px; color: var(--gold); }
.state-tags { position: absolute; bottom: 92px; left: 0; right: 0; text-align: center; font-size: 14px; color: var(--dim); letter-spacing: .1em; }
.ctrl-hint { position: absolute; bottom: 8px; left: 0; right: 0; text-align: center; margin: 0; font-size: 12px; color: rgba(239, 230, 210, .38); padding: 0 16px; }

/* ---------- 薄目 ---------- */
#eyelids { position: fixed; inset: 0; pointer-events: none; z-index: 2; opacity: 0; transition: opacity .18s; }
#eyelids.open { opacity: 1; }
#eyelids::after { content: ""; position: absolute; inset: 0;
  background: radial-gradient(ellipse 52% 30% at 50% 50%, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, .35) 45%, #000 100%); }
#eyelids .lid { position: absolute; left: -10%; right: -10%; height: 50%; background: #000; transition: transform .22s ease-out; }
#eyelids .lid.top { top: 0; border-radius: 0 0 50% 50% / 0 0 38% 38%; transform: translateY(-40%); filter: blur(10px); }
#eyelids .lid.bottom { bottom: 0; border-radius: 50% 50% 0 0 / 38% 38% 0 0; transform: translateY(40%); filter: blur(10px); }
#eyelids.open .lid.top { transform: translateY(-58%); }
#eyelids.open .lid.bottom { transform: translateY(58%); }
#view.peek { filter: grayscale(.75) brightness(.55) contrast(1.05) blur(1.2px); }

/* ---------- 結果 ---------- */
.result-rounds { list-style: none; padding: 0; margin: 8px 0 14px; display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.result-rounds li { padding: 4px 10px; border-radius: 6px; border: 1px solid var(--line); font-size: 13px; }

/* ---------- リプレイ ---------- */
.replay { position: fixed; inset: 0; pointer-events: none; display: none; z-index: 6; }
.replay.show { display: block; }
.replay > * { pointer-events: auto; }
.rp-top { position: absolute; top: 10px; left: 12px; right: 12px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.rp-rounds, .rp-cams, .rp-subjects { display: flex; gap: 6px; flex-wrap: wrap; }
.rp-subjects .btn { border-left-width: 5px; }
.rp-caption { position: absolute; top: 58px; left: 0; right: 0; text-align: center; pointer-events: none; font-size: 15px;
  color: var(--paper); text-shadow: 0 1px 6px #000; }
.rp-bottom { position: absolute; left: 0; right: 0; bottom: 0; padding: 10px 14px 10px; background: linear-gradient(transparent, rgba(0, 0, 0, .85) 30%); }
.rp-timeline { position: relative; }
.rp-marks { position: relative; height: 30px; margin: 0 8px; }
.rp-marks .seg { position: absolute; height: 5px; border-radius: 2px; opacity: .9; }
.rp-marks .seg.listen { background: var(--listen); }
.rp-marks .seg.peek { background: var(--peek); }
.rp-marks .tick { position: absolute; width: 2px; height: 9px; background: #fff; }
.rp-marks .tick.stone { background: #9a9a9a; }
.rp-marks .tick.hit { background: var(--shu); width: 4px; height: 30px; top: 0 !important; }
.rp-marks .tick.clash { background: var(--gold); }
#rp-seek { width: 100%; accent-color: var(--shu); margin: 2px 0; }
.rp-controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.rp-controls select { background: #111; color: var(--paper); border: 1px solid var(--line); border-radius: 6px; padding: 4px; }
.rp-time { font-variant-numeric: tabular-nums; min-width: 90px; }
.chk { display: inline-flex; gap: 4px; align-items: center; color: var(--dim); }
.grow { flex: 1; }
.rp-legend { margin: 6px 0 0; font-size: 11px; color: var(--dim); display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.lg { display: inline-block; width: 14px; height: 5px; border-radius: 2px; margin-right: 2px; }
.lg.listen { background: var(--listen); } .lg.peek { background: var(--peek); } .lg.swing { background: #fff; width: 3px; height: 9px; }
.lg.stone { background: #9a9a9a; width: 3px; height: 9px; } .lg.hit { background: var(--shu); width: 4px; height: 12px; }

.loading { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: #000; z-index: 50;
  font-family: "Yuji Syuku", serif; font-size: 22px; color: var(--dim); }
.loading.done { display: none; }

@media (max-width: 640px) {
  .gauge { width: 140px; }
  .ctrl-hint { display: none; }
  .rp-legend { display: none; }
}
