:root {
  --bg: #070b14;
  --panel: #11192c;
  --panel-2: #17223b;
  --border: rgba(0, 240, 255, 0.28);
  --cyan: #00f0ff;
  --amber: #ffb800;
  --green: #10e898;
  --red: #ff3b5c;
  --text: #f1f6ff;
  --muted: #8ea2c8;
  --glow-c: 0 0 16px rgba(0, 240, 255, 0.55);
  --glow-a: 0 0 16px rgba(255, 184, 0, 0.55);

  /* マッチ棒の色（高コントラスト） */
  --wood-light: #ffe7b3;
  --wood-mid: #e6b25e;
  --wood-dark: #a66c22;
  --head-light: #ff6b6b;
  --head-dark: #c91834;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", sans-serif;
  background-color: var(--bg);
  background-image:
    radial-gradient(circle at 50% 0%, rgba(0, 240, 255, 0.14), transparent 55%),
    radial-gradient(circle at 85% 95%, rgba(255, 184, 0, 0.1), transparent 50%),
    linear-gradient(rgba(0, 240, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 240, 255, 0.04) 1px, transparent 1px);
  background-size: 100% 100%, 100% 100%, 36px 36px, 36px 36px;
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  overflow-x: hidden;
}

.hidden { display: none !important; }

#confetti {
  position: fixed; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 90;
}

/* トップバー */
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 18px;
  background: rgba(7, 11, 20, 0.94);
  border-bottom: 2px solid var(--cyan);
  box-shadow: 0 4px 18px rgba(0, 240, 255, 0.18);
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.brand-mark { font-size: 20px; }
.brand-name { font-size: 17px; font-weight: 900; letter-spacing: 0.05em; color: var(--cyan); text-shadow: var(--glow-c); }
.brand-sub { font-size: 12px; color: var(--amber); font-weight: 800; letter-spacing: 0.08em; }
.topbar-actions { display: flex; gap: 8px; }

/* ボタン共通（スマホ最低44px確保） */
.btn, .btn-chip, .diff-btn {
  font-family: inherit; font-weight: 800; cursor: pointer;
  border-radius: 10px; transition: transform 0.08s, background 0.15s, box-shadow 0.15s;
  min-height: 46px; padding: 10px 18px; font-size: 15px;
  border: 2px solid transparent; color: var(--text);
}
.btn:active:not(:disabled), .btn-chip:active, .diff-btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }

.btn-chip {
  min-height: 38px; padding: 6px 12px; font-size: 13px; border-radius: 8px;
  background: rgba(0, 240, 255, 0.1); border-color: var(--border); color: var(--cyan);
}
.btn-chip:hover { background: var(--cyan); color: #050814; }

.btn-primary {
  background: linear-gradient(180deg, #00f0ff 0%, #00a8cc 100%);
  color: #050a14; border-color: #7df9ff; box-shadow: var(--glow-c);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }

.btn-secondary {
  background: var(--panel-2); color: var(--text); border-color: #3a4f7a;
}
.btn-secondary:hover:not(:disabled) { background: #223256; border-color: var(--cyan); }

.btn-amber {
  background: linear-gradient(180deg, #ffb800 0%, #d98200 100%);
  color: #140d00; border-color: #ffe082; box-shadow: var(--glow-a);
}
.btn-lg { min-height: 54px; font-size: 17px; padding: 12px 26px; }
.btn-sm { min-height: 42px; font-size: 14px; padding: 8px 14px; }

.screen {
  flex: 1;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
}

/* ==================== タイトル画面 ==================== */
.screen-title { justify-content: center; align-items: center; }
.title-card {
  width: 100%; max-width: 720px;
  background: var(--panel); border: 2px solid var(--border);
  border-radius: 18px; padding: 20px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.65);
  display: flex; flex-direction: column; gap: 16px;
}
.hero-media {
  position: relative; border-radius: 14px; overflow: hidden;
  border: 2px solid rgba(0, 240, 255, 0.35);
  aspect-ratio: 16 / 9; background: #0a1020;
}
.hero-video { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0.72; }
.hero-overlay {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(7,11,20,0.25) 0%, rgba(7,11,20,0.88) 100%);
  display: flex; flex-direction: column; justify-content: flex-end; align-items: center;
  padding: 20px; text-align: center;
}
.hero-kicker { margin: 0 0 4px; font-size: 12px; font-weight: 900; letter-spacing: 0.14em; color: var(--amber); }
.hero-title { margin: 0; font-size: clamp(28px, 5vw, 44px); font-weight: 900; color: #fff; text-shadow: var(--glow-c); }
.hero-sub { margin: 4px 0 0; font-size: 15px; font-weight: 800; color: var(--cyan); letter-spacing: 0.12em; }

.host-strip {
  display: flex; align-items: center; gap: 12px;
  background: rgba(7, 11, 20, 0.65); border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px; padding: 10px 14px;
}
.host-avatar { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; border: 2px solid var(--amber); flex-shrink: 0; background: #1e293b; }
.host-avatar-sm { width: 46px; height: 46px; }
.host-avatar.excited { animation: hop 0.45s ease-in-out 2; }
@keyframes hop { 0%,100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-10px) scale(1.08); } }
.host-bubble { margin: 0; font-size: 14px; line-height: 1.5; color: var(--text); font-weight: 700; }

.progress-summary { text-align: center; font-size: 15px; color: var(--muted); }
.progress-summary b { color: var(--amber); font-size: 19px; }

.diff-group { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.diff-btn { background: var(--panel-2); border-color: #32446a; color: var(--muted); font-size: 14px; }
.diff-btn.sel {
  background: rgba(0, 240, 255, 0.16); border-color: var(--cyan); color: #fff;
  box-shadow: var(--glow-c);
}
.title-cta { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ==================== 一覧画面 ==================== */
.list-header { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.list-title { margin: 0; font-size: 20px; color: var(--cyan); }
.puzzle-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(136px, 1fr)); gap: 10px;
}
.pcard {
  position: relative; background: var(--panel); border: 2px solid #2b3c60;
  border-radius: 12px; padding: 12px 10px; text-align: center; cursor: pointer;
  transition: transform 0.1s, border-color 0.15s;
}
.pcard:hover { transform: translateY(-3px); border-color: var(--cyan); }
.pcard.cleared { border-color: var(--green); background: rgba(16, 232, 152, 0.08); }
.pno { font-size: 12px; color: var(--muted); font-weight: 800; }
.pexpr { font-size: 18px; font-weight: 900; margin: 6px 0; letter-spacing: 0.06em; color: #fff; }
.pmoves { font-size: 12px; color: var(--amber); font-weight: 700; }
.pstar { position: absolute; top: 8px; right: 10px; font-size: 16px; color: var(--green); opacity: 0; }
.pcard.cleared .pstar { opacity: 1; }

/* ==================== プレイ画面（画面全面レイアウト） ==================== */
.screen-play {
  max-width: 1440px;
  gap: 12px;
  justify-content: space-between;
}
.play-hud {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
}
.play-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pill {
  padding: 6px 14px; border-radius: 99px; font-size: 14px; font-weight: 900;
  background: var(--panel-2); border: 1px solid #3a4f7a; color: var(--text);
}
.pill-cyan { border-color: var(--cyan); color: var(--cyan); background: rgba(0, 240, 255, 0.1); }
.pill-amber { border-color: var(--amber); color: #140d00; background: var(--amber); font-size: 15px; }

.host-strip-play { padding: 8px 14px; }

/* 中央の主役盤面：残り画面高さをフルに使う */
.stage-wrap {
  flex: 1;
  min-height: 280px;
  background: radial-gradient(ellipse at center, #142240 0%, #0a1020 100%);
  border: 2px solid var(--border);
  border-radius: 18px;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.6), 0 10px 30px rgba(0, 0, 0, 0.5);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 18px;
}

/* マッチ棒数式：--cols（文字数）とビューポート幅・高さの両方に連動して最大拡大 */
.equation {
  --cols: 6;
  --u: clamp(40px, min(calc((92vw - 48px) / (var(--cols) * 1.18)), 22dvh), 138px);
  --t: calc(var(--u) * 0.2);       /* 棒の太さ（極太・高視認） */
  --gap: calc(var(--u) * 0.16);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--gap);
  padding: 12px 6px;
  transition: transform 0.25s;
}
.equation.solved {
  filter: drop-shadow(0 0 18px rgba(16, 232, 152, 0.7));
}

.glyph { position: relative; flex-shrink: 0; }
.glyph.digit { width: var(--u); height: calc(var(--u) * 1.88); }
.glyph.operator { width: calc(var(--u) * 0.92); height: calc(var(--u) * 1.88); }
.glyph.equals { width: calc(var(--u) * 0.86); height: calc(var(--u) * 1.88); }

/* セグメント（タップ判定を広めに確保） */
.seg {
  position: absolute;
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.seg.h { width: calc(var(--u) * 0.86); height: calc(var(--t) * 1.9); left: calc(var(--u) * 0.07); }
.seg.v { width: calc(var(--t) * 1.9); height: calc(var(--u) * 0.86); }

/* 数字 7セグ配置 */
.glyph.digit [data-seg="a"] { top: calc(var(--t) * -0.45); }
.glyph.digit [data-seg="g"] { top: calc(var(--u) * 0.94 - var(--t) * 0.95); }
.glyph.digit [data-seg="d"] { bottom: calc(var(--t) * -0.45); }
.glyph.digit [data-seg="f"] { top: calc(var(--u) * 0.05); left: calc(var(--t) * -0.45); }
.glyph.digit [data-seg="b"] { top: calc(var(--u) * 0.05); right: calc(var(--t) * -0.45); }
.glyph.digit [data-seg="e"] { bottom: calc(var(--u) * 0.05); left: calc(var(--t) * -0.45); }
.glyph.digit [data-seg="c"] { bottom: calc(var(--u) * 0.05); right: calc(var(--t) * -0.45); }

/* 演算子 (+ / -) */
.glyph.operator [data-seg="h"] { width: calc(var(--u) * 0.82); left: calc(var(--u) * 0.05); top: calc(var(--u) * 0.94 - var(--t) * 0.95); }
.glyph.operator [data-seg="v"] { height: calc(var(--u) * 0.82); top: calc(var(--u) * 0.53); left: calc(var(--u) * 0.46 - var(--t) * 0.95); }

/* イコール (=) */
.glyph.equals [data-seg="u"] { width: calc(var(--u) * 0.78); left: calc(var(--u) * 0.04); top: calc(var(--u) * 0.68 - var(--t) * 0.95); }
.glyph.equals [data-seg="l"] { width: calc(var(--u) * 0.78); left: calc(var(--u) * 0.04); top: calc(var(--u) * 1.20 - var(--t) * 0.95); }

/* マッチ棒本体 */
.stick {
  display: block;
  border-radius: 999px;
  position: relative;
  transition: transform 0.14s, box-shadow 0.14s, background 0.14s, opacity 0.14s;
}
.seg.h .stick { width: 88%; height: var(--t); }
.seg.v .stick { width: var(--t); height: 88%; }

/* 未配置スロット（空きガイド：視認性とタップ誘導） */
.seg.off .stick {
  background: rgba(142, 162, 200, 0.13);
  border: 2px dashed rgba(0, 240, 255, 0.28);
}
.seg.off:hover .stick {
  background: rgba(0, 240, 255, 0.25);
  border-color: var(--cyan);
}

/* 配置済みマッチ棒（木軸＋赤い発火部＋高コントラスト） */
.seg.on .stick {
  background: linear-gradient(180deg, var(--wood-light) 0%, var(--wood-mid) 58%, var(--wood-dark) 100%);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.7), 0 0 8px rgba(255, 210, 120, 0.35);
}
.seg.v.on .stick {
  background: linear-gradient(90deg, var(--wood-light) 0%, var(--wood-mid) 58%, var(--wood-dark) 100%);
}
/* マッチの赤い頭 */
.seg.on .stick::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--head-light), var(--head-dark));
  box-shadow: 0 0 8px rgba(255, 59, 92, 0.65);
}
.seg.h.on .stick::after {
  width: calc(var(--t) * 1.45); height: calc(var(--t) * 1.32);
  right: calc(var(--t) * -0.2); top: 50%; transform: translateY(-50%);
}
.seg.v.on .stick::after {
  width: calc(var(--t) * 1.32); height: calc(var(--t) * 1.45);
  top: calc(var(--t) * -0.2); left: 50%; transform: translateX(-50%);
}

/* 選択中 */
.seg.selected .stick {
  transform: scale(1.16);
  box-shadow: 0 0 22px var(--cyan), 0 0 0 3px var(--cyan);
}
/* 移動固定済み */
.seg.locked .stick {
  box-shadow: 0 0 16px rgba(255, 184, 0, 0.8), 0 0 0 2px var(--amber);
}

.answer-line {
  font-size: clamp(20px, 3vw, 28px);
  font-weight: 900;
  color: var(--green);
  text-shadow: 0 0 14px rgba(16, 232, 152, 0.55);
  letter-spacing: 0.08em;
}
.play-msg {
  margin: 0; font-size: 16px; font-weight: 800; text-align: center;
  color: #dbeafe; min-height: 24px;
}
.play-msg.good { color: var(--green); font-size: 20px; }
.play-msg.bad { color: var(--red); }

.clear-actions { display: flex; justify-content: center; }
.play-controls {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
}

/* ==================== 全問クリア画面 ==================== */
.screen-allclear { justify-content: center; align-items: center; }
.allclear-card {
  width: 100%; max-width: 600px; text-align: center;
  background: var(--panel); border: 2px solid var(--amber);
  border-radius: 18px; padding: 24px; box-shadow: var(--glow-a);
}
.clear-video { width: 100%; border-radius: 12px; margin-bottom: 14px; }
.allclear-title { margin: 0 0 8px; font-size: 32px; color: var(--amber); }
.allclear-msg { margin: 0 0 18px; font-size: 16px; color: var(--text); }

/* スマホ最適化 */
@media (max-width: 600px) {
  .topbar { padding: 8px 12px; }
  .brand-name { font-size: 15px; }
  .screen { padding: 10px; }
  .title-cta { grid-template-columns: 1fr; }
  .stage-wrap { padding: 14px 6px; min-height: 220px; }
  .play-controls { gap: 8px; }
  .btn { padding: 10px 10px; font-size: 14px; }
}