.page {
  flex: 1;
  max-width: var(--w-base);
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---------- Tool card ---------- */
.tool {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 20px;
}
.tab-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 9px 16px;
  border-radius: 9px;
  font-family: "Noto Sans JP", sans-serif;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease, box-shadow 140ms ease;
}
.tab-btn.active {
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ---------- 抽選機 ---------- */
.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  background: var(--surface);
}
.stage-head {
  align-self: stretch;
  display: flex;
  gap: 8px;
  justify-content: space-between;
  align-items: center;
}
.stage-count {
  white-space: nowrap;
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.stage-tools {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 8px 14px;
}
.check-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--sub);
  cursor: pointer;
}
.check-row input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.stage-full {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--sub);
  font-family: "Noto Sans JP", sans-serif;
  font-size: 12.5px;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
}
.stage-full:hover { background: var(--bg); }

.ball {
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: var(--accent-soft);
  border: 3px solid var(--accent);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: background 200ms ease, border-color 200ms ease;
}
.ball-letter {
  font-family: "JetBrains Mono", monospace;
  font-weight: 700;
  font-size: 26px;
  line-height: 1;
  color: var(--accent-deep);
  min-height: 26px;
}
.ball-num {
  font-family: "JetBrains Mono", monospace;
  font-weight: 700;
  font-size: 72px;
  line-height: 1.05;
  color: var(--accent-deep);
}
.ball.is-empty {
  background: var(--bg);
  border-color: var(--border);
}
/* 列の文字がないときは場所も取らず、「？」をボールの真ん中に置く */
.ball.is-empty .ball-letter { display: none; }
.ball.is-empty .ball-num {
  color: var(--muted);
  font-family: "Noto Sans JP", sans-serif;
  font-size: 56px;
}
.ball.is-spinning {
  background: var(--bg);
  border-color: var(--border);
}
.ball.is-spinning .ball-letter,
.ball.is-spinning .ball-num { color: var(--muted); }
.ball.is-pop { animation: ballPop 420ms cubic-bezier(.2,.8,.3,1.35); }
@keyframes ballPop {
  0%   { transform: scale(0.85); }
  65%  { transform: scale(1.08); }
  100% { transform: scale(1); }
}

.recent {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  min-height: 26px;
}
.recent-num {
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  font-weight: 600;
  color: var(--sub);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
}

/* 出た番号の一覧。パソコンでは B〜O を横の行に、スマートフォンでは縦の列に並べる */
.board {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.board-line {
  display: grid;
  grid-template-columns: 28px repeat(15, minmax(0, 1fr));
  gap: 4px;
}
.board-letter,
.board-num {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  border-radius: 6px;
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  font-weight: 600;
}
.board-letter {
  color: var(--accent-deep);
  font-weight: 700;
}
.board-num {
  color: var(--muted);
  background: var(--bg);
}
.board-num.is-hit {
  color: var(--accent-deep);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.board-num.is-last {
  color: #fff;
  background: var(--accent);
  box-shadow: none;
}

.draw-foot {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
/* 保存中の表示は左に寄せ、やり直しボタンは右に置いたままにする */
/* 保存中の表示とやり直しボタンは中央にそろえる。横に入りきらないときは2行にする */
.draw-foot { justify-content: center; align-items: center; flex-wrap: wrap; gap: 8px 12px; }
.draw-foot .saved-badge { margin: 0; }
.draw-foot .reset-btn { white-space: nowrap; }

.reset-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--danger);
  font-family: "Noto Sans JP", sans-serif;
  font-weight: 500;
  font-size: 12.5px;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease;
}
.reset-btn:hover {
  background: var(--danger-soft);
  border-color: var(--danger-soft);
}

/* 列の文字を出さないときは、ボールの文字を場所ごと消して番号を真ん中に置く */
.stage.no-letters .ball-letter { display: none; }

/* 大きく表示（全画面）。会場の後ろからも読めるよう、画面の高さに合わせて大きくする */
.stage:fullscreen {
  justify-content: center;
  gap: 3vh;
  padding: 4vh 4vw;
}
.stage:fullscreen .ball { width: 42vh; height: 42vh; border-width: 6px; }
.stage:fullscreen .ball-letter { font-size: 7vh; min-height: 7vh; }
.stage:fullscreen .ball-num { font-size: 20vh; }
.stage:fullscreen .ball.is-empty .ball-num { font-size: 15vh; }
.stage:fullscreen .recent-num { font-size: 2.4vh; padding: 0.4vh 1.4vh; }
.stage:fullscreen .board { max-width: 1400px; width: 100%; align-self: center; }
.stage:fullscreen .board-letter,
.stage:fullscreen .board-num { height: 4.6vh; font-size: 2.4vh; }
.stage:fullscreen .board-line { grid-template-columns: 4vh repeat(15, minmax(0, 1fr)); }

/* ---------- Draw button ---------- */
.draw-btn {
  appearance: none;
  width: 100%;
  border: none;
  background: var(--accent);
  color: white;
  font-family: "Noto Sans JP", sans-serif;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.04em;
  padding: 14px 20px;
  border-radius: var(--radius);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 140ms ease, transform 140ms ease;
}
.draw-btn:hover:not(:disabled) {
  background: var(--accent-deep);
  transform: translateY(-1px);
}
.draw-btn:active:not(:disabled) { transform: translateY(0); }
.draw-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}
.stage .draw-btn { max-width: 420px; }
.stage:fullscreen .draw-btn { font-size: 2.6vh; padding: 1.8vh 3vh; }

/* ---------- カードの設定 ---------- */
.block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 10px;
}
.block-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 12px;
}
.card-settings {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px 20px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field-grow { flex: 1 1 200px; }
.field-label {
  font-size: 12px;
  color: var(--muted);
}

.stepper {
  display: inline-flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.stepper button {
  appearance: none;
  border: none;
  background: transparent;
  width: 36px;
  height: 36px;
  font-family: "JetBrains Mono", monospace;
  font-size: 18px;
  color: var(--sub);
  cursor: pointer;
  transition: background 140ms ease;
  display: grid;
  place-items: center;
  line-height: 1;
}
.stepper button:hover { background: var(--bg); }
.stepper input {
  width: 48px;
  border: none;
  outline: none;
  text-align: center;
  background: transparent;
  font-family: "JetBrains Mono", monospace;
  font-weight: 600;
  font-size: 15px;
  color: var(--ink);
  -moz-appearance: textfield;
}
.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.text-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-family: "Noto Sans JP", sans-serif;
  font-size: 14px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}
.text-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.text-input::placeholder { color: var(--muted); }

.error-msg {
  margin-top: 10px;
  padding: 10px 14px;
  color: var(--danger);
  font-size: 13px;
  font-weight: 500;
  background: var(--danger-soft);
  border-radius: var(--radius);
  display: none;
}
.error-msg.visible { display: block; }

.cards-actions {
  display: none;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 20px 0 14px;
}
.cards-actions.visible { display: flex; }
.cards-note {
  font-size: 13px;
  color: var(--muted);
}
.print-btn {
  appearance: none;
  border: 1px solid var(--accent);
  background: var(--surface);
  color: var(--accent-deep);
  font-family: "Noto Sans JP", sans-serif;
  font-weight: 700;
  font-size: 13.5px;
  padding: 9px 18px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 140ms ease;
}
.print-btn:hover { background: var(--accent-soft); }

/* ---------- ビンゴカード ---------- */
.cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card-page {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.card {
  border: 2px solid var(--ink);
  border-radius: 10px;
  padding: 10px 10px 8px;
  background: #fff;
  color: var(--ink);
}
.card-title {
  text-align: center;
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 6px;
  overflow-wrap: anywhere;
}
.card-grid {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}
.card-grid th,
.card-grid td {
  border: 1.5px solid var(--ink);
  text-align: center;
  font-family: "JetBrains Mono", monospace;
  font-weight: 700;
}
.card-grid th {
  background: var(--ink);
  color: #fff;
  font-size: 15px;
  padding: 4px 0;
}
.card-grid td {
  font-size: 18px;
  height: 40px;
}
.card-grid td.is-free {
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--sub);
  background: var(--bg);
}
.card-no {
  text-align: right;
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  color: var(--sub);
  margin-top: 4px;
}

@media (max-width: 900px) {
  .tool { padding: 20px 16px; }
  .ball { width: 150px; height: 150px; }
  .ball-num { font-size: 60px; }
  /* スマートフォンでは15個を横に並べると小さすぎるため、B〜O を縦の列にする */
  .board {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 6px;
  }
  .board-line {
    display: flex;
    flex-direction: column;
    gap: 3px;
  }
  .board-letter,
  .board-num { height: 26px; font-size: 12.5px; }
}
@media (max-width: 560px) {
  .card-page { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- 印刷 ---------- */
/* 「カードを印刷」のときだけ、カード以外をすべて隠して A4 に4枚ずつ並べる */
@media print {
  @page { size: A4 portrait; margin: 10mm; }

  body.printing-cards { background: #fff !important; }
  body.printing-cards .sidebar,
  body.printing-cards .mob-header,
  body.printing-cards .mob-switch-menu,
  body.printing-cards .mob-overlay,
  body.printing-cards .page-header,
  body.printing-cards .ad-slot,
  body.printing-cards .accordion,
  body.printing-cards .related-columns,
  body.printing-cards .toast,
  body.printing-cards .no-print,
  body.printing-cards #tab-draw {
    display: none !important;
  }
  body.printing-cards .app { margin-left: 0 !important; padding-top: 0 !important; }
  body.printing-cards .content { padding: 0 !important; }
  body.printing-cards .page { max-width: none; }
  body.printing-cards .tool { border: none; padding: 0; }
  body.printing-cards .cards { display: block; }

  body.printing-cards .card-page {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 8mm;
    height: 270mm;
    break-after: page;
    page-break-after: always;
  }
  body.printing-cards .card-page:last-child {
    break-after: auto;
    page-break-after: auto;
  }
  body.printing-cards .card {
    border: 0.6mm solid #000;
    border-radius: 3mm;
    padding: 4mm 4mm 3mm;
    break-inside: avoid;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
  body.printing-cards .card-title { font-size: 13pt; margin-bottom: 3mm; }
  body.printing-cards .card-grid th { font-size: 16pt; padding: 1.5mm 0; background: #000; }
  body.printing-cards .card-grid th,
  body.printing-cards .card-grid td { border: 0.4mm solid #000; }
  body.printing-cards .card-grid td { font-size: 18pt; height: 17mm; }
  body.printing-cards .card-grid td.is-free { font-size: 10pt; background: #eee; }
  body.printing-cards .card-no { font-size: 9pt; margin-top: 2mm; }

  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
