:root {
  --bg1: #1b1033; --bg2: #3a1b52; --ink: #fff8ee; --muted: #cbb9df;
  --pink: #ff7eb6; --pink-d: #e8508f; --gold: #ffd36b; --green: #5de0a6; --blue: #6ab7ff;
  --panel: rgba(30, 18, 54, .88); --line: rgba(255, 255, 255, .16);
  --font: 'Zen Maru Gothic', 'Hiragino Maru Gothic ProN', 'Yu Gothic', sans-serif;
  --mincho: 'Shippori Mincho', 'Yu Mincho', serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg1); color: var(--ink); font-family: var(--font); overflow: hidden; touch-action: manipulation; }
button { font-family: inherit; }
[hidden] { display: none !important; }
#app { position: fixed; inset: 0; }

.screen { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; flex-direction: column; padding: env(safe-area-inset-top) 12px env(safe-area-inset-bottom); }
.screen.active { display: flex; }
#title, #setup-cpu, #online, #waiting {
  background: url(/assets/ui/title_bg.webp) center/cover no-repeat,
    radial-gradient(ellipse at 20% 10%, #6b2a86 0, transparent 55%),
    radial-gradient(ellipse at 90% 90%, #b83a73 0, transparent 50%),
    linear-gradient(160deg, var(--bg2), var(--bg1));
}

/* タイトル */
.logo { text-align: center; margin-bottom: 4vh; position: relative; z-index: 1; }
.logo small { letter-spacing: .4em; color: var(--muted); font-size: 14px; }
.logo h1 { font-family: var(--mincho); font-weight: 800; font-size: clamp(84px, 22vw, 150px); margin: 0; line-height: 1.05; letter-spacing: .08em;
  background: linear-gradient(180deg, #fff 10%, var(--pink) 90%); -webkit-background-clip: text; background-clip: text; color: transparent; filter: drop-shadow(0 4px 18px rgba(255, 90, 160, .5)); }
.logo p { margin: 0; font-family: var(--mincho); letter-spacing: .3em; color: var(--gold); font-size: clamp(14px, 3.6vw, 20px); }
.menu { display: flex; flex-direction: column; gap: 14px; width: min(320px, 82vw); position: relative; z-index: 1; }
.petals { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.petal { position: absolute; top: -30px; width: 14px; height: 18px; background: radial-gradient(circle at 30% 30%, #ffe3ee, #ff9cc2); border-radius: 80% 0 80% 0; opacity: .8; animation: fall linear infinite; }
@keyframes fall { to { transform: translate(var(--sx), 110vh) rotate(720deg); } }
.sound-toggle { position: absolute; right: 14px; bottom: 14px; background: none; border: 1px solid var(--line); color: var(--ink); width: 44px; height: 44px; border-radius: 50%; font-size: 20px; cursor: pointer; z-index: 1; }

/* ボタン/パネル */
.btn { appearance: none; border: 1px solid var(--line); background: rgba(255, 255, 255, .1); color: var(--ink); padding: 13px 20px; border-radius: 999px; font-size: 16px; font-weight: 700; cursor: pointer; transition: transform .12s, background .2s, box-shadow .2s; }
.btn:hover { background: rgba(255, 255, 255, .2); transform: translateY(-1px); }
.btn:active { transform: translateY(1px) scale(.98); }
.btn.primary { background: linear-gradient(180deg, var(--pink), var(--pink-d)); border-color: transparent; box-shadow: 0 6px 20px rgba(232, 80, 143, .45); }
.btn.warn { background: linear-gradient(180deg, #ffb35c, #e8801f); border-color: transparent; color: #2a1400; box-shadow: 0 6px 20px rgba(232, 128, 31, .4); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.panel { width: min(520px, 94vw); max-height: 94vh; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 24px; padding: 22px 22px 18px; backdrop-filter: blur(10px); box-shadow: 0 20px 60px rgba(0, 0, 0, .5); }
.panel.center { text-align: center; }
.panel h2 { margin: 0 0 6px; font-family: var(--mincho); font-size: 28px; letter-spacing: .1em; }
.panel h3 { margin: 16px 0 8px; font-size: 14px; color: var(--muted); letter-spacing: .1em; }
.row { display: flex; gap: 10px; justify-content: space-between; margin-top: 20px; }
.row .btn { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.note { color: var(--muted); font-size: 13px; line-height: 1.6; margin: 10px 0 0; min-height: 1em; }
.choices { display: grid; gap: 8px; }
.choice input, .seg input { position: absolute; opacity: 0; pointer-events: none; }
.choice > span { display: block; padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; cursor: pointer; background: rgba(255, 255, 255, .05); }
.choice b { display: block; font-size: 16px; }
.choice i { display: block; font-style: normal; font-size: 12.5px; color: var(--muted); margin-top: 3px; line-height: 1.5; }
.choice em { font-style: normal; background: var(--gold); color: #3a2400; border-radius: 6px; padding: 1px 6px; font-size: 11px; margin-left: 4px; }
.choice input:checked + span { border-color: var(--pink); background: rgba(255, 126, 182, .18); box-shadow: 0 0 0 2px rgba(255, 126, 182, .35) inset; }
.seg { display: flex; gap: 8px; }
.seg label { flex: 1; }
.seg span { display: block; text-align: center; padding: 10px 6px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; background: rgba(255, 255, 255, .05); font-weight: 700; }
.seg input:checked + span { border-color: var(--pink); background: rgba(255, 126, 182, .22); }
.field { display: block; font-size: 14px; color: var(--muted); margin-top: 8px; }
.field input, .join input { display: block; width: 100%; margin-top: 6px; padding: 12px 14px; font: inherit; font-size: 16px; color: var(--ink); background: rgba(255, 255, 255, .08); border: 1px solid var(--line); border-radius: 12px; }
.join { display: flex; gap: 8px; }
.join input { margin: 0; text-transform: uppercase; letter-spacing: .3em; text-align: center; font-weight: 700; }
.code { font-family: var(--mincho); font-size: 56px; letter-spacing: .25em; margin: 4px 0 14px; color: var(--gold); text-shadow: 0 0 18px rgba(255, 211, 107, .5); }
.spinner { width: 40px; height: 40px; border: 4px solid var(--line); border-top-color: var(--pink); border-radius: 50%; margin: 18px auto; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#btn-wait-cancel { margin-top: 12px; }

/* ゲーム画面 */
#game { justify-content: flex-start; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); background: var(--bg1); }
.hud { width: 100%; max-width: 1100px; display: flex; align-items: stretch; justify-content: space-between; gap: 6px; padding: 6px 10px; flex: none; }
.pl { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1 1 0; max-width: 320px; position: relative; padding: 4px 8px; border-radius: 14px; transition: background .3s, box-shadow .3s; }
.pl.me { justify-content: flex-end; text-align: right; }
.pl.active { background: rgba(255, 126, 182, .18); box-shadow: 0 0 0 2px var(--pink) inset, 0 0 18px rgba(255, 126, 182, .5); }
.avatar { width: 44px; height: 44px; border-radius: 50%; background: linear-gradient(135deg, #8a5fc0, #ff7eb6) center/cover; display: grid; place-items: center; font-size: 11px; font-weight: 900; flex: none; border: 2px solid var(--line); overflow: hidden; }
.avatar.has-img span { display: none; }
.avatar.me { background-image: linear-gradient(135deg, #3b7bd8, #5de0a6); }
/* 画像があるとき(背景画像はJSがstyleで指定)は、位置と大きさを揃える */
.avatar.has-img { background-position: center; background-size: cover; background-repeat: no-repeat; }
.pi { min-width: 0; line-height: 1.2; }
.pi b { font-size: 13px; display: inline-block; max-width: 8em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.dealer { display: none; margin-left: 4px; background: var(--gold); color: #3a2400; font-size: 10px; font-weight: 900; padding: 1px 5px; border-radius: 6px; vertical-align: top; }
.dealer.on { display: inline-block; }
.score { font-family: var(--mincho); font-weight: 800; font-size: 26px; line-height: 1; transition: transform .3s; }
.score.pop { transform: scale(1.35); color: var(--gold); }
.mid { text-align: center; flex: none; font-size: 14px; font-weight: 700; display: flex; flex-direction: column; justify-content: center; min-width: 88px; }
.mid .sub { font-size: 11px; color: var(--muted); font-weight: 500; }
.turn { font-size: 12px; color: var(--gold); min-height: 1.2em; }
.bubble { position: absolute; left: 54px; top: 100%; z-index: 30; background: #fff; color: #2a1240; padding: 6px 12px; border-radius: 14px; font-size: 13px; font-weight: 700; opacity: 0; transform: translateY(-6px); transition: .25s; pointer-events: none; white-space: nowrap; }
.bubble.show { opacity: 1; transform: none; }

#board { position: relative; flex: 1; width: 100%; max-width: 1100px; min-height: 0; overflow: hidden; border-radius: 22px 22px 0 0;
  background: url(/assets/ui/table.webp) center/cover no-repeat,
    radial-gradient(ellipse at 50% 45%, #2a6a55 0, #1b4a3d 55%, #123228 100%); box-shadow: 0 0 0 1px var(--line) inset; }
.tools { display: flex; flex-direction: column; gap: 4px; justify-content: center; flex: none; }
.icon-btn { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: rgba(20, 10, 40, .7); color: var(--ink); font-size: 16px; cursor: pointer; padding: 0; }
.stamps { position: absolute; right: 8px; top: calc(env(safe-area-inset-top) + 60px); z-index: 400; display: flex; flex-direction: column; gap: 5px; align-items: stretch; background: var(--panel); padding: 8px; border-radius: 16px; border: 1px solid var(--line); animation: pop .25s; }
.stamps button { border: 1px solid var(--line); background: rgba(255, 255, 255, .08); color: var(--ink); border-radius: 999px; padding: 8px 14px; font-size: 13px; font-weight: 700; cursor: pointer; font-family: inherit; }

/* 札 */
.card { position: absolute; left: 0; top: 0; width: var(--cw); height: var(--ch); transform-origin: 50% 50%; transition: transform .5s cubic-bezier(.22, .9, .3, 1); will-change: transform; perspective: 900px; cursor: default; user-select: none; -webkit-user-drag: none; }
.board.no-anim .card, .no-anim .card { transition: none !important; }
.card .lift { width: 100%; height: 100%; transition: transform .18s; }
.card .flip { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform .5s; }
.card.down .flip { transform: rotateY(180deg); }
.face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 7%/4%; overflow: hidden; box-shadow: 0 2px 5px rgba(0, 0, 0, .5); }
.face img { width: 100%; height: 100%; display: block; object-fit: cover; pointer-events: none; }
/* 裏面: 本物の花札と同じ、絵のない無地(黒)に白い縁。四隅に角当てを付けた立体的な画像(assets/cards/back.webp。元は docs/card-back.svg) */
.face.back { transform: rotateY(180deg); background: #15110f url(/assets/cards/back.webp) center / 100% 100% no-repeat; }
.card.playable .face { box-shadow: 0 0 0 2px var(--gold), 0 0 14px rgba(255, 211, 107, .7); }
.card.selected .lift { transform: translateY(-18%); }
.card.selected .face { box-shadow: 0 0 0 3px var(--pink), 0 0 20px var(--pink); }
.card.target .face { box-shadow: 0 0 0 3px var(--green), 0 0 18px var(--green); animation: pulse .8s ease-in-out infinite alternate; cursor: pointer; }
.card.hint .face { box-shadow: 0 0 0 2px var(--blue), 0 0 14px var(--blue); }
.card.hit .face { animation: hit .3s ease-in-out; box-shadow: 0 0 0 3px #fff, 0 0 24px var(--gold); }
@keyframes pulse { to { filter: brightness(1.25); } }
@keyframes hit { 50% { filter: brightness(1.6); } }
@media (hover: hover) { .board-hand-hover .card:hover .lift { transform: translateY(-14%); } }
#board .card[data-id]:not(.down):hover .lift { transform: translateY(-10%); }
.deck-slot, .draw-slot { position: absolute; border: 2px dashed rgba(255, 255, 255, .18); border-radius: 8px; pointer-events: none; }
.deck-label { position: absolute; text-align: center; font-size: 11px; color: rgba(255, 255, 255, .7); pointer-events: none; }
.chips { position: absolute; left: 8px; right: 8px; height: 15px; display: flex; gap: 4px; overflow: hidden; pointer-events: none; z-index: 5; }
.chip { font-size: 10.5px; font-weight: 900; line-height: 15px; padding: 0 7px; border-radius: 8px; background: var(--gold); color: #3a2400; white-space: nowrap; }
.chip.bonus { background: #ffa6d0; } .chip.combo { background: #9be7ff; } .chip.koi { background: #ff9a5c; }

/* 演出 */
.fx { position: absolute; inset: 0; pointer-events: none; z-index: 500; overflow: hidden; }
.spark { position: absolute; width: 8px; height: 8px; margin: -4px; background: hsl(var(--h), 100%, 75%); clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%); animation: spark .75s ease-out forwards; }
@keyframes spark { to { transform: translate(var(--dx), var(--dy)) scale(1.8) rotate(180deg); opacity: 0; } }
.banner { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); text-align: center; animation: banner 1.7s cubic-bezier(.2, .9, .3, 1) forwards; width: 100%; }
.banner .bt { font-family: var(--mincho); font-weight: 800; font-size: clamp(38px, 11vw, 78px); letter-spacing: .1em; color: #fff; text-shadow: 0 0 22px var(--pink), 0 4px 0 #b8326a, 0 0 4px #000; }
.banner .bs { margin-top: 6px; display: inline-block; font-weight: 800; font-size: clamp(14px, 3.6vw, 20px); background: rgba(20, 10, 40, .8); padding: 6px 16px; border-radius: 999px; border: 1px solid var(--gold); color: var(--gold); }
.banner.koi .bt { text-shadow: 0 0 22px #ff9a5c, 0 4px 0 #b4570b, 0 0 4px #000; }
.banner.bloom .bt { text-shadow: 0 0 22px #9be7ff, 0 4px 0 #2f77b0, 0 0 4px #000; }
@keyframes banner { 0% { transform: translate(-50%, -50%) scale(.3); opacity: 0; } 15% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; } 25% { transform: translate(-50%, -50%) scale(1); } 80% { opacity: 1; } 100% { transform: translate(-50%, -62%) scale(1); opacity: 0; } }
.floattext { position: absolute; left: 50%; transform: translateX(-50%); font-weight: 900; font-size: 22px; color: #9be7ff; text-shadow: 0 0 10px #2f77b0, 0 2px 0 #000; animation: floaty 1.4s ease-out forwards; }
@keyframes floaty { to { transform: translate(-50%, -40px); opacity: 0; } }
.toast { position: absolute; left: 50%; top: 34%; transform: translateX(-50%); background: rgba(20, 10, 40, .85); border: 1px solid var(--pink); padding: 8px 18px; border-radius: 999px; font-weight: 700; font-size: 14px; animation: toast 2.2s forwards; white-space: nowrap; }
@keyframes toast { 0%, 100% { opacity: 0; transform: translate(-50%, 6px); } 12%, 80% { opacity: 1; transform: translate(-50%, 0); } }
.toast-global { position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%); background: rgba(20, 10, 40, .92); border: 1px solid var(--line); padding: 10px 18px; border-radius: 999px; z-index: 999; }

/* オーバーレイ */
.overlay { position: absolute; inset: 0; background: rgba(10, 4, 24, .6); display: flex; align-items: center; justify-content: center; z-index: 600; padding: 12px; animation: fade .25s; backdrop-filter: blur(3px); }
@keyframes fade { from { opacity: 0; } }
.dialog { width: min(420px, 96vw); max-height: 94vh; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 24px; padding: 20px; text-align: center; box-shadow: 0 20px 60px rgba(0, 0, 0, .6); animation: pop .35s cubic-bezier(.2, .9, .3, 1.2); }
.dialog.wide { width: min(480px, 96vw); }
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
.dialog h3 { margin: 0 0 8px; font-family: var(--mincho); font-size: 26px; letter-spacing: .1em; }
.dialog .sub { margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.yaku-list { list-style: none; padding: 0; margin: 10px 0; display: grid; gap: 6px; }
.yaku-list li { display: flex; justify-content: space-between; background: rgba(255, 255, 255, .08); border-radius: 10px; padding: 8px 14px; font-weight: 700; animation: slide .4s both; }
.yaku-list li b { color: var(--gold); font-family: var(--mincho); font-size: 18px; }
.yaku-list li.mult { background: rgba(255, 126, 182, .18); }
@keyframes slide { from { transform: translateX(-16px); opacity: 0; } }
.koi-total { font-family: var(--mincho); font-weight: 800; font-size: 30px; margin: 10px 0; }
.koi-total span { color: var(--gold); font-size: 44px; }
.scoreline { display: flex; justify-content: center; gap: 20px; margin: 10px 0 16px; font-weight: 700; }
.scoreline b { font-family: var(--mincho); font-size: 24px; margin-left: 6px; }
.finalboard { display: flex; gap: 12px; margin: 16px 0; }
.finalboard > div { flex: 1; padding: 14px 8px; border-radius: 16px; background: rgba(255, 255, 255, .08); border: 1px solid var(--line); }
.finalboard .win { border-color: var(--gold); background: rgba(255, 211, 107, .15); box-shadow: 0 0 24px rgba(255, 211, 107, .35); }
.finalboard .big { font-family: var(--mincho); font-weight: 800; font-size: 44px; }
.rules { width: min(560px, 96vw); text-align: left; }
.rules h3 { text-align: center; }
.rules-body { max-height: 62vh; overflow: auto; padding-right: 6px; font-size: 14px; line-height: 1.7; }
.rules-body h4 { margin: 14px 0 4px; color: var(--pink); }
.rules-body p { margin: 4px 0; } .rules-body ul { margin: 4px 0; padding-left: 20px; }
.ytable { width: 100%; border-collapse: collapse; font-size: 13px; }
.ytable td { border-bottom: 1px solid var(--line); padding: 5px 4px; } .ytable td:last-child { text-align: right; color: var(--gold); white-space: nowrap; }
.rules .btn { display: block; margin: 14px auto 0; }
#ov-rules { z-index: 700; }

@media (max-width: 520px) { .mid { min-width: 70px; } .score { font-size: 22px; } .pi b { max-width: 5.5em; } }
@media (prefers-reduced-motion: reduce) { .petal { display: none; } }

/* キャラクター: タイトルのアイコン列・立ち絵、紹介ダイアログ */
.cast { position: relative; z-index: 1; margin-top: 3vh; width: min(380px, 94vw); text-align: center; }
.cast-label { margin: 0 0 6px; font-size: 12px; letter-spacing: .3em; color: var(--muted); }
.cast-icons { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.cast-ic { width: 44px; height: 44px; padding: 0; border-radius: 50%; border: 2px solid var(--line); background: #2a1646; overflow: hidden; cursor: pointer; transition: transform .12s, border-color .2s; }
.cast-ic img { width: 100%; height: 100%; display: block; object-fit: cover; pointer-events: none; }
.cast-ic:hover, .cast-ic:focus-visible { transform: scale(1.12); border-color: var(--gold); outline: none; }
.feature { display: none; }
@media (min-width: 1100px) and (min-height: 620px) {
  .feature { display: block; position: absolute; right: 6vw; bottom: 5vh; height: 74vh; aspect-ratio: 410 / 626; padding: 0; border: 3px solid var(--gold); border-radius: 18px; overflow: hidden; background: #2a1646; cursor: pointer; z-index: 1; box-shadow: 0 16px 50px rgba(0, 0, 0, .55); }
  .feature img { width: 100%; height: 100%; display: block; object-fit: cover; transition: opacity .6s; }
  .feature img.out { opacity: 0; }
  .feature span { position: absolute; left: 0; right: 0; bottom: 0; padding: 22px 8px 8px; font-family: var(--mincho); font-weight: 800; letter-spacing: .12em; color: #fff; background: linear-gradient(transparent, rgba(20, 8, 40, .85)); }
}
@media (max-height: 700px) {
  .logo { margin-bottom: 2vh; }
  .logo h1 { font-size: clamp(64px, 18vw, 96px); }
  .menu { gap: 10px; }
  .cast { margin-top: 2vh; }
  .cast-ic { width: 38px; height: 38px; }
}
.avatar[role="button"] { cursor: pointer; }
.avatar[role="button"]:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.charcard { width: min(380px, 94vw); }
.cc-label { margin: 0 0 8px; font-size: 13px; letter-spacing: .2em; color: var(--gold); }
.cc-img { display: block; margin: 0 auto 12px; height: min(40vh, 340px); width: auto; aspect-ratio: 410 / 626; object-fit: cover; border: 3px solid var(--gold); border-radius: 16px; box-shadow: 0 10px 30px rgba(0, 0, 0, .5); background: #2a1646; }
.charcard h3 { margin: 0; }
.cc-read { margin: 0 0 8px; font-size: 13px; color: var(--muted); letter-spacing: .1em; }
.cc-role { margin: 0 0 6px; }
.cc-meta { margin: 0 0 14px; font-size: 13px; color: var(--muted); }
.cc-meta b { color: var(--ink); font-weight: 700; }
@media (max-height: 640px) { .cc-img { height: 30vh; } }
