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

:root {
  --bg1: #2b1055; --bg2: #7597de;
  --ink: #1e1b2e; --panel: #ffffff;
  --accent: #ffb703; --good: #22c55e; --bad: #ef4444;
  --radius: 18px;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  background: linear-gradient(135deg, var(--bg1), #4a2a85 55%, var(--bg2));
  min-height: 100vh;
  color: var(--ink);
  padding: 20px 14px 40px;
}

.hidden { display: none !important; }
.screen { max-width: 1100px; margin: 0 auto; }

/* ---------- setup ---------- */
.hero { text-align: center; color: #fff; margin: 10px 0 24px; }
.hero h1 { font-size: clamp(2.4rem, 6vw, 4rem); letter-spacing: 1px; text-shadow: 0 4px 0 rgba(0,0,0,.25); }
.tagline { opacity: .9; font-size: 1.05rem; margin-top: 6px; }

.setup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 820px) { .setup-grid { grid-template-columns: 1fr; } }

.card {
  background: var(--panel); border-radius: var(--radius);
  padding: 22px; box-shadow: 0 12px 30px rgba(0,0,0,.35);
}
.card h2 { font-size: 1.3rem; margin-bottom: 16px; display: flex; align-items: center; gap: 10px; }
.step {
  background: var(--accent); color: #231900; width: 30px; height: 30px;
  border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-size: 1rem; font-weight: 800; flex: none;
}

.dropzone {
  border: 3px dashed #b9a8e8; border-radius: 14px; padding: 22px 14px;
  text-align: center; background: #f6f2ff; transition: .15s;
}
.dropzone.drag { border-color: var(--accent); background: #fff7e0; }
.dz-big { font-weight: 700; font-size: 1.05rem; }
.dz-small { color: #777; margin: 8px 0; }

.gsheet-row { display: flex; gap: 8px; margin-top: 14px; }
.gsheet-row input {
  flex: 1; padding: 11px 12px; border: 2px solid #ddd; border-radius: 10px; font-size: .95rem; min-width: 0;
}
.row-between { display: flex; justify-content: space-between; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

.status { margin-top: 12px; font-size: .95rem; min-height: 1.2em; }
.status.ok { color: #15803d; font-weight: 600; }
.status.err { color: #b91c1c; font-weight: 600; }

.help { margin-top: 14px; font-size: .9rem; color: #444; }
.help summary { cursor: pointer; font-weight: 600; color: #5b21b6; }
.help p { margin: 8px 0; line-height: 1.45; }
table.fmt { border-collapse: collapse; margin: 8px 0; font-size: .82rem; width: 100%; }
table.fmt th, table.fmt td { border: 1px solid #ddd; padding: 5px 7px; text-align: left; }
table.fmt th { background: #f1ebff; }

.lbl { display: block; font-weight: 700; margin: 16px 0 8px; }
.lbl:first-of-type { margin-top: 0; }

.seg { display: inline-flex; background: #efeaff; border-radius: 12px; padding: 4px; gap: 4px; }
.seg button {
  border: 0; background: transparent; padding: 9px 20px; font-size: 1rem; font-weight: 700;
  border-radius: 9px; cursor: pointer; color: #4c1d95;
}
.seg button.on { background: #7c3aed; color: #fff; box-shadow: 0 3px 8px rgba(124,58,237,.4); }

.team-name-row { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
.team-dot { width: 20px; height: 20px; border-radius: 50%; flex: none; box-shadow: inset 0 -3px 5px rgba(0,0,0,.25); }
.team-name-row input {
  flex: 1; padding: 10px 12px; border: 2px solid #ddd; border-radius: 10px; font-size: 1rem; min-width: 0;
}
.team-name-row input:focus { border-color: #7c3aed; outline: none; }

.board-info { margin-top: 16px; font-weight: 700; color: #5b21b6; }

/* ---------- buttons ---------- */
.btn {
  border: 0; border-radius: 11px; padding: 11px 18px; font-size: .98rem; font-weight: 700;
  background: #e7e2f5; color: #3b1470; cursor: pointer; transition: .12s;
}
.btn:hover { filter: brightness(1.05); transform: translateY(-1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); color: #231900; }
.btn-ghost { background: transparent; color: #5b21b6; box-shadow: inset 0 0 0 2px #c9b8f5; }
.btn-start { width: 100%; margin-top: 12px; background: #7c3aed; color: #fff; font-size: 1.1rem; padding: 14px; }
.btn-good { background: var(--good); color: #fff; }
.btn-bad { background: var(--bad); color: #fff; }

/* ---------- game ---------- */
.scoreboard { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.team-card {
  background: #fff; border-radius: 14px; padding: 10px 16px; min-width: 150px; flex: 1;
  max-width: 250px; text-align: center; border-top: 7px solid #999; position: relative;
  box-shadow: 0 6px 16px rgba(0,0,0,.3); opacity: .75; transition: .2s;
}
.team-card.active { opacity: 1; transform: scale(1.05); box-shadow: 0 0 0 3px var(--accent), 0 10px 22px rgba(0,0,0,.4); }
.team-card .tname { font-weight: 800; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.team-card .tscore { font-size: 1.7rem; font-weight: 900; line-height: 1.15; }
.team-card .tadjust button {
  border: 0; background: #efeaff; border-radius: 7px; width: 26px; height: 22px;
  font-weight: 900; cursor: pointer; color: #5b21b6; margin: 0 2px;
}
.team-card .turn-tag {
  position: absolute; top: -11px; right: 10px; background: var(--accent); color: #231900;
  font-size: .68rem; font-weight: 800; padding: 2px 8px; border-radius: 20px; letter-spacing: .4px;
}

.turn-banner { text-align: center; color: #fff; font-size: 1.25rem; font-weight: 700; margin: 20px 0 14px; text-shadow: 0 2px 6px rgba(0,0,0,.4); }

.board { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
.qcard {
  aspect-ratio: 1 / .82; border: 0; border-radius: 16px; cursor: pointer;
  background: linear-gradient(160deg, #8b5cf6, #6d28d9);
  color: #fff; font-size: 2rem; font-weight: 900;
  box-shadow: 0 7px 0 #4c1d95, 0 12px 20px rgba(0,0,0,.35);
  transition: transform .12s; position: relative;
}
.qcard:hover:not(:disabled) { transform: translateY(-3px) scale(1.03); }
.qcard:disabled { cursor: default; }
.qcard.done-correct { background: linear-gradient(160deg, #4ade80, #16a34a); box-shadow: 0 7px 0 #14532d, 0 12px 20px rgba(0,0,0,.3); font-size: 1.7rem; }
.qcard.done-wrong { background: linear-gradient(160deg, #f87171, #dc2626); box-shadow: 0 7px 0 #7f1d1d, 0 12px 20px rgba(0,0,0,.3); font-size: 1.7rem; }
.qcard .mini { position: absolute; bottom: 7px; right: 10px; font-size: .72rem; font-weight: 700; opacity: .9; }

.game-controls { display: flex; gap: 10px; justify-content: center; margin-top: 26px; }
.game-controls .btn-ghost { color: #fff; box-shadow: inset 0 0 0 2px rgba(255,255,255,.6); }

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(15,5,35,.72);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50;
}
.modal-box {
  background: #fff; border-radius: 20px; padding: 26px; max-width: 640px; width: 100%;
  box-shadow: 0 24px 60px rgba(0,0,0,.5); max-height: 92vh; overflow-y: auto;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.modal-cardnum { background: #efeaff; color: #5b21b6; font-weight: 800; padding: 5px 12px; border-radius: 20px; }
.modal-team { font-weight: 800; }
.modal-q { font-size: 1.45rem; font-weight: 700; line-height: 1.35; margin: 18px 0; }
.modal-opts { display: grid; gap: 10px; }
.opt {
  text-align: left; border: 2px solid #ddd6f5; background: #faf8ff; border-radius: 13px;
  padding: 13px 15px; font-size: 1.05rem; cursor: pointer; font-weight: 600; transition: .12s; width: 100%;
}
.opt:hover:not(:disabled) { border-color: #7c3aed; background: #f1ebff; }
.opt .letter {
  display: inline-flex; width: 27px; height: 27px; border-radius: 50%; background: #7c3aed; color: #fff;
  align-items: center; justify-content: center; font-size: .85rem; margin-right: 10px; font-weight: 800;
}
.opt.correct { background: #dcfce7; border-color: var(--good); }
.opt.correct .letter { background: var(--good); }
.opt.wrong { background: #fee2e2; border-color: var(--bad); }
.opt.wrong .letter { background: var(--bad); }
.opt:disabled { cursor: default; opacity: .92; }
.modal-feedback { min-height: 1.4em; margin-top: 14px; font-weight: 800; font-size: 1.1rem; }
.modal-feedback.good { color: #15803d; }
.modal-feedback.bad { color: #b91c1c; }
.modal-actions { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.modal-actions.center { justify-content: center; }

.over-box { text-align: center; }
.over-box h2 { font-size: 2rem; margin-bottom: 16px; }
.stand-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 11px 16px; border-radius: 12px; background: #f6f2ff; margin-bottom: 9px;
  font-size: 1.1rem; font-weight: 700; border-left: 8px solid #999;
}
.stand-row.winner { background: #fef9c3; font-size: 1.25rem; }
