/* オーカカップ 自動集計アプリ
 *
 * 想定する使われ方:
 *   大会当日、コーチがコート横で片手にスマホを持って入力する。
 *   だから最小幅は 320px、タップ領域は 44px 以上を基本にしている。
 *   PCの本部席からも見るので、広い画面では2列に広がる。
 */

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --border: #dde3ec;
  --text: #182029;
  --dim: #5d6976;
  --accent: #1160c4;
  --win: #17803d;
  --win-bg: #d7f5e3;
  --lose: #b3341f;
  --lose-bg: #fde4df;
  --warn: #8a6100;
  --warn-bg: #fdf0cf;
  --radius: 14px;
  --tap: 44px;
  --shadow: 0 1px 2px rgba(20, 30, 45, .07), 0 2px 8px rgba(20, 30, 45, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161c24;
    --surface-2: #1e252f;
    --border: #2a323d;
    --text: #e6ebf2;
    --dim: #97a2b0;
    --accent: #5aa9ff;
    --win: #4ede86;
    --win-bg: #10331f;
    --lose: #ff8a7a;
    --lose-bg: #3a1a15;
    --warn: #e8bf55;
    --warn-bg: #362a0e;
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Kaku Gothic ProN",
               "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

/* ------------------------------------------------------------ ヘッダー */

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 12px calc(6px);
  padding-top: calc(8px + env(safe-area-inset-top));
}
.topbar-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.event { min-width: 0; }
.event-name { font-weight: 800; font-size: 16px; display: block; line-height: 1.25; }
.event-theme { font-size: 11.5px; color: var(--dim); display: block;
               overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex: none; }

.role { font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 700; white-space: nowrap; }
.role-coach { background: var(--win-bg); color: var(--win); }
.role-view { background: var(--surface-2); color: var(--dim); }
.logout { font-size: 11.5px; color: var(--dim); text-decoration: none;
          border: 1px solid var(--border); border-radius: 8px; padding: 3px 8px; }

.leader { font-size: 13px; margin-top: 4px; color: var(--dim); }
.leader b { color: var(--text); font-size: 15px; }

.sync { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--dim); margin-top: 3px; }
#sync-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--win); flex: none; }
#sync-dot.busy { background: var(--warn); }
#sync-dot.err { background: var(--lose); }

.chip {
  display: inline-block; font-weight: 700; font-size: inherit;
  border-left: 4px solid var(--c, var(--dim)); padding-left: 7px;
}

/* ------------------------------------------------------------ レイアウト */

main {
  max-width: 1200px; margin: 0 auto; padding: 12px;
  display: grid; gap: 12px; grid-template-columns: 1fr;
}
@media (min-width: 900px) { main { grid-template-columns: 1fr 1fr; align-items: start; } }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; min-width: 0;
}
@media (min-width: 900px) { .card.wide, main > .card:first-child { grid-column: 1 / -1; } }

.card > h2 {
  margin: 0 0 10px; font-size: 15px; font-weight: 800;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.card > h2::before {
  content: ""; width: 4px; height: 16px; border-radius: 2px;
  background: var(--accent); flex: none;
}

.rule { font-size: 12.5px; color: var(--dim); margin: 0 0 12px; }
.rule b { color: var(--text); }
.dim { color: var(--dim); }
.center { text-align: center; }

.note, .warn, .flash {
  font-size: 12.5px; padding: 8px 12px; border-radius: 10px; margin-bottom: 10px;
}
.note { background: var(--surface-2); color: var(--dim); }
.warn { background: var(--warn-bg); color: var(--warn); font-weight: 600; }
.flash-ok { background: var(--win-bg); color: var(--win); }
.flash-ng { background: var(--lose-bg); color: var(--lose); }

/* ------------------------------------------------------------ 総合順位 */

.ranks { display: grid; gap: 10px; }

.rank-card {
  border: 1px solid var(--border); border-left: 5px solid var(--c);
  border-radius: 12px; padding: 10px 12px; background: var(--surface-2);
}
.rank-head { display: flex; align-items: center; gap: 10px; }
.rank-pos { font-size: 22px; min-width: 42px; font-weight: 800; }
.rank-name { flex: 1; min-width: 0; }
.rank-team { font-weight: 800; font-size: 16px; }
.rank-coach { font-size: 11.5px; color: var(--dim); }
.rank-total { text-align: right; }
.rank-total b { font-size: 26px; font-weight: 800; }
.rank-total span { font-size: 11px; color: var(--dim); margin-left: 2px; }

.rank-bar { height: 5px; border-radius: 99px; background: var(--border); margin: 8px 0; overflow: hidden; }
.rank-bar i { display: block; height: 100%; background: var(--c); transition: width .5s ease; }

.breakdown { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.bd { text-align: center; background: var(--surface); border-radius: 8px; padding: 4px 2px; }
.bd-label { display: block; font-size: 9.5px; color: var(--dim); }
.bd-value { display: block; font-size: 15px; font-weight: 700; }

.prog { display: grid; gap: 4px; }
.prog-row { display: flex; justify-content: space-between; font-size: 13px;
            padding: 5px 0; border-bottom: 1px dashed var(--border); }
.prog-row:last-child { border-bottom: 0; }

.audit { margin: 0; padding-left: 18px; font-size: 12.5px; }
.audit li { margin: 3px 0; }

/* ------------------------------------------------------------ 対戦入力 */

.team-block {
  border: 1px solid var(--border); border-left: 5px solid var(--c);
  border-radius: 12px; margin-bottom: 10px; background: var(--surface-2);
  overflow: hidden;
}
.team-block > summary {
  cursor: pointer; padding: 10px 12px; display: flex; align-items: center;
  gap: 10px; list-style: none; min-height: var(--tap);
}
.team-block > summary::-webkit-details-marker { display: none; }
.tb-name { font-weight: 800; font-size: 15px; flex: 1; }
.tb-sub { font-size: 11.5px; color: var(--dim); }
.tb-score { font-weight: 800; font-size: 17px; min-width: 52px; text-align: right; }

.vs-list { padding: 0 10px 10px; }
.vs-row {
  display: flex; align-items: center; gap: 8px; justify-content: space-between;
  padding: 7px 0; border-top: 1px solid var(--border);
}
.vs-opp { font-size: 13px; min-width: 0; flex: 1; }
.vs-btns { display: flex; gap: 6px; flex: none; }

.pick {
  min-width: 58px; min-height: var(--tap); border-radius: 10px;
  border: 1.5px solid var(--border); background: var(--surface);
  color: var(--dim); font-size: 13px; font-weight: 700; cursor: pointer;
}
.pick:disabled { opacity: .45; cursor: not-allowed; }
.pick.win.on { background: var(--win-bg); border-color: var(--win); color: var(--win); }
.pick.lose.on { background: var(--lose-bg); border-color: var(--lose); color: var(--lose); }
.pick.clear { min-width: 44px; }
.pick.clear.on { background: var(--surface-2); border-color: var(--dim); color: var(--text); }

.stepper { display: flex; align-items: center; gap: 4px; flex: none; }
.step {
  width: var(--tap); height: var(--tap); border-radius: 10px;
  border: 1.5px solid var(--border); background: var(--surface);
  font-size: 19px; font-weight: 700; color: var(--text); cursor: pointer;
}
.step:disabled { opacity: .45; }
.num {
  width: 62px; height: var(--tap); text-align: center; font-size: 17px;
  font-weight: 700; border: 1.5px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text);
}
.num:disabled { opacity: .55; }
.num::-webkit-outer-spin-button, .num::-webkit-inner-spin-button {
  -webkit-appearance: none; margin: 0;
}
.num[type=number] { -moz-appearance: textfield; }

/* ------------------------------------------------------------ クイズ */

.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 12px; }
@media (min-width: 700px) { .totals { grid-template-columns: repeat(6, 1fr); } }
.tot { background: var(--surface-2); border-radius: 10px; padding: 6px; text-align: center; }
.tot span { display: block; font-size: 10.5px; color: var(--dim);
            overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tot b { font-size: 18px; }

.genre {
  border: 1px solid var(--border); border-radius: 12px;
  margin-bottom: 8px; background: var(--surface-2); overflow: hidden;
}
.genre > summary {
  cursor: pointer; padding: 11px 12px; min-height: var(--tap);
  display: flex; align-items: center; justify-content: space-between;
  list-style: none; font-weight: 700;
}
.genre > summary::-webkit-details-marker { display: none; }
.genre > summary::before { content: "▸"; color: var(--dim); margin-right: 8px; }
.genre[open] > summary::before { content: "▾"; }
.genre-name { flex: 1; }

.quiz-q { padding: 10px 12px; border-top: 1px solid var(--border); background: var(--surface); }
.quiz-head { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; }
.quiz-no { font-weight: 800; font-size: 12.5px; }
.quiz-pt {
  font-size: 11px; background: var(--accent); color: #fff;
  padding: 1px 8px; border-radius: 999px; font-weight: 700;
}
.quiz-text { font-size: 13.5px; white-space: pre-wrap; margin-bottom: 6px; }
.quiz-ans > summary { font-size: 12px; color: var(--dim); cursor: pointer; padding: 4px 0; }
.quiz-ans .ans { font-weight: 700; color: var(--win); font-size: 13.5px; padding-bottom: 6px; }

.qteams { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin-top: 8px; }
@media (min-width: 700px) { .qteams { grid-template-columns: repeat(3, 1fr); } }

.qteam { display: flex; gap: 4px; }
.qmain {
  flex: 1; min-height: var(--tap); border-radius: 10px; cursor: pointer;
  border: 1.5px solid var(--border); background: var(--surface);
  border-left: 4px solid var(--c);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 8px; color: var(--text);
}
.qteam.got .qmain { background: var(--win-bg); border-color: var(--win); border-left-color: var(--c); }
.qteam-name { font-size: 11.5px; font-weight: 700; overflow: hidden;
              text-overflow: ellipsis; white-space: nowrap; }
.qteam-pt { font-size: 16px; font-weight: 800; }
.qbonus {
  width: 38px; min-height: var(--tap); border-radius: 10px; cursor: pointer;
  border: 1.5px solid var(--border); background: var(--surface);
  font-size: 12px; font-weight: 700; color: var(--dim);
}
.qbonus.bonus-on { background: var(--warn-bg); border-color: var(--warn); color: var(--warn); }
.qmain:disabled, .qbonus:disabled { opacity: .45; cursor: not-allowed; }

/* ------------------------------------------------------------ だるま・運動会 */

.daruma-card, .sp-row {
  border: 1px solid var(--border); border-left: 5px solid var(--c);
  border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; background: var(--surface-2);
}
.dc-head, .sp-team {
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 800; font-size: 15px; margin-bottom: 2px;
}
.dc-score, .sp-pt { font-size: 15px; }
.dc-label { font-size: 11.5px; color: var(--dim); margin-bottom: 6px; }

.numpicks { display: flex; gap: 5px; flex-wrap: wrap; }
.numpick {
  flex: 1; min-width: var(--tap); min-height: var(--tap); border-radius: 10px;
  border: 1.5px solid var(--border); background: var(--surface);
  font-size: 15px; font-weight: 700; color: var(--text); cursor: pointer;
}
.numpick.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.numpick.clear { color: var(--dim); }
.numpick:disabled { opacity: .45; cursor: not-allowed; }

.topics { font-size: 13px; margin: 0; padding-left: 22px; }
.topics li { margin: 3px 0; }

/* ------------------------------------------------------------ 表・進行表 */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
th { font-size: 11.5px; color: var(--dim); background: var(--surface-2); white-space: nowrap; }
.role-cell { font-size: 11px; color: var(--accent); font-weight: 700; white-space: nowrap; }
.slot {
  display: inline-block; background: var(--accent); color: #fff;
  width: 22px; height: 22px; line-height: 22px; text-align: center;
  border-radius: 6px; font-size: 12px; font-weight: 800;
}

.schedule { display: grid; gap: 2px; }
.sc-item { display: flex; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.sc-item.major { background: var(--surface-2); border-radius: 8px; padding: 8px; }
.sc-time { font-weight: 800; font-size: 13px; min-width: 46px; color: var(--accent); }
.sc-name { font-size: 13.5px; font-weight: 600; }
.sc-meta { font-size: 11.5px; color: var(--dim); }

.rules-text p { font-size: 13px; margin: 6px 0; white-space: pre-wrap; }

/* ------------------------------------------------------------ 下部ナビ */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(8, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px; padding: 6px 0 5px; text-decoration: none; color: var(--dim);
  font-size: 9.5px; min-height: 54px;
}
.nav-item.on { color: var(--accent); background: var(--surface-2); font-weight: 700; }
.nav-ico { font-size: 17px; line-height: 1; }
.nav-label { white-space: nowrap; }

/* ------------------------------------------------------------ ログイン */

.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px; padding-bottom: 20px;
}
.login-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 24px; width: 100%; max-width: 380px;
  box-shadow: var(--shadow);
}
.login-title { font-size: 20px; font-weight: 800; text-align: center; }
.login-sub { font-size: 12.5px; color: var(--dim); text-align: center; margin-bottom: 18px; }
.login-box label { display: block; font-size: 12.5px; color: var(--dim); margin-bottom: 12px; }
.login-box input {
  width: 100%; height: 46px; margin-top: 4px; padding: 0 12px;
  font-size: 16px; border: 1.5px solid var(--border); border-radius: 10px;
  background: var(--bg); color: var(--text);
}
.login-btn {
  width: 100%; height: 48px; border: 0; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: 16px; font-weight: 700;
  cursor: pointer; margin-top: 4px;
}
.login-note { font-size: 11.5px; color: var(--dim); margin-top: 14px; line-height: 1.5; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
