/* ============================================================
   お仕事ビンゴ — デザイントークン
   方向性: 縁日×ゲームショー。深紺ステージ＋金アクセント、
   BINGO各列=カテゴリ色（B青/I橙/N桃/G緑/O紫）
   ============================================================ */
:root {
  --cat-b: #4f8df7; /* B ものづくり */
  --cat-i: #f6a13c; /* I 建てる・直す */
  --cat-n: #f2679d; /* N 売る・もてなす */
  --cat-g: #34c98a; /* G 支える・運ぶ */
  --cat-o: #a07ef5; /* O 守る・育てる */

  --bg: #10172b;
  --bg-glow: #1b2547;
  --surface: #1c2745;
  --surface-2: #243156;
  --line: #35426e;
  --text: #f2f5fd;
  --text-dim: #9aa6c8;
  --accent: #ffc857;
  --accent-deep: #e8a219;
  --danger: #ff6b6b;

  --ink: #1c2433;       /* 印刷カードの文字色 */
  --paper-line: #2a3450;

  --radius: 14px;
  --radius-lg: 22px;
  --reel-item-h: 112px; /* JSと同期（app.jsが上書き設定） */

  --dur-fast: 150ms;
  --dur: 300ms;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  --font-round: "Hiragino Maru Gothic ProN", "BIZ UDPGothic", "Yu Gothic UI",
    "YuGothic", "Meiryo", sans-serif;
}

* { box-sizing: border-box; }

/* hidden属性を最優先（#view-title等のdisplay指定に負けないように） */
[hidden] { display: none !important; }

html { color-scheme: dark; }

body {
  margin: 0;
  font-family: var(--font-round);
  background:
    radial-gradient(1100px 520px at 50% -140px, var(--bg-glow), transparent 70%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}

button { font-family: inherit; cursor: pointer; }
h2 { font-size: 1.05rem; letter-spacing: 0.06em; color: var(--text-dim); margin: 0 0 12px; }
h2 small { font-weight: normal; font-size: 0.78em; margin-left: 6px; }

main { max-width: 1180px; margin: 0 auto; padding: 18px clamp(12px, 3vw, 32px) 80px; }

/* ============ ヘッダー ============ */
.app-header {
  display: flex; flex-wrap: wrap; align-items: center; gap: 14px 22px;
  padding: 16px clamp(12px, 3vw, 32px) 6px;
  max-width: 1180px; margin: 0 auto;
}
.logo { margin: 0; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.logo-main { font-size: 1.7rem; font-weight: 800; letter-spacing: 0.04em; }
.logo-bingo { display: inline-flex; gap: 3px; }
.logo-bingo b {
  display: inline-grid; place-items: center;
  width: 1.55em; height: 1.55em; font-size: 1.15rem;
  background: var(--cat); color: #101526; border-radius: 8px;
  transform: rotate(-4deg);
  box-shadow: 0 3px 0 rgb(0 0 0 / 0.35);
}
.logo-bingo b:nth-child(even) { transform: rotate(4deg) translateY(-2px); }
.logo-sub { font-size: 0.82rem; color: var(--text-dim); letter-spacing: 0.08em; }

.header-controls { margin-left: auto; display: flex; gap: 8px; }
body[data-view="title"] .app-header { display: none; } /* タイトル画面はヒーローが看板を兼ねる */
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}

/* ============ タイトル画面 ============ */
#view-title { display: grid; place-items: center; min-height: calc(100vh - 60px); }
.title-hero {
  position: relative; text-align: center; padding: 48px 20px 40px;
  display: flex; flex-direction: column; align-items: center; gap: 26px;
  width: 100%;
}
.title-kicker {
  margin: 0; color: var(--accent); font-weight: 800; letter-spacing: 0.3em; text-indent: 0.3em;
  font-size: clamp(0.8rem, 1.6vw, 1.05rem);
}
.title-logo { display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap; }
.title-logo .t-main {
  font-size: clamp(2.6rem, 7vw, 4.6rem); font-weight: 800; letter-spacing: 0.06em;
  text-shadow: 0 6px 0 rgb(0 0 0 / 0.35);
}
.title-logo .t-bingo { display: inline-flex; gap: 8px; }
.title-logo .t-bingo b {
  display: inline-grid; place-items: center;
  width: 1.5em; height: 1.5em; font-size: clamp(2rem, 5.4vw, 3.6rem);
  background: var(--cat); color: #101526; border-radius: 0.26em;
  transform: rotate(-5deg);
  box-shadow: 0 0.14em 0 rgb(0 0 0 / 0.35);
  animation: titleBob 2.6s ease-in-out infinite;
}
.title-logo .t-bingo b:nth-child(even) { transform: rotate(5deg); animation-delay: 0.35s; }
.title-logo .t-bingo b:nth-child(3) { animation-delay: 0.7s; }
.title-logo .t-bingo b:nth-child(5) { animation-delay: 1.05s; }
@keyframes titleBob {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 -7px; }
}
.title-menu { display: flex; flex-direction: column; gap: 16px; width: min(440px, 92vw); margin-top: 8px; }
.menu-btn {
  display: grid; grid-template-columns: 64px 1fr; grid-template-rows: auto auto; align-items: center;
  text-align: left; padding: 18px 22px; border-radius: 20px;
  background: var(--surface-2); border: 2px solid var(--line); color: var(--text);
  transition: transform var(--dur-fast) var(--ease-out), border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.menu-btn .m-icon { grid-row: 1 / 3; font-size: 2.3rem; }
.menu-btn .m-label { font-size: 1.45rem; font-weight: 800; letter-spacing: 0.05em; }
.menu-btn .m-sub { font-size: 0.84rem; color: var(--text-dim); font-weight: 700; margin-top: 3px; }
.menu-btn:hover { transform: translateY(-3px); border-color: var(--text-dim); box-shadow: 0 14px 30px rgb(0 0 0 / 0.4); }
.menu-btn.primary {
  background: linear-gradient(180deg, #ffd97a, var(--accent) 60%, var(--accent-deep));
  border-color: transparent; color: #2a1d04;
  box-shadow: 0 6px 0 #8f6510, 0 18px 40px rgb(232 162 25 / 0.30);
}
.menu-btn.primary .m-sub { color: #6b4e0d; }
.menu-btn.primary:hover { transform: translateY(-3px); filter: brightness(1.04); }
.menu-btn.primary:active, .menu-btn:active { transform: translateY(2px); }
.title-toggles { display: flex; gap: 10px; }
.title-deco { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.title-deco i {
  position: absolute; width: 16px; height: 16px; border-radius: 50%;
  opacity: 0.5; animation: decoFloat 7s ease-in-out infinite;
}
.title-deco i:nth-child(1) { background: var(--cat-b); left: 8%;  top: 12%; }
.title-deco i:nth-child(2) { background: var(--cat-i); left: 88%; top: 18%; animation-delay: 1.1s; }
.title-deco i:nth-child(3) { background: var(--cat-n); left: 14%; top: 72%; animation-delay: 2.2s; }
.title-deco i:nth-child(4) { background: var(--cat-g); left: 82%; top: 66%; animation-delay: 3.3s; }
.title-deco i:nth-child(5) { background: var(--cat-o); left: 28%; top: 30%; animation-delay: 4.4s; width: 10px; height: 10px; }
.title-deco i:nth-child(6) { background: var(--accent); left: 70%; top: 40%; animation-delay: 5.5s; width: 10px; height: 10px; }
@keyframes decoFloat {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-22px) scale(1.15); }
}

/* ============ 確認ダイアログ ============ */
#app-dialog {
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  color: var(--text);
  border: 2px solid var(--line); border-radius: 20px;
  padding: 30px 34px; width: min(460px, 92vw);
  box-shadow: 0 30px 80px rgb(0 0 0 / 0.6);
}
#app-dialog::backdrop { background: rgb(7 10 20 / 0.72); }
#dialog-msg { margin: 0; font-size: 1.1rem; font-weight: 700; line-height: 1.8; }
.dialog-actions { display: flex; justify-content: center; gap: 14px; margin-top: 24px; }
.dialog-actions .btn-primary.danger {
  background: linear-gradient(180deg, #ff9d9d, var(--danger));
  box-shadow: 0 4px 0 #93302f; color: #2d0606;
}

/* ============ マシン: レイアウト ============ */
.machine-grid {
  display: grid; grid-template-columns: minmax(380px, 540px) 1fr;
  gap: 22px; align-items: stretch; margin-top: 10px;
}
@media (max-width: 920px) { .machine-grid { grid-template-columns: 1fr; } }

/* ---- リール ---- */
.reel-frame {
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1.5px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow: 0 18px 50px rgb(0 0 0 / 0.45);
}
.reel-viewport {
  position: relative; overflow: hidden;
  height: calc(var(--reel-item-h) * 3);
  border-radius: var(--radius);
  background: #0c1224;
}
.reel-strip { padding-top: var(--reel-item-h); }
.reel-item {
  height: var(--reel-item-h);
  display: flex; align-items: center; justify-content: center; gap: 16px;
  padding: 0 22px;
}
.reel-item .r-no {
  flex: none; min-width: 2.9em; text-align: center;
  font-size: 1.05rem; font-weight: 800; letter-spacing: 0.04em;
  color: #101526; background: var(--cat, var(--accent));
  border-radius: 999px; padding: 4px 10px;
}
.reel-item .r-name {
  font-size: 2.1rem; font-weight: 800; letter-spacing: 0.02em; white-space: nowrap;
}
.reel-item .r-name.sm { font-size: 1.6rem; }
.reel-item.is-center .r-name { color: #fff; }
.reel-item.reel-idle { color: var(--text-dim); font-size: 1.4rem; font-weight: 700; }

.reel-overlay { position: absolute; inset: 0; pointer-events: none; }
.reel-overlay::before, .reel-overlay::after {
  content: ""; position: absolute; left: 0; right: 0; height: var(--reel-item-h); z-index: 2;
}
.reel-overlay::before { top: 0; background: linear-gradient(#0c1224 18%, transparent); }
.reel-overlay::after { bottom: 0; background: linear-gradient(transparent, #0c1224 82%); }
.reel-window {
  position: absolute; left: 6px; right: 6px; top: var(--reel-item-h);
  height: var(--reel-item-h); z-index: 3;
  border: 3px solid var(--accent); border-radius: var(--radius);
  box-shadow: 0 0 26px rgb(255 200 87 / 0.30), inset 0 0 22px rgb(255 200 87 / 0.10);
}
.reel-window::before, .reel-window::after {
  position: absolute; top: 50%; translate: 0 -50%;
  font-size: 1rem; color: var(--accent);
}
.reel-window::before { content: "▶"; left: 8px; }
.reel-window::after { content: "◀"; right: 8px; }
.reel-frame.spinning .reel-window { animation: windowPulse 0.5s ease-in-out infinite alternate; }
@keyframes windowPulse {
  from { box-shadow: 0 0 18px rgb(255 200 87 / 0.25), inset 0 0 18px rgb(255 200 87 / 0.08); }
  to   { box-shadow: 0 0 36px rgb(255 200 87 / 0.50), inset 0 0 26px rgb(255 200 87 / 0.16); }
}

/* ---- 操作 ---- */
.machine-controls { margin-top: 16px; text-align: center; }
.btn-spin {
  width: 100%; padding: 18px; border: none; border-radius: 18px;
  font-size: 1.7rem; font-weight: 800; letter-spacing: 0.25em; text-indent: 0.25em;
  color: #2a1d04;
  background: linear-gradient(180deg, #ffd97a, var(--accent) 55%, var(--accent-deep));
  box-shadow: 0 6px 0 #8f6510, 0 16px 30px rgb(232 162 25 / 0.35);
  transition: transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast), filter var(--dur-fast);
}
.btn-spin:hover:not(:disabled) { transform: translateY(-2px); filter: brightness(1.05); }
.btn-spin:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 #8f6510, 0 8px 18px rgb(232 162 25 / 0.3); }
.btn-spin:disabled { filter: grayscale(0.75) brightness(0.75); cursor: not-allowed; box-shadow: 0 4px 0 #555; }

.sub-controls { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px; margin-top: 14px; }
.counter {
  font-weight: 800; font-size: 1.02rem; letter-spacing: 0.08em;
  background: var(--surface-2); border: 1.5px solid var(--line);
  padding: 7px 14px; border-radius: 999px;
}
.btn-ghost {
  background: transparent; border: 1.5px solid var(--line); color: var(--text-dim);
  padding: 7px 13px; border-radius: 999px; font-size: 0.88rem; font-weight: 700;
  transition: color var(--dur-fast), border-color var(--dur-fast);
}
.btn-ghost:hover:not(:disabled) { color: var(--text); border-color: var(--text-dim); }
.btn-ghost.danger:hover:not(:disabled) { color: var(--danger); border-color: var(--danger); }
.btn-ghost:disabled { opacity: 0.4; cursor: not-allowed; }
.hint { color: var(--text-dim); font-size: 0.78rem; margin: 10px 0 0; }

/* ---- 結果パネル ---- */
.result-panel {
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1.5px solid var(--line); border-radius: var(--radius-lg);
  padding: 26px; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 12px; text-align: center; min-height: 380px;
  box-shadow: 0 18px 50px rgb(0 0 0 / 0.45);
}
.res-empty { color: var(--text-dim); font-size: 1.15rem; font-weight: 700; }
.res-badge {
  display: grid; place-items: center; gap: 0;
  width: 118px; height: 118px; border-radius: 50%;
  background: var(--cat, var(--accent)); color: #101526;
  box-shadow: 0 8px 0 rgb(0 0 0 / 0.3), 0 0 40px color-mix(in oklab, var(--cat, var(--accent)) 55%, transparent);
  animation: badgePop 0.45s var(--ease-out);
}
@keyframes badgePop { from { transform: scale(0.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.res-letter { font-size: 1.5rem; font-weight: 800; line-height: 1; opacity: 0.85; }
.res-no { font-size: 3rem; font-weight: 800; line-height: 1.02; font-variant-numeric: tabular-nums; }
.res-name { font-size: clamp(2.2rem, 4.5vw, 3.4rem); font-weight: 800; letter-spacing: 0.02em; }
.res-name.sm { font-size: clamp(1.8rem, 3.6vw, 2.6rem); }
.res-desc { margin: 0; font-size: 1.18rem; color: var(--text); opacity: 0.92; max-width: 30em; line-height: 1.7; }
.res-cat {
  font-size: 0.92rem; font-weight: 800; color: #101526;
  background: var(--cat, var(--accent)); border-radius: 999px; padding: 5px 16px;
}

/* ============ 出た仕事ボード ============ */
.board-section { margin-top: 34px; }
.board { display: grid; gap: 8px; }
.board-row { display: grid; grid-template-columns: 92px 1fr; gap: 8px; align-items: stretch; }
.board-letter {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--cat); color: #101526; border-radius: 10px;
  font-size: 1.5rem; font-weight: 800; line-height: 1; padding: 6px 2px;
}
.board-letter small { font-size: 0.56rem; font-weight: 800; margin-top: 4px; letter-spacing: 0.02em; }
.board-cells { display: grid; grid-template-columns: repeat(15, 1fr); gap: 4px; }
.bcell {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 5px 2px 6px; text-align: center; min-width: 0;
  display: flex; flex-direction: column; gap: 2px;
  transition: background var(--dur-fast), border-color var(--dur-fast), opacity var(--dur-fast);
  opacity: 0.62;
}
.bcell .bno { font-size: 0.92rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.bcell .bname {
  font-size: 0.58rem; color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 2px;
}
.bcell.hit { background: var(--cat); border-color: var(--cat); color: #101526; opacity: 1; }
.bcell.hit .bname { color: #101526; }
.bcell.last { box-shadow: 0 0 0 3px var(--accent), 0 0 18px rgb(255 200 87 / 0.5); }
@media (max-width: 920px) {
  .board-cells { grid-template-columns: repeat(8, 1fr); }
  .board-row { grid-template-columns: 64px 1fr; }
}

/* ============ 履歴 ============ */
.history-section { margin-top: 30px; }
.history { display: flex; flex-wrap: wrap; gap: 8px; }
.history .h-empty { color: var(--text-dim); font-size: 0.9rem; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 13px 5px 6px; font-size: 0.88rem; font-weight: 700;
}
.chip .h-no {
  background: var(--cat, var(--accent)); color: #101526; border-radius: 999px;
  padding: 2px 9px; font-size: 0.8rem; font-weight: 800;
}
.chip .h-i { color: var(--text-dim); font-size: 0.76rem; font-weight: 700; }
.chip:first-child { border-color: var(--accent); box-shadow: 0 0 12px rgb(255 200 87 / 0.25); }

/* ============ 紙吹雪 ============ */
#confetti { position: fixed; left: 0; right: 0; top: 14%; height: 0; z-index: 60; pointer-events: none; }
#confetti i { position: absolute; width: 10px; height: 14px; border-radius: 2px; will-change: transform, opacity; }

/* ============ カードづくり画面 ============ */
.cards-controls {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 14px;
  background: var(--surface); border: 1.5px solid var(--line);
  border-radius: var(--radius-lg); padding: 16px 18px; margin-top: 10px;
}
.cards-controls label { display: flex; flex-direction: column; gap: 6px; font-size: 0.8rem; font-weight: 700; color: var(--text-dim); }
.cards-controls input, .cards-controls select {
  font-family: inherit; font-size: 1rem; font-weight: 700; color: var(--text);
  background: #0c1224; border: 1.5px solid var(--line); border-radius: 10px; padding: 9px 12px;
}
#card-title { width: 230px; }
#card-count { width: 86px; }
.btn-primary {
  border: none; border-radius: 12px; padding: 12px 22px;
  font-size: 1rem; font-weight: 800; color: #20180a;
  background: linear-gradient(180deg, #ffd97a, var(--accent));
  box-shadow: 0 4px 0 #8f6510;
  transition: transform var(--dur-fast), box-shadow var(--dur-fast), filter var(--dur-fast);
}
.btn-primary.alt { background: linear-gradient(180deg, #6ee3ad, var(--cat-g)); box-shadow: 0 4px 0 #18744c; color: #06281a; }
.btn-primary:hover { transform: translateY(-2px); filter: brightness(1.04); }
.btn-primary:active { transform: translateY(2px); box-shadow: 0 1px 0 #8f6510; }
.gen-status { font-size: 0.88rem; font-weight: 700; color: var(--cat-g); }
.print-hint { color: var(--text-dim); font-size: 0.82rem; margin: 12px 4px 0; line-height: 1.7; }

/* ---- A4ページ（画面プレビュー兼 印刷実体） ---- */
.cards-preview { margin-top: 18px; overflow-x: auto; }
.print-page {
  width: 210mm; height: 297mm; background: #fff; color: var(--ink);
  margin: 0 auto 22px; padding: 11mm 12mm;
  box-shadow: 0 10px 36px rgb(0 0 0 / 0.5); border-radius: 4px;
  display: flex; flex-direction: column; gap: 5mm;
}
.cut-line {
  border: none; border-top: 0.4mm dashed #9aa3b5; margin: 0; position: relative; flex: none;
}
.cut-line::after { content: "✂"; position: absolute; left: 4mm; top: -2.6mm; font-size: 3.6mm; color: #9aa3b5; background: #fff; padding: 0 1mm; }

.bingo-card { display: flex; flex-direction: column; gap: 2.5mm; min-height: 0; }
.layout-1 .bingo-card { flex: 1; }
.layout-2 .bingo-card { height: 131mm; flex: none; }

.bc-head { display: flex; align-items: baseline; justify-content: space-between; gap: 6mm; }
.bc-title { font-size: 16pt; font-weight: 800; letter-spacing: 0.06em; }
.layout-2 .bc-title { font-size: 13pt; }
.bc-meta { font-size: 9.5pt; font-weight: 700; color: #444d5e; display: flex; align-items: baseline; gap: 5mm; white-space: nowrap; }
.bc-nameline { display: inline-block; width: 42mm; border-bottom: 0.4mm solid #444d5e; }

.card-grid {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: repeat(5, 1fr);
  grid-template-rows: 11mm repeat(5, 1fr);
  border: 0.7mm solid var(--ink); border-radius: 2.5mm; overflow: hidden;
  background: #fff;
}
.layout-2 .card-grid { grid-template-rows: 9mm repeat(5, 1fr); }
.cg-head {
  background: var(--cat); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  line-height: 1.05; gap: 0.6mm;
  print-color-adjust: exact; -webkit-print-color-adjust: exact;
}
.cg-head .l { font-size: 14.5pt; font-weight: 800; }
.cg-head .c { font-size: 5.6pt; font-weight: 800; letter-spacing: 0.02em; }
.layout-2 .cg-head .l { font-size: 12pt; }
.layout-2 .cg-head .c { font-size: 5pt; }
.cg-cell {
  position: relative; border-top: 0.35mm solid var(--ink); border-left: 0.35mm solid var(--ink);
  display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 3.2mm 1.4mm 1.4mm; min-width: 0; min-height: 0;
}
.cg-cell:nth-child(5n + 1) { border-left: none; }
.c-no {
  position: absolute; top: 1mm; left: 1.6mm;
  font-size: 7pt; font-weight: 800; color: #8a93a8; letter-spacing: 0.03em;
}
.c-name { font-size: 13pt; font-weight: 800; line-height: 1.3; overflow-wrap: anywhere; }
.c-name.sm { font-size: 10.5pt; }
.layout-2 .c-name { font-size: 10pt; }
.layout-2 .c-name.sm { font-size: 8pt; }
.layout-2 .c-no { font-size: 5.8pt; }
.cg-cell.free { background: #fff4d6; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
.cg-cell.free .c-name { color: #c98a12; letter-spacing: 0.1em; }
.cg-cell.free .star { display: block; font-size: 1.25em; line-height: 1.1; }

.bc-foot { font-size: 8.5pt; font-weight: 700; color: #444d5e; text-align: center; }
.layout-2 .bc-foot { font-size: 7.5pt; }

/* ============ 印刷 ============ */
@page { size: A4 portrait; margin: 0; }
@media print {
  body { background: #fff; }
  .app-header, .cards-controls, .print-hint, #view-machine, #view-title, #confetti, .gen-status, #app-dialog { display: none !important; }
  main { max-width: none; padding: 0; margin: 0; }
  .cards-preview { margin: 0; overflow: visible; }
  .print-page { margin: 0; box-shadow: none; border-radius: 0; }
  .print-page:not(:last-child) { page-break-after: always; }
  .bingo-card { break-inside: avoid; }
}

/* ============ モーション配慮 ============ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
