/* =========================================================
 * でじらぼ 交流ビンゴ 共通の見た目（B13）
 * apps/nbingo・apps/pbingo・apps/sbingo の3本で 同じファイル。
 * ちがうのは いちばん上の :root の色だけ（直すときは 3本 そろえる）。
 * ========================================================= */
:root {
    --main: #1f9bc4;
    --main-dark: #13708f;
    --main-soft: #def3fa;
    --accent: #ff8a3d;
    --accent-dark: #d0661f;
    --paper: #fffbea;
    --dot: #ffe9a8;
}

:root {
    --ink: #444;
    --font: 'M PLUS Rounded 1c', 'Gowun Dodum', 'Hiragino Maru Gothic ProN', 'Hiragino Sans', 'BIZ UDPGothic', 'Meiryo', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
    --font-hand: 'Klee One', 'M PLUS Rounded 1c', 'Gowun Dodum', 'UD Digi Kyokasho N-R', 'Hiragino Maru Gothic ProN', 'Hiragino Sans', 'BIZ UDPGothic', 'Meiryo', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: calc(140px + env(safe-area-inset-left, 0px));
    /* ビンゴの盤の大きさ：高さ と 横はば（右の パネル 360px を ひいた のこり）の 小さいほう */
    --board: min(calc(100dvh - 96px - var(--safe-top) - var(--safe-bottom)), calc(100vw - 420px));
}
html[lang="ko"] { --font: 'Gowun Dodum', 'M PLUS Rounded 1c', 'Apple SD Gothic Neo', 'Malgun Gothic', 'Hiragino Maru Gothic ProN', 'Hiragino Sans', 'BIZ UDPGothic', 'Meiryo', sans-serif; }
html[lang="ko"] body { word-break: keep-all; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
    font-family: var(--font); color: var(--ink); background-color: var(--paper);
    background-image: radial-gradient(var(--dot) 10%, transparent 10%), radial-gradient(var(--dot) 10%, transparent 10%);
    background-size: 20px 20px; background-position: 0 0, 10px 10px;
    height: 100dvh; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
textarea { user-select: text; -webkit-user-select: text; }

/* UI要塞化 */
.hidden { opacity: 0 !important; pointer-events: none !important; visibility: hidden !important; z-index: -1 !important; position: absolute !important; }

.app { position: relative; width: 100%; height: 100%; }
.screen { position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
.lang-slot { position: absolute; top: calc(10px + var(--safe-top)); right: calc(10px + env(safe-area-inset-right, 0px)); z-index: 100; }

.wrap { max-width: 820px; margin: 0 auto; padding: calc(76px + var(--safe-top)) 20px calc(40px + var(--safe-bottom)); }
h1 { margin: 0 0 14px; text-align: center; color: var(--main); font-size: clamp(1.5rem, 3.4vw, 2.1rem); font-weight: 900; text-shadow: 2px 2px 0 var(--dot); }
.lead { text-align: center; font-weight: 700; line-height: 1.7; margin: 0 0 16px; }
.card { background: #fff; border: 4px solid var(--main); border-radius: 22px; padding: 18px 20px; margin-bottom: 18px; box-shadow: 4px 4px 0 var(--main); }
.card h3 { margin: 0 0 8px; font-size: 1.2rem; }
.card p { margin: 6px 0; line-height: 1.7; }
.note { font-size: 0.92rem; color: #777; }
.safe-note { background: var(--main-soft); color: var(--main-dark); border-radius: 14px; padding: 10px 14px; font-weight: 700; line-height: 1.6; font-size: 0.95rem; }

textarea {
    width: 100%; min-height: 200px; resize: vertical; border: 3px solid var(--main-soft); border-radius: 14px; padding: 12px;
    font-family: var(--font-hand); font-size: 1.15rem; line-height: 1.6; outline: none; background: #fff; color: var(--ink);
}
textarea:focus { border-color: var(--main); }

.btn {
    font-family: var(--font); font-weight: 800; font-size: clamp(1.05rem, 2.2vw, 1.3rem); line-height: 1.3;
    min-height: 60px; padding: 10px 24px; border: none; border-radius: 50px; cursor: pointer; color: #fff; background: var(--accent);
    box-shadow: 0 5px 0 var(--accent-dark); display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    transition: transform 0.08s, box-shadow 0.08s; touch-action: manipulation; text-align: center;
}
.btn:active:not(:disabled) { transform: translateY(5px); box-shadow: none; }
.btn:disabled { background: #c5c5c5; box-shadow: 0 5px 0 #999; cursor: default; }
.btn:focus-visible { outline: 3px solid var(--main-dark); outline-offset: 3px; }
.btn-main { background: var(--main); box-shadow: 0 5px 0 var(--main-dark); }
.btn-green { background: #2eaa63; box-shadow: 0 5px 0 #1f7a46; }
.btn-gray { background: #8a959e; box-shadow: 0 5px 0 #66717a; }
.btn-light { background: #fff; color: var(--main); border: 3px solid var(--main); box-shadow: 0 5px 0 var(--main-soft); }
.btn-wide { width: 100%; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > .btn { flex: 1 1 200px; }
.center { text-align: center; }

.msg { margin: 10px 0 0; padding: 10px 14px; border-radius: 12px; font-weight: 700; line-height: 1.6; }
.msg.ok { background: #e6f7ec; color: #1f7a46; }
.msg.ng { background: #ffe9e6; color: #b03a2e; }
.msg.info { background: var(--main-soft); color: var(--main-dark); }
#qr-canvas { background: #fff; border: 6px solid #fff; border-radius: 12px; box-shadow: 0 4px 12px rgba(0,0,0,0.12); image-rendering: pixelated; max-width: 100%; }

/* ===== 名前を えらぶ（大きな ボタン） ===== */
.name-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.name-btn {
    min-height: 64px; padding: 6px 10px; border-radius: 16px; border: 3px solid var(--main); background: #fff; color: var(--ink);
    font-family: var(--font-hand); font-weight: 600; font-size: 1.25rem; line-height: 1.25; cursor: pointer; touch-action: manipulation;
    box-shadow: 0 4px 0 var(--main-soft); overflow-wrap: anywhere;
}
.name-btn:active:not(:disabled) { transform: translateY(4px); box-shadow: none; }
.name-btn:disabled { border-color: #ddd; color: #aaa; background: #f4f4f4; box-shadow: none; cursor: default; }
.name-btn .used { display: block; font-family: var(--font); font-size: 0.75rem; font-weight: 700; color: #999; }

/* ===== 小窓（名前の えらびなおし・たしかめ） ===== */
.overlay {
    position: fixed; inset: 0; z-index: 8000; background: rgba(30,36,46,0.55); display: flex; align-items: center; justify-content: center;
    padding: calc(70px + var(--safe-top)) 12px calc(12px + var(--safe-bottom));
}
.sheet {
    width: min(900px, 100%); max-height: 100%; overflow-y: auto; background: var(--paper); border: 5px solid var(--main); border-radius: 24px;
    padding: 16px 18px 18px; box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}
.sheet-head { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.sheet-head img { width: 84px; height: 84px; object-fit: contain; background: #fff; border-radius: 14px; border: 3px solid var(--main-soft); flex: 0 0 auto; }
.sheet-head h2 { margin: 0; font-size: clamp(1.2rem, 2.6vw, 1.6rem); color: var(--main-dark); line-height: 1.4; }
.sheet-head .ask { display: block; font-size: 0.95rem; color: #666; font-weight: 700; margin-top: 2px; }
.sheet-foot { display: flex; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
/* 名前が 多くても「とじる」が いつも 見える */
.sheet > .sheet-foot { position: sticky; bottom: -18px; margin: 14px -18px -18px; padding: 12px 18px 16px; background: var(--paper); border-top: 3px solid var(--main-soft); }
.sheet .name-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
@media (max-height: 760px) { .sheet .name-btn { min-height: 56px; font-size: 1.15rem; } .sheet-head img { width: 64px; height: 64px; } }
.sheet-foot .btn { flex: 1 1 200px; }
.dialog-box { width: min(460px, 100%); background: #fff; border: 5px solid var(--main); border-radius: 24px; padding: 22px 20px 16px; text-align: center; }
.dialog-box p { margin: 0 0 6px; font-size: 1.25rem; font-weight: 800; line-height: 1.6; white-space: pre-wrap; }

/* ===== カードを つくる（pbingo・sbingo） ===== */
.build { display: grid; grid-template-columns: var(--board) minmax(0, 1fr); gap: 20px; padding: calc(70px + var(--safe-top)) 20px calc(12px + var(--safe-bottom)); height: 100%; }
.build-side { display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.build-side h2 { margin: 0; color: var(--main); font-size: clamp(1.2rem, 2.4vw, 1.6rem); font-weight: 900; }
.build-side .how { margin: 0; font-weight: 700; line-height: 1.6; }
.tray { flex: 1 1 auto; min-height: 0; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; align-content: start;
    background: #fff; border: 4px solid #f1c40f; border-radius: 18px; padding: 10px; }
.tray-item { aspect-ratio: 1 / 1; border: 3px solid #ddd; border-radius: 14px; background: var(--paper); padding: 4px; cursor: pointer; touch-action: manipulation; display: flex; }
.tray-item img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.tray-item.selected { border-color: var(--accent); border-width: 5px; transform: scale(1.06); box-shadow: 0 4px 10px rgba(0,0,0,0.18); }
.tray-item.used { opacity: 0.28; filter: grayscale(60%); }

/* ===== ビンゴの盤 ===== */
.board { width: var(--board); height: var(--board); display: grid; gap: 8px; align-self: start; }
.cell {
    position: relative; min-width: 0; min-height: 0; background: #fff; border: 3px dashed var(--main); border-radius: 16px; overflow: hidden;
    display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 4px; cursor: pointer;
    touch-action: manipulation; box-shadow: 2px 2px 5px rgba(0,0,0,0.06); transition: transform 0.12s;
}
.cell:active { transform: scale(0.96); }
.cell:focus-visible { outline: 4px solid var(--main-dark); outline-offset: 2px; }
.cell.filled { border-style: solid; }
.cell .cimg { width: 100%; flex: 1 1 auto; min-height: 0; object-fit: contain; pointer-events: none; }
.cell .cname {
    flex: 0 0 auto; width: 100%; font-family: var(--font-hand); font-weight: 600; line-height: 1.2; color: var(--ink);
    font-size: calc(var(--board) / var(--n, 3) / 7.5); overflow-wrap: anywhere; padding: 2px 2px 0;
}
.cell .cname.empty { color: #aaa; font-family: var(--font); font-weight: 700; font-size: calc(var(--board) / var(--n, 3) / 9); }
.cell .ctext { font-family: var(--font-hand); font-weight: 600; line-height: 1.25; font-size: calc(var(--board) / var(--n, 3) / 5.6); overflow-wrap: anywhere; }
.cell.free { background: #fff9c4; border-style: solid; cursor: default; }
.cell .free-label { font-size: calc(var(--board) / var(--n, 3) / 10); color: #d35400; font-weight: 800; }
.cell.marked { background: #fff3f6; border-style: solid; border-color: #f48fb1; }
.cell.marked::after {
    content: "🌸"; position: absolute; top: 2px; left: 4px; font-size: calc(var(--board) / var(--n, 3) / 4.2); line-height: 1;
    animation: pop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) both; pointer-events: none; filter: drop-shadow(2px 2px 2px rgba(0,0,0,0.2));
}
.cell.line { box-shadow: 0 0 0 4px #ffd54f inset; }
@keyframes pop { 0% { transform: scale(0) rotate(-20deg); } 100% { transform: scale(1) rotate(0); } }

/* ===== あそぶ 画面 ===== */
.play { display: grid; grid-template-columns: var(--board) minmax(0, 1fr); gap: 20px; padding: calc(70px + var(--safe-top)) 20px calc(12px + var(--safe-bottom)); min-height: 100%; }
.side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.side h2 { margin: 0; font-size: clamp(1.15rem, 2.3vw, 1.5rem); color: var(--main); font-weight: 900; line-height: 1.35; overflow-wrap: anywhere; }
.side .how { margin: 0; font-weight: 700; line-height: 1.6; font-size: 0.98rem; }
.bingo-count { font-size: clamp(1.3rem, 2.8vw, 1.8rem); font-weight: 900; color: #d35400; text-align: center; background: #fff; border: 4px solid #ffd54f; border-radius: 18px; padding: 6px 10px; }
.thanks { background: #fff; border: 4px solid var(--main); border-radius: 18px; padding: 10px 12px; }
.thanks h3 { margin: 0 0 6px; color: var(--main); font-size: 1.15rem; }
.thanks .btn { width: 100%; min-height: 56px; font-size: 1.1rem; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; max-height: 120px; overflow-y: auto; }
.tag { background: var(--main-soft); border: 2px solid var(--main); border-radius: 20px; padding: 4px 12px; font-family: var(--font-hand); font-weight: 600; color: var(--main-dark); animation: pop 0.3s ease both; }
.side .btn-small { min-height: 52px; font-size: 1rem; }

/* ビンゴ！の お祝い */
#bingo-banner {
    position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 8500; pointer-events: none;
    font-size: clamp(3rem, 10vw, 6rem); font-weight: 900; color: #fff; text-shadow: 0 6px 0 #d35400, 0 0 24px rgba(255,160,0,0.8);
    -webkit-text-stroke: 3px #d35400; white-space: nowrap; animation: banner 1.6s ease both;
}
@keyframes banner { 0% { transform: translate(-50%, -50%) scale(0.2); opacity: 0; } 18% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; } 30% { transform: translate(-50%, -50%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -50%) scale(1); } }

#toast {
    position: fixed; left: 50%; bottom: calc(22px + var(--safe-bottom)); transform: translateX(-50%); z-index: 8600; max-width: min(92vw, 640px);
    background: rgba(40,48,60,0.95); color: #fff; padding: 12px 20px; border-radius: 16px; font-weight: 700; line-height: 1.6; text-align: center;
}
#qr-zoom { position: fixed; inset: 0; z-index: 8000; background: rgba(255,255,255,0.98); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; cursor: pointer; }
#qr-zoom canvas { image-rendering: pixelated; }
#qr-zoom p { margin: 0; color: #777; font-weight: 700; }
#qr-zoom.hidden { max-width: 0 !important; max-height: 0 !important; overflow: hidden !important; }  /* P1：かくした 600px の QR が スマホの たてで ページの はばを のばしていた（tbingo・spot と 同じ 直し） */

/* せまい 画面・たて：盤を 上、パネルを 下に（スクロール） */
@media (max-width: 760px) {
    :root { --board: min(calc(100vw - 32px), 560px); }
    .build, .play { grid-template-columns: minmax(0, 1fr); height: auto; padding-left: 16px; padding-right: 16px; }
    .board { justify-self: center; }
    .tray { max-height: none; }
}
@media (prefers-reduced-motion: reduce) {
    .cell.marked::after, .tag, #bingo-banner { animation: none; }
    .cell, .btn { transition: none; }
}
@media print {
    .btn, .lang-slot, .overlay, #toast { display: none !important; }
}
