:root {
  --bg: #000;
  --text: #fff;
  --dim: #8a8a8a;
  --faint: #2e2e2e;
  --line: #fff;
  --g1: #ff2a4f;   /* グリッチの赤 */
  --g2: #00f0ff;   /* グリッチのシアン */
  --font: "Zen Kaku Gothic New", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  --display: "Dela Gothic One", "Zen Kaku Gothic New", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text); font-family: var(--font); font-weight: 900;
  -webkit-text-size-adjust: 100%; overflow: hidden;
}
/* 走査線 */
body::after {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 100;
  background: repeating-linear-gradient(0deg, rgba(255,255,255,.035) 0 1px, transparent 1px 3px);
  mix-blend-mode: screen;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; font-weight: 900; }
.hidden { display: none !important; }

/* 1画面に収める基本レイアウト */
.screen {
  height: 100vh; height: 100dvh; display: flex; flex-direction: column; gap: 8px;
  max-width: 920px; margin: 0 auto; padding: max(12px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom));
}
/* プレイ画面: 1画面に固定。問題文の枠だけが残りの高さを使い、下の枠(--slot)は場面によらず同じ高さ */
body.playpage { overscroll-behavior: none; }
.playpage .screen { position: fixed; inset: 0; }
.slot { --slot: min(300px, 46vh); flex: none; height: var(--slot); position: relative; display: flex; flex-direction: column; justify-content: flex-end; }
.slot > * { min-height: 0; }
.bar { display: flex; align-items: center; gap: 12px; flex: none; min-height: 36px; }
.bar .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dim); font-size: 13px; }
.bar .stack { display: flex; flex-direction: column; line-height: 1.25; }
.bar .stack > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .q { font-family: var(--display); font-size: 18px; letter-spacing: .05em; }
.fill { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 12px; }
.scroll { overflow: auto; min-height: 0; }

/* ---- グリッチ ---- */
.glitch { position: relative; display: inline-block; font-family: var(--display); letter-spacing: .04em; text-decoration: none; }
.glitch::before, .glitch::after {
  content: attr(data-text); position: absolute; inset: 0; pointer-events: none;
}
.glitch::before { color: var(--g1); transform: translateX(-2px); mix-blend-mode: screen; animation: glitch-a 3.2s infinite steps(1); }
.glitch::after { color: var(--g2); transform: translateX(2px); mix-blend-mode: screen; animation: glitch-b 3.2s infinite steps(1); }
@keyframes glitch-a {
  0%, 86%, 100% { clip-path: inset(100% 0 0 0); }
  88% { clip-path: inset(10% 0 60% 0); transform: translateX(-4px); }
  90% { clip-path: inset(55% 0 20% 0); transform: translateX(3px); }
  92% { clip-path: inset(30% 0 45% 0); transform: translateX(-6px); }
  94% { clip-path: inset(80% 0 5% 0); transform: translateX(2px); }
}
@keyframes glitch-b {
  0%, 86%, 100% { clip-path: inset(100% 0 0 0); }
  87% { clip-path: inset(65% 0 10% 0); transform: translateX(4px); }
  89% { clip-path: inset(20% 0 55% 0); transform: translateX(-3px); }
  91% { clip-path: inset(40% 0 35% 0); transform: translateX(5px); }
  95% { clip-path: inset(5% 0 85% 0); transform: translateX(-2px); }
}
.logo { font-size: 22px; color: var(--text); flex: none; }
.logo.big { font-size: clamp(48px, 15vw, 96px); line-height: 1; }

/* 一瞬画面がずれる演出(早押し・判定時) */
.shock { animation: shock .32s steps(2) 1; }
@keyframes shock {
  0% { transform: translate(0); filter: none; }
  20% { transform: translate(-6px, 2px) skewX(-4deg); filter: drop-shadow(4px 0 var(--g1)) drop-shadow(-4px 0 var(--g2)); }
  45% { transform: translate(5px, -2px) skewX(3deg); filter: drop-shadow(-5px 0 var(--g1)) drop-shadow(5px 0 var(--g2)); }
  70% { transform: translate(-2px, 0); filter: drop-shadow(2px 0 var(--g1)); }
  100% { transform: translate(0); filter: none; }
}
@media (prefers-reduced-motion: reduce) {
  .glitch::before, .glitch::after { animation: none; clip-path: inset(100% 0 0 0); }
  .shock { animation: none; }
}

/* ---- 部品 ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; flex: none;
  background: var(--bg); color: var(--text); border: 2px solid var(--line); border-radius: 0;
  padding: 12px 18px; cursor: pointer; text-decoration: none; white-space: nowrap; font-size: 16px;
  transition: box-shadow .08s, transform .08s;
}
.btn:hover:not(:disabled), .btn:focus-visible { box-shadow: -3px 0 0 var(--g1), 3px 0 0 var(--g2); outline: none; }
.btn:active:not(:disabled) { transform: translate(1px, 1px); }
.btn.primary { background: var(--text); color: var(--bg); }
.btn.wide { width: 100%; padding: 16px; font-size: 19px; letter-spacing: .08em; }
.btn.small { padding: 7px 12px; font-size: 14px; }
.btn.icon { padding: 0; width: 44px; height: 44px; }
.btn.icon svg { width: 20px; height: 20px; }
.btn:disabled { opacity: .35; cursor: default; }
input[type=text], input[type=password], input[type=number], select, textarea {
  background: var(--bg); border: 2px solid var(--line); border-radius: 0; padding: 12px 14px; width: 100%; min-width: 0;
  font-size: 16px;
}
input::placeholder, textarea::placeholder { color: #5c5c5c; }
input:focus, select:focus, textarea:focus { outline: none; box-shadow: -3px 0 0 var(--g1), 3px 0 0 var(--g2); }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, #fff 50%), linear-gradient(-45deg, transparent 50%, #fff 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 12px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.end { justify-content: flex-end; }
.dim { color: var(--dim); }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 16px; z-index: 120; max-width: calc(100% - 32px);
}

/* ---- トップ ---- */
.home .hero { flex: none; display: flex; justify-content: center; padding: 4vh 0 2vh; }
.sets { list-style: none; margin: 0; padding: 0; border-top: 2px solid var(--line); }
.sets li { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--faint); }
.sets li .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 17px; }
.sets li .n { color: var(--dim); font-size: 13px; flex: none; }
.label { font-family: var(--display); font-size: 13px; letter-spacing: .12em; color: var(--dim); }

/* ---- プレイ ---- */
.chips { list-style: none; margin: 0; padding: 0; display: flex; gap: 6px; flex-wrap: nowrap; flex: none; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips li { display: flex; align-items: center; gap: 8px; border: 2px solid var(--line); padding: 4px 10px; font-size: 14px; max-width: 60%; flex: none; }
.chips li .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chips li .sc { font-family: var(--display); font-size: 16px; }
.chips li.me { background: var(--text); color: var(--bg); }
.chips li.host .nm::after { content: " ★"; font-size: 10px; vertical-align: 2px; }
.chips li.off { opacity: .35; }
.chips li.locked { border-style: dashed; opacity: .5; }
.chips li.locked .nm { text-decoration: line-through; }

.game { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.qbox { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; border-left: 4px solid var(--line); padding: 4px 0 4px 16px; }
.qtext { font-size: clamp(22px, 5vw, 36px); line-height: 1.6; word-break: break-all; letter-spacing: .02em; }
.qtext span { color: transparent; }
.qtext span.done { color: var(--text); }
.qtext span.done.fresh { color: var(--text); text-shadow: -2px 0 var(--g1), 2px 0 var(--g2); }
.qtext span.now {
  background: linear-gradient(90deg, var(--text) calc(var(--p) * 100%), transparent calc(var(--p) * 100%));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.qtext.revealed span { color: var(--faint); }
.qtext.revealed span.done { color: var(--text); }
.qtext .cut { display: inline-block; width: 5px; height: 1.05em; background: var(--g1); vertical-align: -0.12em; margin: 0 4px; box-shadow: 3px 0 0 var(--g2); }
.status { position: absolute; top: 0; left: 0; right: 0; height: 22px; line-height: 22px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; text-align: center; font-size: 15px; color: var(--dim); }
.status:empty { display: none; }
.status b { color: var(--text); font-size: 18px; }

.buzzer-area { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding-top: 22px; }
.giveup { font-size: 14px; padding: 8px 16px; border-color: var(--dim); color: var(--dim); }
.buzzer {
  width: min(170px, calc(var(--slot) - 100px), 46vw); aspect-ratio: 1; border-radius: 50%; cursor: pointer;
  background: var(--text); color: var(--bg); border: 0; font-size: clamp(28px, 6vw, 38px);
  letter-spacing: .08em; box-shadow: 0 0 0 6px var(--bg), 0 0 0 8px var(--text);
  touch-action: manipulation; -webkit-tap-highlight-color: transparent; transition: transform .05s;
}
.buzzer:not(:disabled) { animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px var(--bg), 0 0 0 8px var(--text), -6px 0 18px -4px var(--g1), 6px 0 18px -4px var(--g2); } }
.buzzer:active:not(:disabled), .buzzer.down { transform: scale(.94); }
.buzzer:disabled { background: var(--faint); color: #555; box-shadow: 0 0 0 6px var(--bg), 0 0 0 8px var(--faint); cursor: default; }

.answer-box { height: 100%; display: flex; flex-direction: column; gap: 6px; }
.answer-box input { font-size: 22px; text-align: center; padding: 10px; }
.answer-line .btn { align-self: stretch; }
/* スマホはフリックキーボードを使うので、入力欄は表示専用にして送信ボタンはキーボード側に置く */
.touch .answer-box input { pointer-events: none; caret-color: transparent; }
.touch .answer-line .btn { display: none; }
body:not(.touch) .flick { display: none; }
body:not(.touch) .answer-box { justify-content: center; }

/* ---- フリックキーボード ---- */
.flick { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(3, 1fr) 0.9fr; grid-template-rows: repeat(4, 1fr); gap: 5px;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.flick .k { display: flex; align-items: center; justify-content: center; border: 2px solid var(--line); background: var(--bg);
  font-size: 22px; position: relative; }
.flick .k.fn { font-size: 15px; color: var(--dim); border-color: var(--dim); }
.flick .k.send { background: var(--text); color: var(--bg); border-color: var(--text); font-size: 16px; grid-row: span 2; }
.flick .k.del { grid-row: span 2; }
.flick .k.on { background: var(--text); color: var(--bg); }
.flick .k.blank { visibility: hidden; }
/* フリック中に出るガイド(上下左右の文字) */
.flick-guide { position: fixed; z-index: 60; pointer-events: none; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); }
.flick-guide span { display: flex; align-items: center; justify-content: center; font-size: 22px; background: var(--bg); color: var(--text); border: 2px solid var(--text); }
.flick-guide span:empty { visibility: hidden; }
.flick-guide span.sel { background: var(--text); color: var(--bg); box-shadow: -3px 0 0 var(--g1), 3px 0 0 var(--g2); }
.timebar { height: 6px; background: var(--faint); overflow: hidden; }
.timebar i { display: block; height: 100%; width: 100%; background: var(--text); transform-origin: left; }

.judge {
  position: absolute; left: 0; right: 0; top: 10%; z-index: 5;
  display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; text-align: center;
}
.judge .mark { width: min(140px, 22dvh); height: min(140px, 22dvh); filter: drop-shadow(-4px 0 var(--g1)) drop-shadow(4px 0 var(--g2)); }
.judge .who { font-size: 20px; background: var(--bg); padding: 2px 10px; }
.judge .pts { font-family: var(--display); font-size: 16px; background: var(--text); color: var(--bg); padding: 2px 10px; }

.reveal { display: flex; flex-direction: column; gap: 6px; border-top: 2px solid var(--line); padding: 6px 0 0; height: 100%; }
.reveal .ans { font-size: clamp(28px, 7vw, 44px); line-height: 1.2; }
.reveal .who { color: var(--dim); font-size: 14px; }
.reveal .exp { flex: 1 1 auto; font-weight: 500; font-size: 14px; line-height: 1.75; color: #d0d0d0; overflow: auto; min-height: 0; }

.lobby { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 14px; justify-content: center; }
.wait { text-align: center; font-family: var(--display); letter-spacing: .2em; color: var(--dim); }

.result { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 14px; }
.big-score { font-family: var(--display); font-size: clamp(64px, 18vw, 120px); line-height: 1; }
.rank-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.rank-table td { padding: 9px 4px; border-bottom: 1px solid var(--faint); }
.rank-table td.r { font-family: var(--display); width: 3em; }
.rank-table td.num { text-align: right; font-family: var(--display); }
.rank-table td.sub { text-align: right; color: var(--dim); font-size: 13px; width: 4em; }
.rank-table tr.me td { background: var(--text); color: var(--bg); }
.rank-table tr.me td.sub { color: #555; }

.credit { font-size: 10px; color: #555; font-weight: 500; }

.overlay { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.overlay .box { width: min(400px, 100%); display: flex; flex-direction: column; gap: 14px; align-items: stretch; }
.overlay .box .glitch { align-self: center; }

/* ---- 管理画面(縦スクロールあり) ---- */
.admin .list { list-style: none; margin: 0; padding: 0; border-top: 2px solid var(--line); }
.admin .list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--faint); }
.admin code { font-family: inherit; background: var(--faint); padding: 0 4px; }
body.admin { overflow: auto; }
.admin .wrap { max-width: 920px; margin: 0 auto; padding: 16px 16px 48px; display: flex; flex-direction: column; gap: 16px; }
.admin label.field { display: block; font-size: 12px; color: var(--dim); margin: 0 0 6px; font-weight: 700; }
.qedit { border: 2px solid var(--line); padding: 14px; margin-bottom: 12px; display: flex; flex-direction: column; gap: 10px; }
.qedit textarea { min-height: 72px; resize: vertical; }
.qedit .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 640px) { .qedit .cols { grid-template-columns: 1fr; } }
.preview .qtext { font-size: 20px; }
.preview .kana { font-size: 12px; color: var(--dim); margin-top: 4px; word-break: break-all; font-weight: 500; }
.admin #main { display: flex; flex-direction: column; gap: 28px; }
.admin #editor > .row > div:first-child { flex: 1; min-width: 200px; }
.btn.danger { color: var(--g1); border-color: var(--g1); }
