/*
 * oekaki-live — 共通スタイル（PLAYER / HOST / MOD / 作成 / 規約）
 *
 * 意匠の非交渉:
 *   1. 絵文字 0（check:emoji）。線アイコン（assets/js/icons.js）＋配色＋タイポで作る
 *   2. `.btn:hover` は `@media (hover: hover)` の中にだけ書く（タッチ端末で色が残る・roulette 実測）
 *   3. 外部フォント・外部 CDN を読まない（CSP で塞いである）
 *   4. `backdrop-filter` / `filter` を親に付けない（内側の position: fixed が壊れる）
 *
 * 地はダーク。PLAYER はスマホ、HOST は配信 PC、MOD はスマホ片手。どれも暗い部屋で使う前提。
 */

:root {
  --bg: #12131a;
  --plate: #1c1e29;
  --sunk: #0d0e14;
  --line: #2c2f3d;
  --ink: #f3f1ec;
  --ink-2: #b7b4ad;
  --ink-3: #85827b;
  --accent: #ffb23f;
  --accent-ink: #1a1305;
  --ok: #3ccf7a;
  --ok-ink: #062b16;
  --danger: #ff5c5c;
  --danger-ink: #2b0606;
  --info: #5cc8ff;
  --font-sans: system-ui, -apple-system, 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', 'Noto Sans JP',
    'Yu Gothic', Meiryo, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --radius: 14px;
  --pad: 16px;
}

* {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
a {
  color: var(--info);
}
button {
  font: inherit;
  color: inherit;
}
[hidden] {
  display: none !important;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---- 骨格 ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px var(--pad);
  background: var(--sunk);
  min-height: 48px;
}
.brand {
  color: var(--ink);
  text-decoration: none;
  font-weight: 800;
  letter-spacing: 0.02em;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.brand__mark {
  color: var(--accent);
}
.spacer {
  flex: 1;
}
.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--pad);
}
.wrap--narrow {
  max-width: 480px;
}
.footer {
  padding: 24px var(--pad) 40px;
  color: var(--ink-3);
  font-size: 13px;
  text-align: center;
}
.footer a {
  color: var(--ink-2);
}
.footer__links {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

/* ---- 文字 ---- */
h1 {
  font-size: 24px;
  margin: 0 0 12px;
  font-weight: 800;
  line-height: 1.25;
}
h2 {
  font-size: 18px;
  margin: 24px 0 8px;
  font-weight: 700;
}
.lead {
  color: var(--ink-2);
  margin: 0 0 20px;
}
.muted {
  color: var(--ink-3);
}
.small {
  font-size: 13px;
}
.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.big {
  font-size: 32px;
  font-weight: 800;
  line-height: 1.2;
}
.huge {
  font-size: 44px;
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: -0.01em;
}

/* ---- 面 ---- */
.card {
  background: var(--plate);
  border-radius: var(--radius);
  padding: var(--pad);
  margin-bottom: 12px;
}
.card--hi {
  background: color-mix(in oklab, var(--accent) 12%, var(--plate));
}
.card--danger {
  background: color-mix(in oklab, var(--danger) 12%, var(--plate));
}
.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.center {
  text-align: center;
}

/* ---- 入力 ---- */
label {
  display: block;
  font-size: 14px;
  color: var(--ink-2);
  margin-bottom: 6px;
}
.input,
select.input {
  width: 100%;
  font: inherit;
  font-size: 18px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 2px solid var(--line);
  background: var(--sunk);
  color: var(--ink);
  outline: none;
}
.input:focus {
  border-color: var(--accent);
}
.input--code {
  font-family: var(--font-mono);
  font-size: 28px;
  letter-spacing: 0.2em;
  text-align: center;
}
.hint {
  font-size: 13px;
  color: var(--ink-3);
  margin-top: 6px;
}
.hint--warn {
  color: var(--accent);
}
.field {
  margin-bottom: 16px;
}

/* ---- ボタン ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 18px;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: var(--plate);
  color: var(--ink);
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.btn:active {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}
.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn--ok {
  background: var(--ok);
  border-color: var(--ok);
  color: var(--ok-ink);
}
.btn--danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}
.btn--ghost {
  background: transparent;
}
.btn--big {
  width: 100%;
  min-height: 64px;
  font-size: 20px;
  border-radius: 16px;
}
.btn--block {
  width: 100%;
}
.btn--sm {
  min-height: 36px;
  padding: 4px 12px;
  font-size: 14px;
  border-radius: 10px;
}
.btn svg {
  width: 20px;
  height: 20px;
  flex: none;
}
@media (hover: hover) {
  .btn:hover:not(:disabled) {
    border-color: var(--ink-3);
  }
  .btn--primary:hover:not(:disabled) {
    background: color-mix(in oklab, var(--accent) 88%, white);
    border-color: color-mix(in oklab, var(--accent) 88%, white);
  }
  .btn--ok:hover:not(:disabled) {
    background: color-mix(in oklab, var(--ok) 88%, white);
    border-color: color-mix(in oklab, var(--ok) 88%, white);
  }
}

/* ---- 状態帯（HOST 上部・PLAYER 上部） ---- */
.strip {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  padding: 8px var(--pad);
  background: var(--sunk);
  font-size: 13px;
  color: var(--ink-2);
}
.strip__item {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--plate);
  white-space: nowrap;
}
.strip__item b {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.conn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.conn::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink-3);
}
.conn[data-state='open']::before {
  background: var(--ok);
}
.conn[data-state='closed']::before {
  background: var(--danger);
}

/* ---- phase 表示（PLAYER） ---- */
.phase {
  min-height: calc(100dvh - 48px - 40px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 24px var(--pad);
  gap: 16px;
}
.phase__title {
  font-size: 32px;
  font-weight: 900;
  line-height: 1.2;
  margin: 0;
}
.phase__sub {
  color: var(--ink-2);
  font-size: 16px;
  margin: 0;
}
.phase__topic {
  font-size: 28px;
  font-weight: 800;
  padding: 12px 20px;
  border-radius: 12px;
  background: var(--plate);
  overflow-wrap: anywhere;
}
.back-to-stream {
  color: var(--accent);
  font-weight: 800;
  font-size: 18px;
}
.countdown {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 56px;
  font-weight: 800;
  line-height: 1;
}
.countdown--last {
  color: var(--danger);
  font-size: 72px;
}

/* ---- キャンバス（PLAYER・画面いっぱい） ---- */
.draw {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}
.draw__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--sunk);
  min-height: 44px;
}
.draw__topic {
  flex: 1;
  font-weight: 800;
  font-size: 17px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.draw__time {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 22px;
  font-weight: 800;
  min-width: 3ch;
  text-align: right;
}
.draw__time--last {
  color: var(--danger);
  font-size: 28px;
}
.draw__stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  min-height: 0;
}
.draw__canvas {
  background: #ffffff;
  touch-action: none;
  border-radius: 6px;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1 / 1;
  display: block;
}
.draw__tools {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: var(--sunk);
}
.palette {
  display: flex;
  gap: 8px;
  justify-content: center;
}
.swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid transparent;
  padding: 0;
  cursor: pointer;
}
.swatch[aria-pressed='true'] {
  border-color: var(--accent);
}
.widths {
  display: flex;
  gap: 8px;
  align-items: center;
}
.width-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 2px solid var(--line);
  background: var(--plate);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}
.width-btn[aria-pressed='true'] {
  border-color: var(--accent);
}
.width-btn i {
  display: block;
  background: var(--ink);
  border-radius: 50%;
}
.draw__actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.draw__actions .btn--primary {
  flex: 1;
}

/* ---- 承認キュー（MOD / HOST） ---- */
.queue {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.entry-no {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.05em;
}
.artwork {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #ffffff;
  border-radius: 10px;
  overflow: hidden;
}
.artwork img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.mod-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.mod-actions .btn--danger {
  margin-top: 12px;
}

/* ---- ギャラリー（HOST の優勝選択） ---- */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}
.gallery__item {
  padding: 0;
  border: 3px solid var(--line);
  border-radius: 10px;
  background: #ffffff;
  overflow: hidden;
  cursor: pointer;
  position: relative;
  aspect-ratio: 1 / 1;
}
.gallery__item img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.gallery__item span {
  position: absolute;
  left: 6px;
  top: 6px;
  font-family: var(--font-mono);
  font-weight: 800;
  background: var(--sunk);
  color: var(--ink);
  padding: 2px 8px;
  border-radius: 6px;
}
.gallery__item[aria-pressed='true'] {
  border-color: var(--accent);
}

/* ---- 鍵の1回表示 ---- */
.keybox {
  background: var(--sunk);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 14px;
  overflow-wrap: anywhere;
  user-select: all;
}

/* ---- トースト ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 700;
  max-width: calc(100% - 32px);
  z-index: 50;
}
.toast--error {
  background: var(--danger);
  color: #fff;
}

/* ---- 規約 ---- */
.doc {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px var(--pad) 40px;
}
.doc table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0 16px;
  font-size: 14px;
}
.doc th,
.doc td {
  text-align: left;
  vertical-align: top;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
.doc th {
  width: 34%;
  color: var(--ink-2);
  font-weight: 600;
}
.doc p {
  margin: 0 0 12px;
}
.doc ul {
  padding-left: 20px;
}
