/* 레이아웃: 휴대폰 세로 한 열(최대 480px) — 위 상태 줄, 가운데 내용, 아래 탭 줄. 카드는 63:88 비율 */
:root {
  --bg: #F3EDE1; --paper: #FFFBF3; --ink: #2A2118; --muted: #76695A; --line: #E2D7C3;
  --gold: #B8892F; --gold-ink: #7D6234; --night: #1C1712; --olive: #5E7A4A; --rose: #B5524A; --sky: #3E6C99;
  --win: #3F7D4E; --lose: #A0473F; --btn-bg: #1C1712; --btn-ink: #FFF6E4;
  --f-display: 'Noto Sans KR', 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif;
  --f-body: 'Noto Sans KR', 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif;
  --f-num: 'Archivo', system-ui, sans-serif;
  --r: 14px; --shadow: 0 6px 18px -8px rgba(42, 33, 24, .35);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #15110D; --paper: #221C16; --ink: #F1E8D6; --muted: #B3A58F; --line: #3A3026;
  --gold: #D4A955; --gold-ink: #E3C27E; --night: #0C0A08; --olive: #8BAA72; --rose: #D9776D; --sky: #7FA6D1;
  --win: #77B686; --lose: #E08A80; --btn-bg: #D4A955; --btn-ink: #0C0A08; --shadow: 0 6px 18px -8px rgba(0, 0, 0, .7); color-scheme: dark; } }
:root[data-theme="dark"] {
  --bg: #15110D; --paper: #221C16; --ink: #F1E8D6; --muted: #B3A58F; --line: #3A3026;
  --gold: #D4A955; --gold-ink: #E3C27E; --night: #0C0A08; --olive: #8BAA72; --rose: #D9776D; --sky: #7FA6D1;
  --win: #77B686; --lose: #E08A80; --btn-bg: #D4A955; --btn-ink: #0C0A08; --shadow: 0 6px 18px -8px rgba(0, 0, 0, .7); color-scheme: dark; }
html.big { font-size: 118%; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 var(--f-body); -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--gold-ink); }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--f-display); font-weight: 800; line-height: 1.2; text-wrap: balance; word-break: keep-all; margin: 0; }
p { margin: 0; word-break: keep-all; }

#app { max-width: 480px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; padding-inline: 16px; padding-block: 12px 96px; gap: 16px; }
.boot { margin: auto; display: grid; place-items: center; gap: 12px; color: var(--muted); }
.boot-card { width: 64px; height: 90px; border-radius: 10px; background: var(--gold); animation: flip 1.2s infinite ease-in-out; }
@keyframes flip { 50% { transform: rotateY(180deg); background: var(--olive); } }

/* 버튼 */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 10px 18px; border-radius: 999px;
  border: 0; background: var(--btn-bg); color: var(--btn-ink); font-family: var(--f-display); font-size: 1.1rem; cursor: pointer; text-decoration: none; }
.btn.gold { background: var(--gold); color: var(--night); }
.btn.line { background: transparent; color: var(--ink); border: 2px solid var(--line); }
.btn.kakao { background: #FEE500; color: #191600; }
.btn.small { min-height: 38px; padding: 6px 14px; font-size: .95rem; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .45; cursor: default; }
.btn:not(:disabled):active { transform: scale(.97); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 2px solid var(--line); background: var(--paper); border-radius: 999px; padding: 6px 14px; cursor: pointer; font-size: .95rem; }
.chip[aria-pressed="true"] { border-color: var(--gold); background: var(--gold); color: var(--night); }
.muted { color: var(--muted); font-size: .9rem; }
.tag { display: inline-block; font-size: .78rem; letter-spacing: .04em; padding: 2px 8px; border-radius: 999px; background: var(--line); color: var(--ink); }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: grid; gap: 12px; }
.stack { display: grid; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 0; }
input[type=text], input[type=tel], input[type=password], input[type=number], input[type=date], select {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--paper); }
label { display: grid; gap: 6px; font-size: .95rem; }
.check { display: flex; gap: 10px; align-items: flex-start; }
.check input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--gold); }

/* 첫 화면 */
.hero { text-align: center; display: grid; gap: 10px; padding-block: 18px 6px; }
.hero h1 { font-size: 2.3rem; letter-spacing: -.01em; }
.hero h1 small { display: block; font-size: 1rem; color: var(--gold-ink); letter-spacing: .3em; margin-bottom: 4px; }
.fan { display: flex; justify-content: center; height: 132px; margin-block: 6px; }
.fan .card { width: 78px; margin-inline: -14px; transform-origin: 50% 120%; }
.fan .card:nth-child(1) { transform: rotate(-16deg); } .fan .card:nth-child(2) { transform: rotate(-6deg) translateY(-6px); }
.fan .card:nth-child(3) { transform: rotate(6deg) translateY(-6px); } .fan .card:nth-child(4) { transform: rotate(16deg); }

/* 상태 줄 */
.top { display: flex; align-items: center; gap: 10px; }
.top .who { flex: 1; min-width: 0; line-height: 1.25; }
.top .who b { font-family: var(--f-display); font-weight: 800; font-size: 1.15rem; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.frag { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--paper); border: 1px solid var(--line); font-family: var(--f-num); font-weight: 800; font-variant-numeric: tabular-nums; }
.frag i { width: 14px; height: 14px; background: var(--gold); transform: rotate(45deg); border-radius: 3px; display: inline-block; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--paper); cursor: pointer; display: grid; place-items: center; }
.icon-btn svg { width: 22px; height: 22px; }

/* 아래 탭 */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; background: var(--paper); border-top: 1px solid var(--line); z-index: 10;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px)); }
.tabs .in { max-width: 480px; margin: 0 auto; display: grid; grid-template-columns: repeat(5, 1fr); }
.tabs button { border: 0; background: none; display: grid; justify-items: center; gap: 2px; padding: 6px 0; font-size: .82rem; color: var(--muted); cursor: pointer; }
.tabs button svg { width: 24px; height: 24px; }
.tabs button[aria-current="page"] { color: var(--ink); font-weight: 700; }
.tabs button[aria-current="page"] svg { color: var(--gold); }

/* 카드 */
.card { position: relative; aspect-ratio: 63 / 88; max-width: 100%; border-radius: 10px; overflow: hidden; background: var(--night);
  box-shadow: var(--shadow); border: 3px solid var(--rc, #8C8273); color: #FFF6E4; text-align: left; padding: 0; cursor: pointer; display: block; width: 100%; }
.card .art { position: absolute; inset: 0; }
.card .art svg, .card .art-img { width: 100%; height: 100%; display: block; object-fit: cover; }
.card .art-fig { position: absolute; left: 50%; bottom: 7%; height: 86%; width: auto; max-width: 96%; transform: translateX(-50%); object-fit: contain; filter: drop-shadow(0 4px 6px rgba(0,0,0,.35)); }
.card .nm { position: absolute; left: 0; right: 0; bottom: 0; padding: 18% 6px 5px; background: linear-gradient(transparent, rgba(12, 9, 6, .88) 45%); }
.card .nm b { font-family: var(--f-display); font-weight: 800; font-size: .95em; display: block; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .st { display: flex; gap: 3px; font-family: var(--f-num); font-weight: 800; font-size: .72em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.card .st span { flex: 1; text-align: center; border-radius: 4px; background: rgba(255, 246, 228, .16); padding: 1px 0; }
.card .st span.on { background: var(--gold); color: #1C1712; }
.card .lv { position: absolute; top: 4px; right: 5px; font-size: .7em; color: #FFD983; text-shadow: 0 1px 2px #000; }
.card .rr { position: absolute; top: 4px; left: 5px; font-size: .62em; padding: 0 5px; border-radius: 6px; background: rgba(20, 16, 12, .88); border: 1px solid var(--rc); color: #FFF6E4; } /* 대비 4.5:1 이상 (W24 검수) */
.card.back { background: var(--night) repeating-linear-gradient(45deg, transparent 0 8px, rgba(184, 137, 47, .18) 8px 9px); border-color: var(--gold); }
.card.back::after { content: ''; position: absolute; inset: 22% 22%; border: 2px solid var(--gold); border-radius: 50%; opacity: .6; }
.card.off { filter: grayscale(1) brightness(.55); }
.card.sel { outline: 4px solid var(--gold); outline-offset: 2px; transform: translateY(-8px); }
.card.in-deck::before { content: '덱'; position: absolute; z-index: 2; bottom: 34%; right: 4px; font-size: .62em; background: var(--gold); color: #1C1712; border-radius: 6px; padding: 0 5px; }
.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; font-size: 13px; }
@media (max-width: 360px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* 카드 상세 (뒤집기) */
.sheet-bg { position: fixed; inset: 0; background: rgba(12, 9, 6, .6); z-index: 20; display: grid; align-items: end; justify-items: center; }
.sheet { width: 100%; max-width: 480px; max-height: 92%; overflow: auto; background: var(--bg); border-radius: 20px 20px 0 0; padding: 18px 16px calc(20px + env(safe-area-inset-bottom, 0px)); display: grid; gap: 14px; animation: up .25s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: .5; } }
.flip { perspective: 900px; width: min(250px, 70vw); margin: 0 auto; font-size: 20px; }
.flip .in { position: relative; aspect-ratio: 63 / 88; transition: transform .6s; transform-style: preserve-3d; }
.flip.turned .in { transform: rotateY(180deg); }
.flip .face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.flip .face.b { transform: rotateY(180deg); background: var(--paper); color: var(--ink); border: 3px solid var(--rc); border-radius: 10px; padding: 16px 14px; display: grid; align-content: start; gap: 10px; font-size: 15px; overflow: auto; }
.flip .face.b h3 { font-size: 1.3rem; }
.abil { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.abil b { font-family: var(--f-display); font-weight: 800; color: var(--gold-ink); font-size: 1.1rem; }
.stats3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stats3 div { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 8px 4px; }
.stats3 b { display: block; font-family: var(--f-num); font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }

/* 홈 */
.cta { background: var(--night); color: #FFF6E4; border-radius: 20px; padding: 20px; display: grid; gap: 14px; position: relative; overflow: hidden; }
.cta::after { content: ''; position: absolute; right: -40px; top: -40px; width: 160px; height: 160px; border-radius: 50%; border: 2px dashed rgba(212, 169, 85, .4); }
.cta h2 { font-size: 1.7rem; }
.cta p { color: #D9CDB5; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mode { text-align: left; border: 1px solid var(--line); background: var(--paper); color: var(--ink); border-radius: var(--r); padding: 14px; cursor: pointer; display: grid; gap: 4px; min-height: 96px; }
.mode b { font-family: var(--f-display); font-weight: 800; font-size: 1.15rem; }
.mode span { font-size: .85rem; color: var(--muted); }
.meter { height: 10px; border-radius: 999px; background: var(--line); overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--gold); border-radius: inherit; }
.sec-h { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.sec-h h2 { font-size: 1.35rem; }

/* 퀴즈 */
.q { font-family: var(--f-display); font-size: 1.35rem; line-height: 1.35; }
.opts { display: grid; gap: 10px; }
.opt { min-height: 54px; text-align: left; padding: 12px 16px; border-radius: 14px; border: 2px solid var(--line); background: var(--paper); cursor: pointer; font-size: 1.05rem; display: flex; gap: 10px; align-items: center; }
.opt::before { content: attr(data-k); font-family: var(--f-num); font-weight: 800; color: var(--gold-ink); width: 1.2em; }
.opt.right { border-color: var(--win); background: color-mix(in srgb, var(--win) 14%, var(--paper)); }
.opt.wrong { border-color: var(--lose); background: color-mix(in srgb, var(--lose) 12%, var(--paper)); }
.streak { display: flex; gap: 6px; }
.streak i { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--gold); }
.streak i.on { background: var(--gold); }
table.odds { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.odds td, table.odds th { padding: 8px; border-bottom: 1px solid var(--line); text-align: left; }
table.odds td:last-child, table.odds th:last-child { text-align: right; }

/* 대결 */
.battle { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.battle > * { min-width: 0; }
.side { display: flex; align-items: center; gap: 10px; }
.side .nm { flex: 1; min-width: 0; line-height: 1.25; }
.side .nm b { font-family: var(--f-display); font-weight: 800; font-size: 1.05rem; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pips { display: flex; gap: 5px; }
.pips i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--gold); }
.pips i.on { background: var(--gold); }
.minibacks { display: flex; gap: 3px; }
.minibacks i { width: 14px; height: 20px; border-radius: 3px; background: var(--night); border: 1px solid var(--gold); }
.topic { background: var(--night); color: #FFF6E4; border-radius: 16px; padding: 12px 16px; display: flex; align-items: center; gap: 12px; }
.topic .t { font-family: var(--f-display); font-size: 1.6rem; flex: 1; }
.topic .r { font-family: var(--f-num); font-weight: 800; color: #E3C27E; font-variant-numeric: tabular-nums; }
.timer { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.timer i { display: block; height: 100%; background: var(--gold); transform-origin: left; }
.arena { display: grid; grid-template-columns: minmax(0, 132px) auto minmax(0, 132px); justify-content: center; gap: 10px; align-items: center; font-size: 15px; }
.slot { aspect-ratio: 63 / 88; border-radius: 10px; border: 2px dashed var(--line); display: grid; place-items: center; color: var(--muted); font-size: .85rem; text-align: center; padding: 6px; }
.vs { font-family: var(--f-num); font-weight: 800; font-size: 1.1rem; color: var(--muted); display: grid; gap: 4px; justify-items: center; }
.vs b { font-size: 1.9rem; color: var(--ink); font-variant-numeric: tabular-nums; }
.winmark { outline: 4px solid var(--win); outline-offset: 2px; }
.hand { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; font-size: 11px; }
.evs { display: grid; gap: 6px; }
.ev { background: var(--paper); border-left: 4px solid var(--gold); border-radius: 8px; padding: 6px 10px; font-size: .92rem; animation: up .3s ease-out; }
.cheers { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.cheer-pop { position: fixed; left: 50%; top: 18%; transform: translateX(-50%); background: var(--night); color: #FFF6E4; padding: 10px 18px; border-radius: 999px; font-family: var(--f-display); z-index: 30; animation: up .3s ease-out; }
.result { text-align: center; display: grid; gap: 10px; }
.result h2 { font-size: 2.2rem; }
.overlay { position: fixed; inset: 0; z-index: 25; background: rgba(12, 9, 6, .72); display: grid; place-items: center; padding: 16px; }
.overlay .box { width: 100%; max-width: 440px; background: var(--bg); border-radius: 20px; padding: 18px; display: grid; gap: 12px; }

/* 순위 */
.rank { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.rank td { padding: 10px 6px; border-bottom: 1px solid var(--line); }
.rank td:first-child { width: 2.2em; font-family: var(--f-num); font-weight: 800; color: var(--gold-ink); }
.rank td:last-child { text-align: right; font-family: var(--f-num); font-weight: 800; }
.rank tr.me td { background: color-mix(in srgb, var(--gold) 16%, transparent); }
.bar { height: 6px; border-radius: 999px; background: var(--gold); margin-top: 4px; }

#toast { position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); max-width: 90%; z-index: 40; pointer-events: none; }
#toast div { background: var(--night); color: #FFF6E4; padding: 10px 16px; border-radius: 12px; margin-top: 6px; animation: up .25s ease-out; box-shadow: var(--shadow); }

/* 시작 카드 연출 */
.deal { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; font-size: 11px; perspective: 800px; }
.deal .flip { width: 100%; font-size: 11px; }
.deal .flip .in { transition-duration: .7s; }

/* 수 싸움: 상대가 아직 안 낸 카드 · 주제 고르기 */
.small { font-size: .82rem; }
.lchips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.lchip { flex: none; border: 1px solid var(--line); background: var(--paper); border-radius: 10px; padding: 4px 8px; font-size: .8rem; cursor: pointer; display: grid; gap: 2px; text-align: center; color: var(--ink); }
.lchip span { display: flex; gap: 3px; justify-content: center; font-family: var(--f-num); font-weight: 800; font-variant-numeric: tabular-nums; }
.lchip i { font-style: normal; min-width: 1.3em; border-radius: 4px; color: var(--muted); }
.lchip i.on { background: var(--gold); color: #1C1712; }
.topic-btn { display: grid; gap: 2px; text-align: left; min-height: 64px; padding: 12px 16px; border-radius: 14px; border: 2px solid var(--line); background: var(--paper); color: var(--ink); cursor: pointer; }
.topic-btn b { font-family: var(--f-display); font-weight: 800; font-size: 1.4rem; }
.topic-btn span { font-size: .9rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.topic-btn:not(:disabled):hover, .topic-btn:focus-visible { border-color: var(--gold); }
.overlay.soft { background: rgba(12, 9, 6, .35); align-items: start; padding-top: 30vh; }
.opt.picked { border-color: var(--gold); }
/* 공개 연출: 상대 카드 뒤집기 → 점수 올라감 → 특수 능력 차례로 → 판 결과 */
.drop-in { animation: drop .35s cubic-bezier(.2, .9, .3, 1.3) both; }
@keyframes drop { from { transform: translateY(-24px) scale(.9); opacity: 0; } }
.reveal-in { animation: turn .55s ease-out both; }
@keyframes turn { from { transform: perspective(600px) rotateY(90deg); filter: brightness(2); } }
.winmark { animation: glow 1.4s ease-in-out .9s 2 both; }
@keyframes glow { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--win) 45%, transparent), var(--shadow); transform: scale(1.04); } }
.ev.stg { animation: up .35s ease-out both; }
.verdict.w { border-color: var(--win); } .verdict.l { border-color: var(--lose); } .verdict.d { border-color: var(--line); }
.vs .count { display: inline-block; min-width: 1.4em; }
.result h2.won { animation: pop .6s cubic-bezier(.2, .9, .3, 1.4) both; color: var(--gold-ink); }
@keyframes pop { from { transform: scale(.4); opacity: 0; } }
.fb { display: grid; gap: 6px; }

/* 미션 · 친구 · 따라하기 */
.missions { display: grid; gap: 10px; }
.mission { display: flex; gap: 10px; align-items: center; }
.mission .grow { flex: 1; min-width: 0; }
.mission .meter { margin-top: 6px; height: 8px; }
.mission.done { opacity: .6; }
.friend { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.friend .grow { display: grid; min-width: 0; }
.tutor { border: 2px solid var(--gold); }
.coach { background: var(--paper); border: 2px dashed var(--gold); border-radius: 14px; padding: 10px 14px; font-size: .98rem; animation: up .3s ease-out both; }
details summary { cursor: pointer; padding: 6px 0; }

html.calm *, html.calm *::before, html.calm *::after { animation: none !important; transition: none !important; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
