@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+JP:wght@700;900&family=Zen+Maru+Gothic:wght@500;700;900&display=swap');

:root {
  --bg: #080c1a;
  --panel: rgba(16, 23, 46, 0.92);
  --panel-soft: rgba(26, 36, 70, 0.9);
  --ink: #f5f2e8;
  --muted: #93a3c7;
  --gold: #f2be4a;
  --gold-hi: #ffe89e;
  --shu: #ff4f64;
  --jade: #38d99c;
  --cyan: #57d8ff;
  --violet: #b67cff;
  --logic: #5b8def;
  --lit: #3fa77b;
  --yoji: #ef5b56;
  --idiom: #e8a735;
  --culture: #a674e8;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; user-select: none; }
button, .tree-card, .stage-card, .sp-slot, .k-card, .f-chip { touch-action: manipulation; }
html, body {
  margin: 0; padding: 0;
  background: #050811;
  color: var(--ink);
  font-family: 'Zen Maru Gothic', 'Hiragino Maru Gothic ProN', 'Yu Gothic', sans-serif;
  min-height: 100dvh; overflow: hidden;
}
body { display: flex; justify-content: center; }

.shell {
  width: 100%; max-width: 420px; height: 100dvh;
  position: relative; display: flex; flex-direction: column;
  background: #0a1024; overflow: hidden;
  box-shadow: 0 0 40px rgba(0,0,0,0.85);
}

/* ---- Top Currency Header (Hidden during Battle) ---- */
.top-hud {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding: calc(8px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) 6px calc(10px + env(safe-area-inset-left));
  background: rgba(7, 11, 24, 0.92);
  border-bottom: 1px solid rgba(255,232,158,0.16); z-index: 15; flex-shrink: 0;
}
.cur-group { display: flex; align-items: center; gap: 6px; }
.cur-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 999px;
  background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.14);
  font-size: 11.5px; font-weight: 900; font-variant-numeric: tabular-nums;
}
.cur-pill.gem { border-color: rgba(87,216,255,0.4); color: var(--cyan); }
.cur-pill.tome { border-color: rgba(242,190,74,0.45); color: var(--gold-hi); }
.cur-pill.lamp { border-color: rgba(56,217,156,0.4); color: var(--jade); }
.icon-btn {
  width: 30px; height: 30px; border-radius: 9px;
  background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.16);
  color: var(--ink); font-size: 13px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

/* ---- Authored SVG icon sprite ---- */
.ic { width: 1.15em; height: 1.15em; display: inline-block; vertical-align: -0.2em; flex-shrink: 0; }
.cur-pill .ic { width: 15px; height: 15px; }
.nav-btn .ic { width: 22px; height: 22px; }
.icon-btn .ic { width: 18px; height: 18px; }
.mini-btn .ic, .f-chip .ic { width: 1.1em; height: 1.1em; }
.ic-gem { color: var(--cyan); }
.ic-tome, .ic-lamp, .ic-star, .ic-star-empty, .ic-crown { color: var(--gold-hi); }
.ic-heart, .ic-tree { color: var(--jade); }
.ic-warning { color: var(--gold); }
.ic-summon, .ic-spirit { color: var(--violet); }
.sk-cut, .sk-flame { color: var(--shu); }
.sk-shield { color: var(--jade); }
.sk-hourglass { color: var(--cyan); }
.sk-bolt { color: var(--gold-hi); }
.big-cta .ic, .mini-btn.gold .ic, .attr-chip .ic, .dmg-pop .ic { color: inherit; }
.sp-sk .ic { width: 12px; height: 12px; margin-right: 1px; }
.buff-chips .ic { width: 13px; height: 13px; }
.toast .ic { width: 14px; height: 14px; }
.toast-ico { display: inline-flex; align-items: center; }

/* ---- Screen-reader-only text ---- */
.sr-only {
  position: absolute !important; width: 1px !important; height: 1px !important;
  padding: 0 !important; margin: -1px !important; overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important;
}

/* ---- Browser surfaces ---- */
::selection { background: rgba(242,190,74,.35); color: #fff; }
:focus-visible { outline: 2px solid var(--gold-hi); outline-offset: 2px; }
.screen, .modal-card, #resWords {
  scrollbar-width: thin;
  scrollbar-color: rgba(255,232,158,.35) transparent;
}
.screen::-webkit-scrollbar, .modal-card::-webkit-scrollbar, #resWords::-webkit-scrollbar { width: 6px; height: 6px; }
.screen::-webkit-scrollbar-track, .modal-card::-webkit-scrollbar-track, #resWords::-webkit-scrollbar-track { background: transparent; }
.screen::-webkit-scrollbar-thumb, .modal-card::-webkit-scrollbar-thumb, #resWords::-webkit-scrollbar-thumb {
  background: rgba(255,232,158,.35); border-radius: 999px;
}

/* ---- Main Screen Area ---- */
.screen {
  flex: 1; display: none; flex-direction: column; overflow-y: auto; position: relative;
  padding: 10px 12px 14px; gap: 10px;
}
.screen.active { display: flex; }

/* ---- Bottom Tab Navigation ---- */
.nav-bar {
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(7, 11, 24, 0.96);
  border-top: 1px solid rgba(255,232,158,0.18);
  padding: 4px calc(4px + env(safe-area-inset-right)) calc(7px + env(safe-area-inset-bottom)) calc(4px + env(safe-area-inset-left));
  flex-shrink: 0; z-index: 15;
}
.nav-btn {
  background: transparent; border: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 4px 2px; border-radius: 10px; cursor: pointer;
  font-size: 11px; font-weight: 900; transition: color .15s, background .15s;
}
.nav-btn .ni { height: 22px; display: flex; align-items: center; justify-content: center; line-height: 1; }
.nav-btn.active { color: var(--gold-hi); background: rgba(242,190,74,0.14); }

/* ---- HOME SCREEN ---- */
#scrHome {
  background: linear-gradient(180deg, rgba(8,12,26,0.38), rgba(8,12,26,0.92) 72%),
              url('../assets/img/bg_grand_library.webp') center/cover no-repeat;
  justify-content: space-between;
  overflow-x: hidden;
}
.home-hero {
  position: relative; display: flex; flex-direction: column; align-items: center;
  /* Tall phones: the party fills the free space instead of leaving a dead band. */
  flex: 1 1 auto; justify-content: center;
  padding-top: 6px; gap: 10px;
}
.speech-bubble {
  background: rgba(10,16,34,0.88); border: 1.4px solid rgba(255,232,158,0.5);
  border-radius: 14px; padding: 7px 13px; font-size: 12px; font-weight: 700;
  color: var(--ink); max-width: 92%; text-align: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
.home-party-stage {
  /* Height follows the free vertical space (tall phones) but never gets wider than
     the column: lead + two 0.62x sides overlapping by 0.18x lead = 1.88x lead. */
  --stage-h: 148px;
  --stage-h: min(clamp(148px, calc(100vh - 520px), 280px), calc((min(100vw, 420px) - 24px) / 1.9 + 10px));
  --stage-h: min(clamp(148px, calc(100dvh - 520px), 280px), calc((min(100vw, 420px) - 24px) / 1.9 + 10px));
  display: flex; align-items: flex-end; justify-content: center; gap: 2px;
  height: var(--stage-h); width: 100%; position: relative;
}
.home-sp {
  object-fit: contain; filter: drop-shadow(0 8px 14px rgba(0,0,0,0.7));
  animation: floatBob 2.6s ease-in-out infinite alternate;
}
.home-sp.lead { height: calc(var(--stage-h) - 10px); z-index: 3; }
.home-sp.side { height: calc((var(--stage-h) - 10px) * 0.62); opacity: 0.92; animation-delay: .4s; z-index: 2; }
.home-sp.side:first-child { margin-right: calc((var(--stage-h) - 10px) * -0.18); }
.home-sp.side:last-child { margin-left: calc((var(--stage-h) - 10px) * -0.18); }
@keyframes floatBob { from{transform:translateY(0)} to{transform:translateY(-6px)} }

.tree-card {
  display: flex; align-items: center; gap: 10px;
  background: linear-gradient(135deg, rgba(22,42,58,0.92), rgba(14,22,44,0.94));
  border: 1.5px solid rgba(56,217,156,0.45); border-radius: 16px;
  padding: 9px 12px; cursor: pointer; position: relative; overflow: hidden;
  transition: transform .1s;
}
button.tree-card, button.stage-card, button.sp-slot {
  width: 100%; margin: 0; text-align: left; font-family: inherit; color: inherit;
  -webkit-appearance: none; appearance: none;
}
button.tree-card:disabled { cursor: default; }
.tree-card:active { transform: scale(0.98); }
.tree-card.ready { border-color: var(--gold-hi); box-shadow: 0 0 18px rgba(242,190,74,0.3); }
.tree-icon { width: 52px; height: 52px; object-fit: contain; flex-shrink: 0; }
.tree-meta { flex: 1; }
.tree-title { display: block; font-size: 13px; font-weight: 900; color: var(--gold-hi); }
.tree-sub { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.tree-btn {
  padding: 6px 11px; border-radius: 10px; font-size: 11.5px; font-weight: 900;
  background: linear-gradient(180deg, #ffe694, #e2a22b); color: #15192a;
}
.tree-card:not(.ready) .tree-btn { background: rgba(255,255,255,0.1); color: var(--muted); }

.big-cta {
  width: 100%; height: 54px; border-radius: 16px; border: none;
  background: linear-gradient(180deg, #ffe694 0%, #e8a427 100%);
  color: #161a2c; font-family: 'Noto Serif JP', serif; font-weight: 900; font-size: 18px;
  letter-spacing: 0.08em; cursor: pointer;
  box-shadow: 0 6px 22px rgba(242,190,74,0.38);
}
.big-cta:active { transform: scale(0.98); }
.big-cta:disabled { opacity: 0.55; cursor: default; box-shadow: none; }
.big-cta:disabled:active { transform: none; }

/* ---- QUEST MAP SCREEN ---- */
.sec-title { font-family: 'Noto Serif JP', serif; font-size: 16px; font-weight: 900; color: var(--gold-hi); }
.stage-list { display: flex; flex-direction: column; gap: 8px; }
.stage-card {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 16px;
  background: linear-gradient(135deg, rgba(25,36,72,0.92), rgba(14,20,42,0.96));
  border: 1.5px solid rgba(255,255,255,0.16); cursor: pointer;
  transition: transform .1s, border-color .15s;
}
.stage-card:active { transform: scale(0.98); }
.stage-card.locked { opacity: 0.45; pointer-events: none; }
.stage-card:disabled { cursor: default; }
.stage-card:disabled:active { transform: none; }
.stage-card.next-up { border-color: var(--gold-hi); box-shadow: 0 0 16px rgba(242,190,74,0.25); }
.st-boss-img { width: 52px; height: 52px; object-fit: contain; flex-shrink: 0; filter: drop-shadow(0 4px 8px rgba(0,0,0,0.6)); }
.st-info { flex: 1; min-width: 0; }
.st-name { display: block; font-family: 'Noto Serif JP', serif; font-size: 15px; font-weight: 900; color: #fff; }
.st-tags { display: flex; align-items: center; gap: 6px; margin-top: 4px; font-size: 11px; font-weight: 900; }
.attr-chip { padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 900; color: #0a0f20; }
.st-stars { font-size: 13px; color: var(--gold-hi); display: inline-flex; align-items: center; gap: 2px; }
.st-stars .ic { width: 14px; height: 14px; }

/* ---- BATTLE SCREEN (Full RPG + Kirikaruta!) ---- */
#scrBattle {
  padding: calc(7px + env(safe-area-inset-top)) 10px calc(9px + env(safe-area-inset-bottom)); gap: 5px;
  overflow-x: hidden; overflow-y: auto; /* safety net on short viewports */
  background: linear-gradient(180deg, rgba(8,12,26,0.45), rgba(8,12,26,0.93) 62%),
              url('../assets/img/bg_battle_sanctum.webp') center top/cover no-repeat;
}
.bt-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; z-index: 5; }
.wave-badge {
  font-size: 11px; font-weight: 900; padding: 3px 9px; border-radius: 999px;
  background: rgba(8,12,26,0.82); border: 1px solid rgba(255,232,158,0.4); color: var(--gold-hi);
}
.wave-badge.boss { border-color: var(--shu); color: #ff99a4; }
.cd-pill {
  font-size: 11px; font-weight: 900; padding: 3px 9px; border-radius: 999px;
  background: rgba(8,12,26,0.84); border: 1px solid rgba(255,255,255,0.2); color: #fff;
}
.cd-pill.danger { border-color: var(--shu); color: #ff94a0; animation: pulse .7s infinite alternate; }
@keyframes pulse { from{transform:scale(1)} to{transform:scale(1.07)} }

.bt-arena {
  position: relative; display: flex; flex-direction: column; align-items: center;
  padding: 2px 4px 4px; gap: 4px; flex-shrink: 0;
}
.bt-arena.shake-hit { animation: shakeH .24s ease-out; }
.bt-arena.shake-miss { animation: shakeM .3s ease-out; }
@keyframes shakeH { 0%,100%{transform:translate(0,0)} 25%{transform:translate(-8px,4px)} 55%{transform:translate(8px,-3px)} }
@keyframes shakeM { 0%,100%{transform:translate(0,0)} 25%{transform:translate(-9px,0)} 55%{transform:translate(9px,0)} }

.bt-enemy-box {
  /* 86px on short screens; on taller ones the enemy takes the band that used to
     sit empty between the party row and the cards (~32px stays as breathing room). */
  --enemy-h: 86px;
  --enemy-h: clamp(86px, calc(100vh - 520px), 230px);
  --enemy-h: clamp(86px, calc(100dvh - 520px), 230px);
  position: relative; height: var(--enemy-h); display: flex; align-items: center; justify-content: center;
}
.bt-enemy-img {
  height: calc(var(--enemy-h) - 2px); width: auto; max-width: 100%; object-fit: contain;
  filter: drop-shadow(0 6px 14px rgba(0,0,0,0.7));
  animation: floatBob 2.2s ease-in-out infinite alternate;
  transition: transform .08s, filter .12s, opacity .25s;
}
/* No src until the first battle HUD render: never show a broken-image box. */
.bt-enemy-img:not([src]) { visibility: hidden; }
.bt-enemy-img.slashed { transform: scale(0.84, 1.12) !important; filter: brightness(2.2) drop-shadow(0 0 22px var(--gold-hi)); }
.bt-enemy-img.dying { transform: scale(0.45) !important; opacity: 0; }
.slash-svg {
  position: absolute; inset: -14px -52px; width: calc(100% + 104px); height: calc(100% + 28px);
  pointer-events: none; z-index: 10; opacity: 0;
}
.slash-svg.fire { animation: slashF .3s cubic-bezier(.12,.9,.28,1) forwards; }
@keyframes slashF { 0%{opacity:0;transform:scale(0.75)} 20%{opacity:1;transform:scale(1.06)} 100%{opacity:0;transform:scale(1.12)} }

.enemy-hp-wrap { width: 100%; display: flex; flex-direction: column; gap: 2px; }
.hp-head { display: flex; justify-content: space-between; font-size: 11px; font-weight: 900; }
.bar-track { position: relative; height: 8px; border-radius: 999px; background: rgba(255,255,255,0.14); overflow: hidden; }
.bar-ghost { position: absolute; inset: 0 auto 0 0; background: rgba(255,232,158,0.75); transition: width .46s ease-out; }
.bar-fill { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, #df3649, #ff707d); transition: width .14s ease-out; }
.bar-fill.player { background: linear-gradient(90deg, #169c6c, #49e8aa); }

/* Sand Meaning Line (18sp verbatim, right-edge crumble!) */
.meaning-panel {
  position: relative; width: 100%; min-height: 70px;
  background: rgba(9, 14, 30, 0.86); border: 1.4px solid rgba(255,232,158,0.34);
  border-radius: 14px; padding: 8px 11px;
  display: flex; align-items: center; justify-content: center;
  transition: border-color .15s, box-shadow .15s;
}
.meaning-panel.frozen { border-color: var(--cyan); box-shadow: 0 0 18px rgba(87,216,255,0.38); }
.meaning-line {
  font-family: 'Noto Serif JP', serif; font-weight: 700; font-size: 17px;
  line-height: 1.44; color: var(--ink); width: 100%; word-break: break-all;
}
.meaning-line.clarified { color: #fffef5 !important; text-shadow: 0 0 14px rgba(255,232,158,0.75); }
.m-ch { transition: opacity .15s linear, color .12s linear; }
.m-ch.crumbling { opacity: 0.36; color: #cbb98a; }
.m-ch.gone { opacity: 0.06; color: #6b5f47; }
.m-ch.shu { color: var(--shu) !important; text-shadow: 0 0 10px rgba(255,79,100,0.9); }

/* Party 3 Spirits Strip (RPG Combat Heart!) */
.party-strip { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; flex-shrink: 0; }
.sp-slot {
  position: relative; display: flex; align-items: center; gap: 5px; min-width: 0;
  padding: 5px 6px; border-radius: 12px;
  background: linear-gradient(180deg, rgba(28,39,76,0.92), rgba(14,20,40,0.96));
  border: 1.5px solid rgba(255,255,255,0.16); cursor: pointer;
  transition: transform .12s, border-color .18s, box-shadow .18s;
}
.sp-slot.ready {
  border-color: var(--gold-hi);
  box-shadow: 0 0 14px rgba(255,232,158,0.45);
  background: linear-gradient(180deg, rgba(242,190,74,0.28), rgba(18,26,54,0.96));
  animation: spPulse 1.1s ease-in-out infinite alternate;
}
@keyframes spPulse { from{transform:scale(1)} to{transform:scale(1.03)} }
.sp-slot.lunge { transform: translateY(-10px) scale(1.08) !important; border-color: #fff !important; }
.sp-av { width: 34px; height: 34px; object-fit: contain; flex-shrink: 0; }
.sp-meta { flex: 1; min-width: 0; }
.sp-sk { display: block; font-size: 11px; font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink); }
.sp-slot.ready .sp-sk { color: var(--gold-hi); }
.sp-bar { display: block; height: 5px; border-radius: 999px; background: rgba(0,0,0,0.5); margin-top: 3px; overflow: hidden; }
.sp-bar-fill { height: 100%; border-radius: 999px; transition: width .2s; }
.sp-attr-dot { position: absolute; top: 3px; left: 4px; width: 7px; height: 7px; border-radius: 50%; }

/* Player HP + Active Buff Chips */
.player-bar-row {
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
  background: rgba(9,14,30,0.82); border-radius: 10px; padding: 4px 8px;
}
.buff-chips { display: flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 900; }

/* 5 Vertical Karuta Cards (Single-Line Fixed!) */
.cards-col {
  display: flex; flex-direction: column; gap: 5px; margin-top: auto; flex-shrink: 0;
}
.k-card {
  width: 100%; height: 48px; padding: 0 10px; border-radius: 12px;
  background: linear-gradient(180deg, #212c4f 0%, #141c36 100%);
  border: 1.5px solid rgba(235,224,198,0.22);
  color: var(--ink); font-family: 'Noto Serif JP', serif; font-weight: 900;
  font-size: 17.5px; line-height: 1; white-space: nowrap; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: transform .08s, opacity .15s, border-color .12s;
}
.k-card:active { transform: scale(0.975); }
.k-card:disabled { cursor: default; }
.k-card:disabled:active { transform: none; }
.k-card.cut { opacity: 0.12; pointer-events: none; transform: scale(0.94); text-decoration: line-through; }
.k-card.hit-ok { border-color: var(--gold-hi) !important; background: linear-gradient(180deg, rgba(242,190,74,0.34), #1f2848) !important; box-shadow: 0 0 20px rgba(255,232,158,0.6); }
.k-card.hit-ng { border-color: var(--shu) !important; background: #3b1726 !important; color: #ff9ca6; }
.k-card.reveal-ok { border-color: var(--gold-hi) !important; box-shadow: 0 0 14px rgba(255,232,158,0.45); }
.k-card.dim { opacity: 0.28; pointer-events: none; }

/* Damage Pop & Bridge Overlay */
.fx-layer { position: absolute; inset: 0; pointer-events: none; z-index: 18; overflow: hidden; }
.dmg-pop {
  position: absolute; left: 50%; top: 18%;
  font-family: 'Zen Maru Gothic', sans-serif; font-weight: 900;
  text-shadow: 0 3px 10px #000, 0 0 12px #000;
  animation: popUp .95s cubic-bezier(.16,.84,.44,1) forwards;
  text-align: center; white-space: nowrap;
}
@keyframes popUp {
  0%{opacity:0;transform:translate(calc(-50% + var(--dx)),0) scale(0.6)}
  20%{opacity:1;transform:translate(calc(-50% + var(--dx)),-38px) scale(1.22)}
  80%{opacity:1;transform:translate(calc(-50% + var(--dx)),-68px) scale(1)}
  100%{opacity:0;transform:translate(calc(-50% + var(--dx)),-88px) scale(0.95)}
}

.bridge-pop {
  position: absolute; left: 14px; right: 14px; top: 44%; transform: translateY(-50%) scale(0.92);
  border-radius: 16px; background: rgba(10,14,28,0.96); border: 1.8px solid var(--gold-hi);
  padding: 11px 13px; text-align: center; z-index: 22; opacity: 0; pointer-events: none;
  transition: opacity .1s, transform .1s;
  box-shadow: 0 10px 30px rgba(0,0,0,0.85);
}
.bridge-pop.show { opacity: 1; transform: translateY(-50%) scale(1); }
.bridge-pop.miss { border-color: var(--shu); }
.bp-word { font-family: 'Noto Serif JP', serif; font-size: 24px; font-weight: 900; color: #fff; }
.bp-read { font-size: 11.5px; color: var(--gold-hi); font-weight: 700; }
.bp-mean { font-size: 12px; color: var(--ink); margin-top: 4px; line-height: 1.4; }
.bp-bridge { margin-top: 7px; padding-top: 6px; border-top: 1px solid rgba(255,255,255,0.12); font-size: 12px; font-weight: 900; color: var(--cyan); }

/* ---- SPIRITS / PARTY SCREEN ---- */
.party-bar {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px;
  background: rgba(16,23,46,0.92); border: 1.4px solid rgba(255,232,158,0.35);
  border-radius: 16px; padding: 8px;
}
.p-slot {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: rgba(255,255,255,0.05); border-radius: 12px; padding: 6px 4px; text-align: center;
}
.p-slot img { width: 52px; height: 52px; object-fit: contain; }
.roster-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; }
.sp-card {
  display: flex; flex-direction: column; gap: 5px;
  background: linear-gradient(180deg, rgba(26,36,70,0.92), rgba(14,20,42,0.96));
  border: 1.5px solid rgba(255,255,255,0.15); border-radius: 14px; padding: 8px;
}
.sp-card.in-party { border-color: var(--gold-hi); box-shadow: inset 0 0 0 1px rgba(242,190,74,0.35); }
.sp-card-top { display: flex; align-items: center; gap: 7px; }
.sp-card-top img { width: 46px; height: 46px; object-fit: contain; flex-shrink: 0; }
.rar-badge { font-size: 11px; font-weight: 900; padding: 1px 5px; border-radius: 5px; display: inline-block; }
.rar-SSR { background: linear-gradient(90deg, #ff7eb3, #ffe694, #57d8ff); color: #121628; }
.rar-SR { background: var(--gold); color: #121628; }
.rar-R { background: #6b7fa8; color: #fff; }
.mini-btn {
  flex: 1; height: 28px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.09); color: #fff; font-size: 11px; font-weight: 900; cursor: pointer;
}
.mini-btn.gold { background: linear-gradient(180deg, #ffe694, #e2a22b); color: #161a2c; border: none; }
.mini-btn:disabled { opacity: 0.45; cursor: default; }

/* ---- GACHA SCREEN ---- */
.gacha-banner {
  border-radius: 18px; padding: 14px; text-align: center;
  background: radial-gradient(circle at 50% 25%, rgba(182,124,255,0.34), rgba(24,32,68,0.95) 68%);
  border: 1.6px solid rgba(255,232,158,0.55); display: flex; flex-direction: column; gap: 8px;
}
.gacha-showcase { display: flex; justify-content: center; gap: 6px; height: 108px; align-items: flex-end; }
.gacha-showcase img { height: 96px; object-fit: contain; filter: drop-shadow(0 6px 14px rgba(0,0,0,0.7)); }
.gacha-results { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; }
.g-pull-card {
  display: flex; align-items: center; gap: 7px; padding: 7px 8px; border-radius: 12px;
  background: rgba(16,24,52,0.95); border: 1.5px solid rgba(255,255,255,0.18);
  animation: pullPop .28s cubic-bezier(.22,1.35,.36,1) backwards;
}
.g-pull-card.SSR { border-color: var(--gold-hi); background: linear-gradient(135deg, rgba(242,190,74,0.28), rgba(87,216,255,0.18)); box-shadow: 0 0 16px rgba(255,232,158,0.45); }
.g-pull-card.SR { border-color: #f2be4a; }
.g-pull-card img { width: 42px; height: 42px; object-fit: contain; }
@keyframes pullPop { from{opacity:0;transform:scale(0.7)} to{opacity:1;transform:scale(1)} }

/* ---- DICTIONARY (LAMP SHELF) ---- */
.dict-filters { display: flex; gap: 5px; flex-wrap: wrap; }
.f-chip {
  padding: 4px 9px; border-radius: 999px; font-size: 11px; font-weight: 900;
  background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.15);
  color: var(--muted); cursor: pointer;
}
.f-chip.active { background: rgba(242,190,74,0.22); border-color: var(--gold-hi); color: var(--gold-hi); }
.dict-list { display: flex; flex-direction: column; gap: 6px; }
/* Dictionary list is study material: allow text selection there. */
.dict-list, .dict-list * { user-select: text; -webkit-user-select: text; }
.dict-more { flex: 0 0 auto; width: 100%; height: 36px; }
.dict-row {
  background: rgba(16,24,48,0.88); border-left: 3px solid rgba(255,255,255,0.2);
  border-radius: 10px; padding: 8px 10px; font-size: 11.5px;
}
.dict-row.lit { border-left-color: var(--gold-hi); background: rgba(28,36,68,0.92); }

/* Battle-result words: full subtle border instead of a one-sided bar. */
.res-word {
  background: rgba(255,255,255,0.045); border: 1px solid rgba(255,255,255,0.14);
  border-radius: 10px; padding: 7px 9px; font-size: 11.5px;
}
.res-word.lit { background: rgba(242,190,74,0.10); border-color: rgba(242,190,74,0.30); }
.res-word .res-x { color: var(--shu); font-weight: 900; }
.res-word .res-mean { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ---- MODALS & TOAST ---- */
dialog.modal-bg {
  position: fixed; inset: 0; width: 100%; height: 100dvh;
  max-width: none; max-height: none; margin: 0; padding: 16px;
  border: 0; background: transparent; color: var(--ink);
  display: none; align-items: center; justify-content: center; z-index: 40;
  overflow: hidden;
}
dialog.modal-bg[open] { display: flex; }
dialog.modal-bg::backdrop { background: rgba(5,8,18,0.88); }
/* iOS Safari 15.0–15.3 has no showModal(): the dialog gets [open] + this
   class, and the dialog element itself becomes the full-screen backdrop. */
dialog.modal-bg.modal-fallback-open { background: rgba(5,8,18,0.88); }
.modal-card {
  width: 100%; max-width: 370px; max-height: 86dvh; overflow-y: auto;
  border-radius: 22px; background: linear-gradient(180deg, #1b274d, #0d1328);
  border: 1.6px solid var(--gold-hi); padding: 16px; display: flex; flex-direction: column; gap: 10px;
}
/* Full-width buttons directly inside a modal (column layout): don't let flex:1 collapse them. */
.modal-card > .mini-btn { flex: 0 0 auto; width: 100%; }
#resStars { display: flex; align-items: center; justify-content: center; gap: 4px; }
#resStars .ic { width: 22px; height: 22px; }
.reward-row { display: flex; justify-content: space-around; gap: 8px; }
.rw-box {
  flex: 1; text-align: center; padding: 9px 6px; border-radius: 12px;
  background: rgba(255,255,255,0.07); border: 1px solid rgba(255,232,158,0.3);
}
.toast {
  position: fixed; left: 50%; top: calc(48px + env(safe-area-inset-top)); transform: translateX(-50%);
  display: flex; align-items: center; justify-content: center; gap: 5px;
  background: rgba(10,16,36,0.96); border: 1px solid var(--gold-hi); color: var(--gold-hi);
  padding: 6px 14px; border-radius: 999px; font-size: 11.5px; font-weight: 900; z-index: 50;
  opacity: 0; pointer-events: none; transition: opacity .16s;
  width: max-content; max-width: calc(100vw - 24px); text-align: center; line-height: 1.35;
}
.toast.show { opacity: 1; }

/* ---- Boot error (missing vocabulary data) ---- */
.boot-error {
  position: fixed; inset: 0; z-index: 60; padding: 24px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(5,8,18,0.94);
}
.boot-error[hidden] { display: none; }
.boot-error-card {
  width: 100%; max-width: 340px; border-radius: 20px; padding: 18px;
  background: linear-gradient(180deg, #1b274d, #0d1328);
  border: 1.6px solid var(--shu); display: flex; flex-direction: column; gap: 12px;
  text-align: center;
}
.boot-error-title { font-family: 'Noto Serif JP', serif; font-size: 17px; font-weight: 900; color: #ff9ca6; }
.boot-error-text { font-size: 12px; color: var(--muted); line-height: 1.5; }

/* ---- Single-active-tab blocking overlay ---- */
.tab-overlay {
  /* Above the PWA update banner (pwa.js uses 2147483000) so it cannot be used
     while this tab is blocked. Native dialogs are closed before showing it. */
  position: fixed; inset: 0; z-index: 2147483600;
  display: flex; align-items: center; justify-content: center;
  padding: calc(24px + env(safe-area-inset-top)) 18px calc(24px + env(safe-area-inset-bottom));
  background: rgba(5,8,18,0.94);
}
.tab-overlay[hidden] { display: none; }
.tab-overlay-card {
  width: 100%; max-width: 340px; border-radius: 22px; padding: 22px 18px;
  background: linear-gradient(180deg, #1b274d, #0d1328);
  border: 1.6px solid var(--gold-hi);
  box-shadow: 0 18px 60px rgba(0,0,0,0.65);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  text-align: center;
}
.tab-overlay-icon { color: var(--gold-hi); display: flex; justify-content: center; }
.tab-overlay-icon .ic { width: 38px; height: 38px; }
.tab-overlay-title {
  font-family: 'Noto Serif JP', serif; font-size: 18px; line-height: 1.45;
  font-weight: 900; color: var(--gold-hi);
}
.tab-overlay-text { font-size: 12px; line-height: 1.6; color: var(--muted); }
.tab-overlay-btn { flex: 0 0 auto; width: 100%; height: 46px; font-size: 14px; }

/* Toasts rendered inside an open modal are visible above its top layer. */
.dialog-toast { z-index: 2; }

/* ---- Short battle viewports (iPhone SE 375x667 with Safari bars ~550px tall) ---- */
@media (max-height: 700px) {
  #scrBattle { gap: 4px; padding: calc(4px + env(safe-area-inset-top)) 9px calc(6px + env(safe-area-inset-bottom)); }
  .bt-arena { gap: 2px; padding: 1px 2px 2px; }
  .bt-enemy-box {
    --enemy-h: 74px;
    --enemy-h: clamp(74px, calc(100vh - 480px), 230px);
    --enemy-h: clamp(74px, calc(100dvh - 480px), 230px);
  }
  .meaning-panel { min-height: 58px; padding: 6px 10px; }
  .meaning-line { font-size: 15.5px; line-height: 1.36; }
  .party-strip { gap: 5px; }
  .sp-slot { padding: 4px 5px; gap: 4px; }
  .sp-av { width: 30px; height: 30px; }
  .player-bar-row { padding: 3px 7px; }
  .cards-col { gap: 4px; }
  .k-card { height: 45px; font-size: 17px; }
}

@media (max-height: 600px) {
  #scrBattle { gap: 3px; padding: calc(3px + env(safe-area-inset-top)) 8px calc(4px + env(safe-area-inset-bottom)); }
  .bt-top .wave-badge, .bt-top .cd-pill { font-size: 11px; padding: 2px 8px; }
  .bt-enemy-box {
    --enemy-h: 62px;
    --enemy-h: clamp(62px, calc(100vh - 420px), 230px);
    --enemy-h: clamp(62px, calc(100dvh - 420px), 230px);
  }
  .enemy-hp-wrap { gap: 1px; }
  .hp-head { font-size: 11px; }
  .bar-track { height: 7px; }
  .meaning-panel { min-height: 50px; padding: 4px 8px; border-radius: 12px; }
  .meaning-line { font-size: 14px; line-height: 1.32; }
  .party-strip { gap: 4px; }
  .sp-slot { padding: 2px 4px; gap: 4px; border-radius: 10px; }
  .sp-av { width: 24px; height: 24px; }
  .sp-sk { font-size: 11px; }
  .sp-bar { height: 4px; margin-top: 2px; }
  .sp-attr-dot { width: 6px; height: 6px; }
  .player-bar-row { padding: 2px 6px; gap: 6px; }
  .buff-chips { font-size: 11px; }
  .cards-col { gap: 3px; }
  .k-card { height: 42px; font-size: 16px; border-radius: 10px; }
}

/* ---- Reduced motion: keep every state change, drop the ambient and shaking motion ---- */
@media (prefers-reduced-motion: reduce) {
  .home-sp, .bt-enemy-img, .sp-slot.ready, .cd-pill.danger { animation: none; }
  /* Hit / miss feedback stays visible as a brief border flash instead of a screen shake. */
  .bt-arena.shake-hit, .bt-arena.shake-miss { animation: arenaFlash .24s linear; }
  @keyframes arenaFlash { 0%,100% { outline: 0 solid transparent; } 30% { outline: 2px solid var(--gold-hi); outline-offset: -2px; } }
  .slash-svg.fire { animation-duration: .2s; }
  .g-pull-card { animation: none; }
  .bar-ghost { transition-duration: .2s; }
  .dmg-pop { animation-name: popFade; }
  @keyframes popFade {
    0% { opacity: 0; transform: translate(calc(-50% + var(--dx)), -40px); }
    15%, 80% { opacity: 1; transform: translate(calc(-50% + var(--dx)), -40px); }
    100% { opacity: 0; transform: translate(calc(-50% + var(--dx)), -40px); }
  }
  .tree-card, .stage-card, .big-cta, .k-card { transition: none; }
}
