/* ビンゴ日和 — クラフト調 (罫線背景 / Caveat + Kiwi Maru / 温かみパレット)。
   艦隊デザイントークン (okurimono-cho) を踏襲し、パーティー用の accent を追加。 */

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

:root {
  --ink: #1a1a2e;
  --ink-light: #4a4a6a;
  --paper: #fdf6e3;
  --paper-line: #c8d8e8;
  --accent: #d9583b;
  --accent-dark: #b8432a;
  --card: rgba(255, 255, 255, 0.65);
  --col-b: #c9464d;
  --col-i: #d4960c;
  --col-n: #27ae60;
  --col-g: #2f7d8c;
  --col-o: #8e7cc3;
  --header-h: 48px;
}

html,
body {
  height: 100%;
}

body {
  font-family: "Kiwi Maru", system-ui, -apple-system, "Hiragino Sans", sans-serif;
  background: var(--paper);
  color: var(--ink);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
  /* 罫線背景 */
  background: repeating-linear-gradient(
    to bottom,
    var(--paper) 0px,
    var(--paper) 31px,
    rgba(200, 216, 232, 0.55) 31px,
    rgba(200, 216, 232, 0.55) 32px
  );
}

header.brand {
  height: var(--header-h);
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 16px 0;
}

.logo {
  font-family: "Caveat", cursive;
  font-size: 26px;
  font-weight: 700;
  color: var(--accent);
}

.logo-ja {
  font-size: 12px;
  color: var(--ink-light);
}

main#view {
  flex: 1;
  padding: 12px 16px 32px;
}

.site-footer {
  padding: 16px;
  text-align: center;
  font-size: 12px;
  color: var(--ink-light);
}

.site-footer a {
  color: var(--ink-light);
}

/* ---------- 基本部品 ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  font-size: 15px;
  border-radius: 12px;
  border: 2px solid var(--ink);
  background: #fff;
  color: var(--ink);
  padding: 10px 16px;
  min-height: 44px;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 2px 2px 0 rgba(26, 26, 46, 0.25);
}

.btn:active {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 rgba(26, 26, 46, 0.25);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent-dark);
  color: #fff;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.8);
}

.btn-danger {
  border-color: #a03030;
  color: #a03030;
  background: #fff;
}

.btn-big {
  width: 100%;
  font-size: 17px;
  min-height: 54px;
  margin-top: 12px;
}

.btn-small {
  min-height: 34px;
  font-size: 13px;
  padding: 4px 10px;
  box-shadow: none;
}

.btn[disabled] {
  opacity: 0.5;
  pointer-events: none;
}

.card {
  background: var(--card);
  border: 1.5px solid var(--paper-line);
  border-radius: 14px;
  padding: 14px;
  margin: 12px 0;
}

.muted {
  color: var(--ink-light);
}

.small {
  font-size: 12.5px;
}

.center {
  text-align: center;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 16px;
}

.section-head {
  font-size: 16px;
  font-weight: 500;
}

.count-badge {
  display: inline-block;
  min-width: 26px;
  text-align: center;
  background: var(--ink);
  color: var(--paper);
  border-radius: 999px;
  font-size: 13px;
  padding: 0 8px;
  margin-left: 4px;
}

.view-title {
  font-family: "Caveat", cursive;
  font-size: 30px;
  margin: 8px 0 4px;
}

/* ---------- エントリ ---------- */

.hero-title {
  font-family: "Caveat", cursive;
  font-size: 52px;
  line-height: 1.2;
  color: var(--accent);
  margin-top: 24px;
  text-align: center;
}

.hero-sub {
  text-align: center;
  margin-bottom: 20px;
}

.hero-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.join-form .field {
  display: block;
  margin-bottom: 12px;
}

.field-label {
  display: block;
  font-size: 13px;
  color: var(--ink-light);
  margin-bottom: 4px;
}

.join-form input {
  width: 100%;
  font-family: inherit;
  font-size: 20px;
  padding: 10px 12px;
  border: 2px solid var(--paper-line);
  border-radius: 10px;
  background: #fff;
}

#join-code {
  letter-spacing: 6px;
  font-variant-numeric: tabular-nums;
}

.form-error {
  color: #a03030;
  font-size: 13px;
  margin: 4px 0;
}

.home-note {
  margin-top: 24px;
  font-size: 12.5px;
  color: var(--ink-light);
  text-align: center;
}

/* ---------- 招待 ---------- */

.invite-card {
  text-align: center;
}

.invite-label {
  font-size: 13px;
  color: var(--ink-light);
}

.room-code {
  font-family: "Caveat", cursive;
  font-size: 56px;
  font-weight: 700;
  letter-spacing: 4px;
  line-height: 1.1;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.qr {
  margin: 10px auto;
  display: block;
  background: #fff;
  border-radius: 8px;
  padding: 0;
}

.invite-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.player-list {
  list-style: none;
  margin: 8px 0;
}

.player-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--paper-line);
  border-radius: 10px;
  padding: 6px 10px;
  margin-bottom: 6px;
}

.player-list .p-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-list .p-meta {
  font-size: 12px;
  color: var(--ink-light);
  white-space: nowrap;
}

.player-list .p-meta.reach {
  color: var(--col-i);
  font-weight: 500;
}

.player-list .p-meta.rank {
  color: var(--accent);
  font-weight: 500;
}

.kick-btn {
  border: 1.5px solid var(--paper-line);
  background: #fff;
  color: var(--ink-light);
  border-radius: 8px;
  min-width: 34px;
  min-height: 34px;
  font-size: 14px;
  cursor: pointer;
}

.kick-btn.confirm {
  background: #a03030;
  border-color: #a03030;
  color: #fff;
  font-size: 11px;
  padding: 0 6px;
}

.sticky-action {
  position: sticky;
  bottom: 12px;
}

/* ---------- ホスト: 抽選 ---------- */

.bigscreen-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.bs-code {
  font-size: 13px;
  color: var(--ink-light);
  font-variant-numeric: tabular-nums;
}

.current-number-wrap {
  text-align: center;
  margin: 8px 0;
}

.current-label {
  font-size: 13px;
  color: var(--ink-light);
}

.current-number {
  font-family: "Caveat", cursive;
  font-size: 110px;
  font-weight: 700;
  line-height: 1.05;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.current-number.small {
  font-size: 64px;
}

.current-number.rolling {
  color: var(--ink-light);
}

.draw-count {
  font-size: 13px;
  color: var(--ink-light);
}

.ticker {
  min-height: 24px;
  text-align: center;
  font-size: 14px;
  margin: 6px 0;
}

.ticker .t-bingo {
  color: var(--accent);
  font-weight: 700;
}

.ticker .t-reach {
  color: var(--col-i);
}

/* 履歴グリッド: B/I/N/G/O 行 × 15 */
.history-grid {
  display: grid;
  /* minmax(0,1fr): 1fr の min-content 下限で 15 列が画面外にはみ出すのを防ぐ */
  grid-template-columns: 22px repeat(15, minmax(0, 1fr));
  gap: 3px;
  margin: 14px 0;
}

.history-grid .hg-label {
  font-family: "Caveat", cursive;
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.history-grid .hg-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10.5px;
  border-radius: 5px;
  border: 1px solid var(--paper-line);
  background: rgba(255, 255, 255, 0.5);
  color: var(--ink-light);
  font-variant-numeric: tabular-nums;
}

.history-grid .hg-cell.hit {
  color: #fff;
  border-color: transparent;
  font-weight: 500;
}

.history-grid .hg-cell.latest {
  outline: 2.5px solid var(--ink);
  outline-offset: 1px;
}

.hg-b.hit { background: var(--col-b); }
.hg-i.hit { background: var(--col-i); }
.hg-n.hit { background: var(--col-n); }
.hg-g.hit { background: var(--col-g); }
.hg-o.hit { background: var(--col-o); }
.hg-label.lb-b { color: var(--col-b); }
.hg-label.lb-i { color: var(--col-i); }
.hg-label.lb-n { color: var(--col-n); }
.hg-label.lb-g { color: var(--col-g); }
.hg-label.lb-o { color: var(--col-o); }

.host-panel {
  margin: 16px 0;
}

.host-panel summary {
  cursor: pointer;
  font-size: 14px;
  color: var(--ink-light);
  padding: 6px 0;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  font-size: 14px;
}

.toggle-row input {
  width: 20px;
  height: 20px;
}

/* 大画面モード: 同一 DOM の CSS 拡大 (プロジェクタ向け) */
body.bigscreen #app {
  max-width: none;
}

body.bigscreen .current-number {
  font-size: min(38vh, 46vw);
}

body.bigscreen .history-grid {
  max-width: 900px;
  margin-left: auto;
  margin-right: auto;
}

body.bigscreen .history-grid .hg-cell {
  font-size: clamp(11px, 1.6vw, 20px);
}

body.bigscreen header.brand,
body.bigscreen .site-footer,
body.bigscreen #btn-draw,
body.bigscreen #draw-note,
body.bigscreen .host-panel,
body.bigscreen .current-label,
body.bigscreen .muted {
  display: none;
}

body.bigscreen .bigscreen-head {
  padding: 12px;
}

body.bigscreen .bs-code {
  font-size: 24px;
}

/* ---------- プレイヤー: カード ---------- */

.player-banner {
  min-height: 22px;
  text-align: center;
  font-size: 14px;
  color: var(--ink-light);
}

.bingo-card {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin: 10px auto;
  max-width: 400px;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 16px;
  padding: 10px;
  box-shadow: 3px 3px 0 rgba(26, 26, 46, 0.2);
}

.bc-head {
  font-family: "Caveat", cursive;
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  line-height: 1.2;
}

.bc-cell {
  aspect-ratio: 1;
  border: 1.5px solid var(--paper-line);
  border-radius: 10px;
  background: #fffdf5;
  font-family: inherit;
  font-size: clamp(16px, 5.5vw, 24px);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  cursor: pointer;
  position: relative;
  transition: transform 0.25s;
  transform-style: preserve-3d;
}

.bc-cell.drawable {
  border-color: var(--accent);
  border-width: 2px;
}

.bc-cell.latest {
  animation: pulse 1.2s ease-in-out 2;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(217, 88, 59, 0); }
  50% { box-shadow: 0 0 0 6px rgba(217, 88, 59, 0.35); }
}

/* めくり: 色 + パターンの二重符号化 (色覚対応) */
.bc-cell.flipped {
  background: var(--accent);
  background-image: repeating-linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.18) 0 6px,
    transparent 6px 12px
  );
  color: #fff;
  border-color: var(--accent-dark);
  transform: rotateY(360deg);
}

.bc-cell.free {
  background: var(--col-i);
  background-image: repeating-linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.18) 0 6px,
    transparent 6px 12px
  );
  color: #fff;
  border-color: var(--col-i);
  font-family: "Caveat", cursive;
  font-size: 18px;
  cursor: default;
}

.player-status {
  text-align: center;
  min-height: 24px;
  font-size: 15px;
}

.player-status .reach-word {
  color: var(--col-i);
  font-weight: 700;
}

.player-status .rank-word {
  color: var(--accent);
  font-weight: 700;
}

/* ---------- 結果 ---------- */

.result-list {
  list-style: none;
  margin: 12px 0;
}

.result-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--paper-line);
  border-radius: 10px;
  padding: 8px 12px;
  margin-bottom: 6px;
}

.result-list .r-rank {
  font-family: "Caveat", cursive;
  font-size: 24px;
  font-weight: 700;
  min-width: 44px;
  color: var(--accent);
}

.result-list li.no-bingo .r-rank {
  color: var(--ink-light);
  font-size: 14px;
  font-family: inherit;
}

.result-list .r-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-list .r-at {
  font-size: 12px;
  color: var(--ink-light);
  white-space: nowrap;
}

.store-card,
.pwa-card {
  text-align: center;
}

.store-lead {
  font-weight: 500;
  margin-bottom: 4px;
}

/* ---------- オーバーレイ / 紙吹雪 / トースト ---------- */

.bingo-overlay {
  position: fixed;
  inset: 0;
  background: rgba(253, 246, 227, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  z-index: 60;
  text-align: center;
}

.bingo-overlay[hidden] {
  display: none;
}

.bingo-word {
  font-family: "Caveat", cursive;
  font-size: 88px;
  font-weight: 700;
  color: var(--accent);
  transform: rotate(-4deg);
}

.bingo-rank {
  font-size: 22px;
}

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

.confetti[hidden] {
  display: none;
}

.toasts {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 80;
  width: min(92vw, 420px);
}

.toast {
  background: var(--ink);
  color: var(--paper);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  text-align: center;
  animation: toast-in 0.25s ease-out;
}

.toast.accent {
  background: var(--accent);
  color: #fff;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .bc-cell,
  .bc-cell.flipped {
    transition: none;
    transform: none;
  }
  .bc-cell.latest {
    animation: none;
  }
}
