*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --a:          #2563eb;
  --a-light:    #dbeafe;
  --b:          #dc2626;
  --b-light:    #fee2e2;
  --green:      #16a34a;
  --gray:       #9ca3af;
  --bg:         #f3f4f6;
  --card:       #ffffff;
  --text:       #111827;
  --muted:      #6b7280;
  --border:     #e5e7eb;
  --surface:    #f9fafb;
  --admin-bg:   #ede9fe;
  --admin-text: #5b21b6;
  --r:          12px;
  --sh:         0 2px 8px rgba(0,0,0,.10);
}

@media (prefers-color-scheme: dark) {
  :root:not(.light) {
    --bg:         #0f172a;
    --card:       #1e293b;
    --text:       #f1f5f9;
    --muted:      #94a3b8;
    --border:     #334155;
    --surface:    #0f172a;
    --admin-bg:   #2e1065;
    --admin-text: #c4b5fd;
    --a-light:    #1e3a5f;
    --b-light:    #450a0a;
    --sh:         0 2px 8px rgba(0,0,0,.35);
  }
}

.dark {
  --bg:         #0f172a;
  --card:       #1e293b;
  --text:       #f1f5f9;
  --muted:      #94a3b8;
  --border:     #334155;
  --surface:    #0f172a;
  --admin-bg:   #2e1065;
  --admin-text: #c4b5fd;
  --a-light:    #1e3a5f;
  --b-light:    #450a0a;
  --sh:         0 2px 8px rgba(0,0,0,.35);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
}

.view {
  display: none;
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 14px 32px;
  min-height: 100dvh;
}
.view.active { display: block; }

/* ---- Home ---- */
.app-title {
  text-align: center;
  font-size: 1.4rem;
  font-weight: 800;
  margin: 28px 0 18px;
  letter-spacing: -.5px;
}

.card {
  background: var(--card);
  border-radius: var(--r);
  padding: 20px;
  box-shadow: var(--sh);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}

input[type="text"] {
  width: 100%;
  padding: 13px 14px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
  background: var(--card);
  color: var(--text);
  transition: border-color .15s;
}
input[type="text"]:focus { border-color: var(--a); }

.divider {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: .85rem;
}
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ---- Buttons ---- */
.btn {
  padding: 14px 18px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.btn-full { width: 100%; }

.btn-primary   { background: var(--a);     color: #fff; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-success   { background: var(--green);  color: #fff; }
.btn-correct   { background: var(--green);  color: #fff; flex: 1; font-size: 1.1rem; padding: 20px; border-radius: 10px; }
.btn-wrong     { background: var(--b);      color: #fff; flex: 1; font-size: 1.1rem; padding: 20px; border-radius: 10px; }
.btn-skip      { background: var(--gray);   color: #fff; margin-top: 10px; font-size: .9rem; }
.btn-undo      { background: #f59e0b;       color: #fff; margin-top: 10px; font-size: .9rem; }
.btn-admin         { background: #7c3aed;    color: #fff; }
.btn-admin-active  { background: #4c1d95;   color: #fff; border: 2px solid #c4b5fd; }
.btn-toggle-qcount { background: #0e7490;   color: #fff; margin-top: 8px; font-size: .9rem; }

/* ---- Lobby ---- */
.lobby-header { text-align: center; margin-bottom: 14px; padding-top: 8px; }

.room-code-badge {
  display: inline-block;
  background: var(--card);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: .9rem;
  box-shadow: var(--sh);
  margin-bottom: 8px;
}
.room-code-badge strong {
  font-size: 1.6rem;
  letter-spacing: 5px;
  color: var(--a);
  font-variant-numeric: tabular-nums;
}

.hint { font-size: .82rem; color: var(--muted); }

.teams-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.team-title {
  font-size: .95rem;
  font-weight: 700;
  text-align: center;
  padding: 7px;
  border-radius: 8px 8px 0 0;
  color: #fff;
}
.team-a-bg { background: var(--a); }
.team-b-bg { background: var(--b); }

.btn-edit-team {
  background: none;
  border: none;
  cursor: pointer;
  font-size: .85rem;
  opacity: .75;
  padding: 0 0 0 6px;
  vertical-align: middle;
}
.btn-edit-team:hover { opacity: 1; }

.team-name-input {
  background: rgba(255,255,255,.2);
  border: none;
  border-bottom: 2px solid rgba(255,255,255,.8);
  color: #fff;
  font-size: .95rem;
  font-weight: 700;
  text-align: center;
  width: 90%;
  outline: none;
  border-radius: 0;
}

.slots-container {
  background: var(--card);
  padding: 8px;
  border-radius: 0 0 8px 8px;
  box-shadow: var(--sh);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.slot-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 4px;
  border: 2px solid transparent;
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: all .15s;
  width: 100%;
  -webkit-tap-highlight-color: transparent;
}
.slot-btn:hover:not(:disabled) { background: var(--a-light); border-color: var(--a); }
.slot-btn.mine { background: var(--a-light); border-color: var(--a); }
.slot-btn.taken { background: var(--surface); color: var(--muted); cursor: not-allowed; }
.slot-btn .slot-num  { font-size: .72rem; font-weight: 600; color: var(--muted); }
.slot-btn .slot-name { font-size: .78rem; font-weight: 500; max-width: 72px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.lobby-footer { display: flex; flex-direction: column; gap: 8px; }

.admin-section { margin-bottom: 12px; display: flex; flex-direction: column; gap: 6px; }
.admin-list {
  background: var(--admin-bg);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: .82rem;
  color: var(--admin-text);
  font-weight: 500;
}

/* ---- Game ---- */
.score-board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.team-panel {
  background: var(--card);
  border-radius: var(--r);
  overflow: hidden;
  box-shadow: var(--sh);
}

.team-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  color: #fff;
}
.team-panel-a .team-header { background: var(--a); }
.team-panel-b .team-header { background: var(--b); }

.team-label   { font-weight: 700; font-size: .88rem; }
.team-product { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }

.team-formula {
  padding: 3px 8px;
  font-size: .68rem;
  color: var(--muted);
  text-align: center;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.slots-list { padding: 4px 6px; }

.slot-row {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 4px;
  border-radius: 4px;
  margin-bottom: 2px;
}
.slot-row.locked { opacity: .5; }
.slot-row.reach  { background: rgba(234, 179, 8, 0.13); border-left: 3px solid #eab308; }
.slot-row.mine-a { background: var(--a-light); border-left: 3px solid var(--a); }
.slot-row.mine-b { background: var(--b-light); border-left: 3px solid var(--b); }

.reach-star {
  color: #eab308;
  font-size: .7rem;
  vertical-align: middle;
  margin-left: 2px;
}

.slot-row .r-num  { font-size: .7rem; color: var(--muted); font-weight: 600; min-width: 20px; }
.slot-row .r-pts  { font-size: .95rem; font-weight: 700; min-width: 22px; font-variant-numeric: tabular-nums; }
.slot-row .r-name { font-size: .7rem; color: var(--muted); flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.question-bar {
  background: var(--card);
  border-radius: 8px;
  padding: 8px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: .88rem;
  box-shadow: var(--sh);
  margin-bottom: 10px;
}

.my-controls {
  background: var(--card);
  border-radius: var(--r);
  padding: 14px;
  box-shadow: var(--sh);
}
.my-slot-info {
  text-align: center;
  font-weight: 600;
  font-size: .95rem;
  margin-bottom: 12px;
  min-height: 1.4em;
}
.answer-btns { display: flex; gap: 10px; }

/* ---- Result ---- */
.result-card {
  background: var(--card);
  border-radius: var(--r);
  padding: 28px 20px;
  box-shadow: var(--sh);
  text-align: center;
  margin-top: 48px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.result-icon { font-size: 3.5rem; }
#result-title { font-size: 1.5rem; font-weight: 800; }
.result-scores {
  background: var(--surface);
  border-radius: 8px;
  padding: 14px;
  font-size: .92rem;
  line-height: 2;
  text-align: left;
}

/* ---- テーマ切り替え ---- */
.theme-toggle {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 999;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: var(--sh);
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: background .2s, border-color .2s;
  padding: 0;
}

/* ---- 管理者編集ボタン ---- */
.btn-admin-edit { background: #059669; color: #fff; margin-top: 8px; font-size: .9rem; }

/* ---- 管理者編集モーダル ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: 16px 14px 32px;
}

.modal-content {
  background: var(--card);
  border-radius: var(--r);
  width: 100%;
  max-width: 480px;
  padding: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,.3);
  margin: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1rem; font-weight: 700; }

.btn-close-modal {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 4px;
}
.btn-close-modal:hover { background: var(--surface); }

.edit-section {
  background: var(--surface);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 10px;
}

.edit-section-title {
  font-size: .78rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 8px;
}

.edit-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.edit-label {
  font-size: .8rem;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
  white-space: nowrap;
}

.edit-input {
  width: 64px;
  padding: 7px 8px;
  border: 2px solid var(--border);
  border-radius: 6px;
  font-size: .9rem;
  background: var(--card);
  color: var(--text);
  outline: none;
  -moz-appearance: textfield;
}
.edit-input:focus { border-color: var(--a); }
.edit-input::-webkit-outer-spin-button,
.edit-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.slot-col-label {
  text-align: center;
  font-size: .72rem;
  color: var(--muted);
  font-weight: 600;
}

/* ポイント行：枠番号 + 名前 + pt ラベル + pt 入力 */
.slot-edit-pt-row {
  display: grid;
  grid-template-columns: 32px 1fr 22px 48px;
  align-items: center;
  gap: 4px;
  padding: 6px 0 2px;
}

/* プレーヤー誤答ヘッダ（空欄 + 誤答数 + 🔒） */
.slot-edit-player-hdr {
  display: grid;
  grid-template-columns: 1fr 48px 26px;
  align-items: center;
  gap: 4px;
  padding: 0 0 2px 8px;
  opacity: .65;
}

/* プレーヤー誤答行（名前 + 誤答数入力 + ロックチェック） */
.slot-edit-player-row {
  display: grid;
  grid-template-columns: 1fr 48px 26px;
  align-items: center;
  gap: 4px;
  padding: 3px 0 3px 8px;
}

.slot-sep { border: none; border-top: 1px solid var(--border); margin: 6px 0; }

.slot-edit-num  { font-size: .75rem; font-weight: 700; color: var(--muted); }
.slot-edit-name { font-size: .72rem; color: var(--muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.slot-edit-pname { font-size: .75rem; color: var(--text); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.slot-input {
  width: 100%;
  padding: 5px 4px;
  border: 2px solid var(--border);
  border-radius: 6px;
  font-size: .85rem;
  text-align: center;
  background: var(--card);
  color: var(--text);
  outline: none;
  -moz-appearance: textfield;
}
.slot-input:focus { border-color: var(--a); }
.slot-input::-webkit-outer-spin-button,
.slot-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.slot-lock-chk {
  display: block;
  margin: 0 auto;
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--b);
}

.btn-apply-slot {
  background: var(--a);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 5px 8px;
  font-size: .75rem;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn-apply-slot-full { width: 100%; margin-top: 6px; padding: 7px 0; }
.btn-apply-slot:active { opacity: .75; }

/* ---- 再接続バナー ---- */
.reconnecting-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1100;
  background: #f59e0b;
  color: #fff;
  text-align: center;
  padding: 9px 16px;
  font-size: .9rem;
  font-weight: 700;
  letter-spacing: .5px;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}

.dc-tag {
  display: inline-block;
  background: #f59e0b;
  color: #fff;
  font-size: .6rem;
  padding: 1px 4px;
  border-radius: 3px;
  margin-left: 3px;
  vertical-align: middle;
  font-weight: 600;
}

/* ---- スルーアニメーション ---- */
.skip-flash {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3.5rem;
  font-weight: 800;
  color: #fff;
  background: rgba(107, 114, 128, 0.82);
  pointer-events: none;
  opacity: 0;
  z-index: 1000;
  border-radius: 0;
  letter-spacing: 4px;
}
.skip-flash.show {
  animation: skip-fade 1.4s cubic-bezier(.4,0,.2,1) forwards;
}
@keyframes skip-fade {
  0%   { opacity: 0; transform: scale(.7); }
  15%  { opacity: 1; transform: scale(1.08); }
  40%  { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(.85); }
}
