/* Layout: one portrait screen. Foes and their next move up top, the swordsman's
   bar and hand of talisman cards in the thumb zone, turn controls at the bottom. */
:root {
  --night: #121a2b;      /* sky behind the pass */
  --dusk: #1d2942;       /* raised panels */
  --ridge: #0c1220;      /* mountain silhouette */
  --mist: #8e9bb6;       /* secondary text, indigo-biased */
  --moon: #ebe6d8;       /* primary text */
  --paper: #f1e8d2;      /* card face */
  --paper-edge: #d9ccad;
  --ink: #231e19;        /* ink on paper */
  --lantern: #f0a63a;    /* accent: energy, selection */
  --lantern-dim: #8a6a3a;
  --blood: #d8493f;      /* HP, damage */
  --ward: #62a3d9;       /* block */
  --jade: #72c08e;       /* buffs */
  --hex: #b48ad9;        /* debuffs */
  --seal-attack: #b3352c;
  --seal-skill: #2f6191;
  --seal-power: #a07a1e;
  --f-brush: 'Yuji Syuku', 'Hiragino Mincho ProN', 'Yu Mincho', serif;
  --f-mincho: 'Shippori Mincho B1', 'Hiragino Mincho ProN', 'Yu Mincho', serif;
  --f-body: 'Zen Kaku Gothic New', 'Hiragino Sans', 'Noto Sans JP', system-ui, sans-serif;
  --cw: min(calc((100vw - 56px) / 5), 92px); /* card width: five fit side by side */
  color-scheme: dark;
}
/* @standalone-only */
:root { padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
/* @end */
html { box-sizing: border-box; height: 100%; background: var(--night); }
*, *::before, *::after { box-sizing: inherit; }
body {
  margin: 0;
  height: 100%;
  background:
    radial-gradient(60vmax 40vmax at 82% -6%, rgba(240, 166, 58, 0.10), transparent 60%),
    radial-gradient(80vmax 50vmax at 10% 30%, rgba(98, 163, 217, 0.08), transparent 70%),
    var(--night);
  color: var(--moon);
  font: 14px/1.5 var(--f-body);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overflow: hidden;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--lantern); outline-offset: 2px; }
[hidden] { display: none !important; }

#app {
  position: relative;
  height: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.screen { height: 100%; }

/* ------------------------------------------------------------ buttons */
.btn {
  border: 0;
  border-radius: 999px;
  padding: 0.8em 1.5em;
  font-weight: 700;
  letter-spacing: 0.04em;
  min-height: 44px;
}
.btn.primary { background: var(--lantern); color: var(--ink); box-shadow: 0 0 0 1px rgba(0,0,0,.2), 0 6px 24px rgba(240, 166, 58, 0.25); }
.btn.primary:disabled { background: var(--lantern-dim); box-shadow: none; opacity: 0.6; }
.btn.ghost { background: transparent; color: var(--mist); box-shadow: inset 0 0 0 1px rgba(142, 155, 182, 0.4); }
.chip-btn {
  background: var(--dusk);
  border: 0;
  border-radius: 999px;
  padding: 0.35em 0.9em;
  color: var(--mist);
  font-size: 13px;
  min-height: 34px;
}
.chip-btn b { color: var(--moon); font-variant-numeric: tabular-nums; }
.chip-btn.round { width: 34px; padding: 0; font-weight: 700; }

/* ------------------------------------------------------------ title */
#title { display: grid; place-items: center; }
.title-inner { max-width: 26em; display: grid; gap: 18px; padding-block: 24px; }
.eyebrow { margin: 0; color: var(--lantern); font-size: 12px; letter-spacing: 0.3em; }
.logo {
  margin: 0;
  font: 400 clamp(64px, 22vw, 112px)/1 var(--f-brush);
  letter-spacing: 0.06em;
  text-shadow: 0 0 40px rgba(240, 166, 58, 0.18);
}
.lede { margin: 0; color: var(--moon); font-size: 15px; text-wrap: pretty; }
.howto { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; color: var(--mist); font-size: 13px; }
.howto li { padding-left: 1.1em; position: relative; }
.howto li::before { content: ''; position: absolute; left: 0; top: 0.65em; width: 6px; height: 6px; background: var(--lantern); transform: rotate(45deg); }
.howto b { color: var(--moon); }
.title-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.level-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 14px; background: var(--dusk); }
.level-text { flex: 1; display: grid; text-align: center; line-height: 1.3; }
.level-name { font-family: var(--f-mincho); font-weight: 800; letter-spacing: 0.08em; }
.level-name b { color: var(--lantern); font-size: 18px; }
.level-text small { color: var(--mist); font-size: 12px; }
.level-row .chip-btn:disabled { opacity: 0.3; }
.records { margin: 0; color: var(--mist); font-size: 12px; text-align: center; min-height: 1.5em; }
.level-tag { margin-left: 8px; padding: 0 6px; border-radius: 5px; background: var(--dusk); color: var(--lantern); font-size: 12px; vertical-align: 2px; }
.title-actions .btn { flex: 1 1 auto; }

/* ------------------------------------------------------------ battle */
#battle { display: flex; flex-direction: column; }
.hud { display: flex; align-items: center; justify-content: space-between; padding-block: 10px 4px; }
.stage { font-family: var(--f-mincho); font-weight: 800; font-size: 18px; letter-spacing: 0.08em; }
.stage-of { color: var(--mist); font-size: 13px; margin-left: 4px; font-weight: 700; }
.fast { margin-left: 10px; font-family: var(--f-body); font-size: 11px; font-weight: 700; letter-spacing: 0.02em; color: var(--lantern); vertical-align: 2px; }
.fast b { font-size: 14px; margin: 0 1px; }
.fast.gone { color: var(--mist); }
.hud-actions { display: flex; gap: 8px; }

#field { position: relative; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
#foes {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding-block: 8px;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 80' preserveAspectRatio='none'%3E%3Cpath d='M0 80 L0 52 L40 38 L70 46 L110 22 L150 40 L190 30 L230 48 L270 18 L310 36 L350 28 L400 44 L400 80 Z' fill='%230c1220'/%3E%3C/svg%3E") bottom / 100% 42% no-repeat;
}
.foe {
  position: relative;
  flex: 0 1 150px;
  min-width: 0;
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 6px 4px 8px;
  border-radius: 14px;
  background: none;
  border: 0;
  transition: transform 0.2s, opacity 0.4s;
}
.foe.dead { opacity: 0.18; pointer-events: none; }
.foe.targetable { cursor: pointer; }
.foe.targetable .glyph { box-shadow: 0 0 0 3px var(--lantern), 0 0 28px rgba(240, 166, 58, 0.45); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 3px var(--lantern), 0 0 8px rgba(240, 166, 58, 0.2); } }
.foe.acting { animation: lunge 0.45s ease; }
@keyframes lunge { 40% { transform: translateY(14px) scale(1.06); } }
.glyph {
  width: clamp(76px, 24vw, 108px);
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font: 400 clamp(46px, 15vw, 66px)/1 var(--f-brush);
  color: var(--moon);
  background: radial-gradient(circle at 50% 40%, #2a3756, #151e33 70%);
  box-shadow: inset 0 0 0 2px rgba(235, 230, 216, 0.15);
}
.foe.boss .glyph { width: clamp(104px, 32vw, 140px); font-size: clamp(64px, 20vw, 88px); color: #f3d6cf; background: radial-gradient(circle at 50% 40%, #4a2328, #1c1220 70%); }
.foe-name { font-family: var(--f-mincho); font-weight: 800; font-size: 14px; letter-spacing: 0.06em; }
.intent {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 30px;
  padding: 2px 10px 2px 6px;
  border-radius: 999px;
  background: var(--dusk);
  font-weight: 900;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.intent svg { width: 20px; height: 20px; flex: none; }
.intent .k-attack { color: var(--blood); }
.intent .k-defend { color: var(--ward); }
.intent .k-buff { color: var(--jade); }
.intent .k-debuff { color: var(--hex); }
.intent small { font-size: 13px; color: var(--mist); font-weight: 700; }
.intent-note { font-size: 11px; color: var(--mist); text-align: center; line-height: 1.35; min-height: 1.35em; text-wrap: balance; }
.intent-note b { color: var(--moon); font-weight: 700; }
.card.dragging { transition: none; z-index: 5; box-shadow: 0 0 0 2px var(--lantern), 0 14px 30px rgba(0, 0, 0, 0.6); }
#hand .card { touch-action: none; }
.foe.drop .glyph { box-shadow: 0 0 0 4px var(--lantern), 0 0 36px rgba(240, 166, 58, 0.6); }

.bar {
  position: relative;
  width: 100%;
  max-width: 140px;
  height: 14px;
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.45);
  overflow: hidden;
}
.bar i { position: absolute; inset: 0 auto 0 0; background: var(--blood); transition: width 0.35s ease; }
.bar span {
  position: relative;
  z-index: 2;
  display: block;
  text-align: center;
  font-size: 11px;
  line-height: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}
.bar.has-block { box-shadow: 0 0 0 2px var(--ward); }
.bar .half { position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: linear-gradient(var(--moon) 0 28%, transparent 28% 72%, var(--moon) 72%); z-index: 3; }
.foe-meta { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; justify-content: center; min-height: 20px; }
.block-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 0 7px 0 5px;
  height: 20px;
  border-radius: 6px;
  background: var(--ward);
  color: #0d1a29;
  font-weight: 900;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.block-badge svg { width: 13px; height: 13px; }
.chips { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.chip {
  font-size: 11px;
  font-weight: 700;
  padding: 0 6px;
  height: 20px;
  line-height: 20px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.35);
  white-space: nowrap;
}
.chip.good { color: var(--jade); box-shadow: inset 0 0 0 1px rgba(114, 192, 142, 0.5); }
.chip.bad { color: var(--hex); box-shadow: inset 0 0 0 1px rgba(180, 138, 217, 0.5); }
.chip.power { color: var(--lantern); box-shadow: inset 0 0 0 1px rgba(240, 166, 58, 0.5); }

#banner {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 6px;
  text-align: center;
  pointer-events: none;
  z-index: 5;
}
#banner span {
  display: inline-block;
  padding: 6px 18px;
  background: rgba(12, 18, 32, 0.92);
  border-radius: 999px;
  font-family: var(--f-mincho);
  font-weight: 800;
  font-size: 17px;
  letter-spacing: 0.08em;
  box-shadow: 0 0 0 1px rgba(240, 166, 58, 0.4);
  animation: bannerIn 0.25s ease;
}
@keyframes bannerIn { from { transform: translateY(6px); opacity: 0; } }

/* hero */
#hero {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  margin-top: 4px;
  border-radius: 14px;
  background: var(--dusk);
  position: relative;
}
.lantern {
  flex: none;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  align-content: center;
  background: radial-gradient(circle at 50% 45%, #ffd27f, var(--lantern) 55%, #a8641a);
  color: var(--ink);
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 0 22px rgba(240, 166, 58, 0.45);
  transition: filter 0.2s;
}
.lantern-num { display: flex; align-items: baseline; }
.lantern-num span { font-size: 26px; }
.lantern-num small { font-size: 12px; }
.lantern em { font-style: normal; font-size: 9px; font-weight: 700; letter-spacing: 0.1em; margin-top: 2px; }
.lantern.empty { filter: grayscale(0.85) brightness(0.65); box-shadow: none; }
.hero-main { flex: 1; min-width: 0; display: grid; gap: 5px; }
.hero-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hero-name { font-family: var(--f-mincho); font-weight: 800; letter-spacing: 0.06em; }
#heroBar { max-width: none; height: 16px; }
#heroBar span { line-height: 16px; font-size: 12px; }
.hero-bottom { display: flex; align-items: center; gap: 8px; min-height: 20px; font-size: 12px; }
.incoming { color: var(--mist); font-variant-numeric: tabular-nums; }
.incoming b { color: var(--blood); font-size: 14px; }
.incoming b.safe { color: var(--jade); }
.incoming small { color: var(--mist); font-size: 11px; margin-left: 4px; }

/* hand */
#hand {
  position: relative;
  height: calc(var(--cw) * 1.42 + 26px);
  display: flex;
  justify-content: center;
  align-items: flex-end;
  padding-bottom: 2px;
  margin-top: 6px;
}
.card {
  position: relative;
  flex: none;
  width: var(--cw);
  aspect-ratio: 5 / 7;
  border: 0;
  border-radius: 7px;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 0 0 1px var(--paper-edge), 0 6px 14px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  text-align: center;
  transition: transform 0.18s ease, box-shadow 0.18s, opacity 0.2s, margin 0.2s;
  transform-origin: 50% 100%;
}
.card .seal { height: 6px; border-radius: 7px 7px 0 0; background: var(--seal-attack); }
.card.skill .seal { background: var(--seal-skill); }
.card.power .seal { background: var(--seal-power); }
.card .cost {
  position: absolute;
  top: -8px;
  left: -6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--lantern);
  color: var(--ink);
  font-weight: 900;
  font-size: 14px;
  box-shadow: 0 0 0 2px var(--night);
}
.card .name {
  font-family: var(--f-mincho);
  font-weight: 800;
  font-size: 13px;
  line-height: 1.15;
  padding: 7px 3px 2px;
  letter-spacing: 0.02em;
}
.card .type { font-size: 9px; color: #7a6c58; letter-spacing: 0.1em; display: flex; justify-content: center; gap: 3px; align-items: center; }
.card .theme { font-style: normal; font-weight: 700; padding: 0 3px; border-radius: 3px; color: var(--paper); letter-spacing: 0; line-height: 1.35; }
.card .theme.kuzushi { background: #7d4a8f; }
.card .theme.kihaku { background: #b3352c; }
.card .theme.mamori { background: #2f6191; }
.card .text {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px 4px 6px;
  font-size: 10.5px;
  line-height: 1.3;
  font-weight: 700;
}
.card .text > span { word-break: keep-all; overflow-wrap: anywhere; }
.card .text .up { color: #1b7a43; }
.card .text .down { color: var(--seal-attack); }
.card.unplayable { opacity: 0.5; }
.card.unplayable .cost { background: #6b6152; color: var(--paper); }
.card.selected {
  transform: translateY(-14px) scale(1.16);
  z-index: 3;
  box-shadow: 0 0 0 2px var(--lantern), 0 10px 26px rgba(0, 0, 0, 0.6);
}
.card.selected:first-child { transform-origin: 0 100%; }
.card.selected:last-child { transform-origin: 100% 100%; }
.hint { margin: 0; min-height: 1.5em; text-align: center; font-size: 12px; color: var(--mist); }

.controls { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center; padding-block: 4px 12px; }
.pile-btn { background: none; border: 0; color: var(--mist); font-size: 13px; min-height: 44px; }
.pile-btn b { color: var(--moon); font-variant-numeric: tabular-nums; }
.pile-btn:first-child { text-align: left; }
.pile-btn:last-child { text-align: right; }
.btn.end { background: var(--moon); color: var(--ink); padding-inline: 2em; }
.btn.end.ready { background: var(--lantern); animation: nudge 1.6s ease-in-out infinite; }
@keyframes nudge { 50% { box-shadow: 0 0 0 6px rgba(240, 166, 58, 0.15); } }
.btn.end:disabled { opacity: 0.4; }

/* floating numbers */
.float {
  position: absolute;
  left: 50%;
  top: 30%;
  transform: translateX(-50%);
  font-weight: 900;
  font-size: 26px;
  pointer-events: none;
  z-index: 6;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.9);
  animation: floatUp 0.9s ease-out forwards;
  white-space: nowrap;
}
.float.dmg { color: var(--blood); }
.float.blk { color: var(--ward); font-size: 18px; }
.float.st { color: var(--hex); font-size: 15px; }
.float.st.good { color: var(--jade); }
.float.heal { color: var(--jade); }
@keyframes floatUp { from { opacity: 1; transform: translate(-50%, 0); } to { opacity: 0; transform: translate(-50%, -40px); } }
.shake { animation: shake 0.3s ease; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

/* overlays */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: end center;
  background: rgba(8, 12, 22, 0.72);
  padding-left: max(12px, env(safe-area-inset-left, 0px));
  padding-right: max(12px, env(safe-area-inset-right, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } }
.sheet {
  width: 100%;
  max-width: 520px;
  max-height: 92%;
  overflow-y: auto;
  background: var(--dusk);
  border-radius: 20px 20px 0 0;
  padding: 20px 16px 16px;
  display: grid;
  gap: 12px;
}
.sheet h2 { margin: 0; font: 800 22px/1.3 var(--f-mincho); letter-spacing: 0.05em; text-wrap: balance; }
.sheet .sub { margin: 0; color: var(--mist); font-size: 13px; }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; padding-top: 4px; }
.sheet-actions .btn { flex: 1 1 auto; }
.reward-cards { display: flex; justify-content: center; gap: 10px; padding: 14px 0 6px; }
.reward-cards .card { --cw: min(28vw, 128px); }
.reward-cards .card .name { font-size: 15px; padding-top: 10px; }
.reward-cards .card .text { font-size: 12px; }
.reward-cards .card.picked { transform: translateY(-8px); box-shadow: 0 0 0 3px var(--lantern), 0 10px 26px rgba(0, 0, 0, 0.6); }
.next-foes { display: grid; gap: 6px; padding: 10px 12px; border-radius: 12px; background: rgba(0, 0, 0, 0.25); }
.nf-label { font-size: 11px; letter-spacing: 0.2em; color: var(--lantern); }
.nf { display: flex; gap: 10px; align-items: center; }
.nf-glyph { flex: none; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font: 22px/1 var(--f-brush); background: #151e33; box-shadow: inset 0 0 0 1px rgba(235, 230, 216, 0.2); }
.nf-glyph.boss { color: #f3d6cf; background: #3a1c22; }
.nf-text { font-size: 13px; line-height: 1.35; min-width: 0; }
.nf-text small { color: var(--mist); font-size: 12px; }
.rarity { font-size: 10px; letter-spacing: 0.1em; padding-bottom: 6px; color: #7a6c58; }
.rarity.uncommon { color: var(--seal-skill); }
.rarity.rare { color: var(--seal-power); }
.pile-cards, .deck-list { display: flex; flex-wrap: wrap; gap: 12px 8px; justify-content: center; padding-top: 8px; }
.pile-cards .card, .deck-list .card { --cw: min(21vw, 86px); }
.camp-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.camp-opt {
  display: grid;
  gap: 6px;
  align-content: start;
  text-align: left;
  padding: 16px 14px;
  min-height: 110px;
  border: 0;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.28);
  box-shadow: inset 0 0 0 1px rgba(240, 166, 58, 0.35);
}
.camp-opt b { font: 800 20px/1.2 var(--f-mincho); color: var(--lantern); letter-spacing: 0.08em; }
.camp-opt span { font-size: 13px; color: var(--mist); }
.camp-opt:active { background: rgba(240, 166, 58, 0.12); }
.smith-preview { margin: 0; min-height: 3em; font-size: 13px; text-align: center; color: var(--mist); }
.smith-preview b { color: var(--moon); }
.pile-cards .card.picked { box-shadow: 0 0 0 3px var(--lantern), 0 6px 14px rgba(0, 0, 0, 0.45); transform: translateY(-4px); }
.card.up .name { color: #1b6e3f; white-space: nowrap; }
.card .name sup { font-size: 0.75em; line-height: 0; margin-left: 1px; }
.foe.enraged .glyph { color: #ffd9cf; background: radial-gradient(circle at 50% 40%, #7a2a24, #2a1018 70%); box-shadow: 0 0 0 2px rgba(216, 73, 63, 0.7), 0 0 30px rgba(216, 73, 63, 0.45); }
.info-body { display: grid; gap: 10px; font-size: 13px; }
.info-body dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; }
.info-body dt { font-weight: 700; }
.info-body dd { margin: 0; color: var(--mist); }

@media (max-height: 640px) {
  :root { --cw: min(19vw, 80px); }
  .glyph { width: 68px; font-size: 42px; }
  .foe.boss .glyph { width: 92px; font-size: 58px; }
  #hero { padding: 6px 10px; }
  .lantern { width: 50px; height: 50px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
