/* Battle screen. Layout: battle bar / enemy stage / GM log (flex) / player dock. */

#view-battle { gap: 8px; overflow: hidden; }

/* Battle bar */
.battle-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.bb-info {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
  font-size: 0.8rem;
}
.trial-badge { cursor: pointer; color: #9aa3b5; border-style: dashed; font-family: inherit; }
.trial-badge:hover { color: var(--gold); border-color: var(--gold); }
.log-cta { display: block; margin-top: 8px; }
.bb-depth {
  color: var(--crimson);
  font-family: 'Noto Serif JP', serif;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Enemy stage */
.enemy-stage {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 14px;
  background: linear-gradient(180deg, rgba(28, 14, 20, 0.65) 0%, rgba(14, 16, 24, 0.75) 100%);
  border: 1.5px solid #351d23;
  padding: 10px 14px;
  flex-shrink: 0;
}
.boss-card {
  width: 88px;
  height: 104px;
  background: radial-gradient(circle, #2e141c 0%, #0b0d14 100%);
  border: 2.5px solid var(--crimson);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 26px rgba(215, 58, 73, 0.42);
  cursor: pointer;
  position: relative;
  transition: transform 0.16s ease, width 0.2s ease, height 0.2s ease;
}
.boss-card:hover { transform: scale(1.04); }
.boss-card.hit { animation: bossSlash 0.42s ease; }
@keyframes bossSlash {
  0% { transform: scale(1); filter: brightness(1); }
  25% { transform: scale(0.88) rotate(-5deg); filter: brightness(2.8) drop-shadow(0 0 20px #fff); }
  60% { transform: scale(1.08) rotate(4deg); }
  100% { transform: scale(1); filter: brightness(1); }
}
.boss-kanji {
  font-family: 'Noto Serif JP', serif;
  font-size: 3.4rem;
  color: var(--crimson);
  line-height: 1;
  text-shadow: 0 0 16px rgba(215, 58, 73, 0.6);
}
.boss-kanji.multi { font-size: 2rem; writing-mode: vertical-rl; }
.boss-info { display: flex; flex-direction: column; gap: 7px; min-width: 0; font-size: 0.8rem; }
.boss-tags { display: flex; gap: 6px; min-width: 0; }
.hp-line { display: flex; align-items: center; gap: 8px; }
.hp-bar-wrap {
  flex: 1;
  max-width: 260px;
  height: 10px;
  background: #1c1f2b;
  border: 1px solid var(--border);
  overflow: hidden;
}
.hp-bar-fill { width: 100%; height: 100%; background: var(--crimson); transition: width 0.35s ease; }
.hp-bar-fill.player { background: var(--green); }
.hp-bar-fill.player.low { background: #e0a040; animation: lowPulse 1.2s ease-in-out infinite; }
@keyframes lowPulse { 50% { opacity: 0.55; } }
.hp-num { font-size: 0.78rem; white-space: nowrap; }
.enemy-hand-wrap { display: flex; align-items: center; gap: 8px; min-width: 0; }
.mini-label { font-size: 0.68rem; color: var(--muted); white-space: nowrap; }

.num-pop {
  position: absolute;
  top: -12px;
  right: -8px;
  font-weight: 700;
  font-size: 1.2rem;
  text-shadow: 0 0 10px #000;
  animation: floatUp 0.95s ease forwards;
  pointer-events: none;
  z-index: 30;
}
.num-pop.dmg { color: #ff4d5e; }
.num-pop.heal { color: var(--green); right: auto; left: 40%; }
@keyframes floatUp {
  0% { opacity: 1; transform: translateY(0) scale(0.9); }
  100% { opacity: 0; transform: translateY(-34px) scale(1.2); }
}

/* GM log — takes all remaining height */
.gm-box {
  flex: 1 1 auto;
  min-height: 72px;
  overflow-y: auto;
  background: rgba(11, 13, 20, 0.92);
  border: 1.5px solid var(--border);
  padding: 10px 12px;
  color: #dcd7cc;
  font-size: 0.83rem;
  line-height: 1.55;
  user-select: text;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overscroll-behavior: contain;
}
.log-entry {
  padding: 8px 10px;
  background: rgba(22, 25, 38, 0.65);
  border-left: 3px solid var(--crimson);
  white-space: pre-wrap;
  word-break: break-word;
  animation: logSlideIn 0.24s ease;
}
.log-entry.hint-log { border-left-color: var(--gold); background: rgba(35, 30, 20, 0.55); }
.log-entry.sys-log { border-left-color: var(--green); }
.log-entry.verdict-fizzle { border-left-color: #555b68; }
.log-entry.verdict-weak { border-left-color: #8a6a70; }
.log-entry.verdict-clever { border-left-color: var(--gold); }
.log-entry.verdict-masterful {
  border-left-color: #c58cff;
  background: linear-gradient(90deg, rgba(120, 60, 180, 0.22), rgba(22, 25, 38, 0.65));
}
.log-entry.pending-log {
  border-left-color: var(--gold);
  background: rgba(45, 22, 28, 0.65);
  color: var(--gold);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}
.rune-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--gold);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes logSlideIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.gm-box strong { color: var(--gold); }
.gm-box em { font-style: normal; color: var(--muted); }

/* Player dock */
.player-dock {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  background: linear-gradient(0deg, rgba(18, 20, 31, 0.88) 0%, rgba(12, 14, 22, 0.45) 100%);
  border: 1.5px solid #2b1d24;
  padding: 9px 12px;
}
.player-stat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  font-size: 0.8rem;
  position: relative;
}
.hp-label { color: var(--green); font-weight: 700; }

.hand-table {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  width: 100%;
}
.deck-pile {
  width: 66px;
  height: 92px;
  background: repeating-linear-gradient(135deg, #241319, #241319 6px, #140b0f 6px, #140b0f 12px);
  border: 2px solid var(--gold);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--gold);
  font-family: 'Noto Serif JP', serif;
  font-size: 0.82rem;
  box-shadow: -4px 4px 0 #1b1116, -8px 8px 14px rgba(0,0,0,0.7);
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s ease;
}
.deck-pile:hover { transform: translateY(-3px); border-color: var(--crimson); }
.deck-pile span { font-size: 1.25rem; font-weight: 900; }

.card-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: nowrap;
  perspective: 800px;
}
.enemy-hand-wrap .card-row { justify-content: flex-start; gap: 6px; }
@keyframes deckDraw3D {
  0% { opacity: 0; transform: translateX(-110px) translateY(18px) rotate(-14deg) rotateY(180deg) scale(0.5); }
  60% { opacity: 1; transform: translateX(4px) translateY(-5px) rotate(2deg) rotateY(18deg) scale(1.04); }
  100% { opacity: 1; transform: none; }
}
.kanji-card {
  width: 86px;
  height: 112px;
  background: linear-gradient(165deg, #212538 0%, #0e1018 100%);
  border: 2px solid #57303a;
  border-radius: 7px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.65);
  animation: deckDraw3D 0.42s cubic-bezier(0.2, 0.85, 0.25, 1) backwards;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.kanji-card::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(229, 192, 123, 0.15);
  border-radius: 4px;
  pointer-events: none;
}
.kanji-card:hover, .kanji-card.kb-focus {
  transform: translateY(-8px) scale(1.05);
  border-color: var(--gold);
  box-shadow: 0 10px 22px rgba(215, 58, 73, 0.45);
  z-index: 10;
}
.kanji-card:active { transform: scale(0.95); }
.kanji-card .key-hint { position: absolute; bottom: 3px; left: 6px; font-size: 0.6rem; color: var(--muted); }
.kanji-card .char { font-family: 'Noto Serif JP', serif; font-size: 2.8rem; color: #f7f3e8; line-height: 1; }
.kanji-card .dict-link {
  position: absolute;
  top: 0;
  right: 0;
  padding: 3px 5px;
  font-size: 0.65rem;
  color: var(--muted);
  text-decoration: none;
  z-index: 5;
}
.kanji-card .dict-link:hover { color: var(--gold); }
.kanji-card.enemy-sm { width: 44px; height: 56px; border-color: #46262e; border-radius: 5px; }
.kanji-card.enemy-sm .char { font-size: 1.45rem; color: #e87680; }
.kanji-card.enemy-sm .dict-link { display: none; }
.kanji-card.enemy-sm:hover { transform: translateY(-3px); }

.cmd-chips {
  display: flex;
  gap: 6px;
  justify-content: center;
  width: 100%;
}
.chip {
  background: #171b29;
  border: 1px solid var(--border);
  color: #c0c6d4;
  padding: 6px 10px;
  font-size: 0.75rem;
  cursor: pointer;
  border-radius: 4px;
  white-space: nowrap;
}
.chip:hover { border-color: var(--crimson); color: #fff; }
.chip-cost { color: #ff8a95; font-size: 0.68rem; }
.prompt-row { display: flex; gap: 8px; width: 100%; }
.prompt-input {
  flex: 1;
  min-width: 0;
  background: #090b11;
  border: 1.5px solid var(--crimson);
  color: #fff;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  user-select: text;
}
.prompt-input:focus { border-color: var(--gold); }
.prompt-input:disabled { opacity: 0.5; }
.prompt-input.flash { animation: inputFlash 0.35s ease; }
@keyframes inputFlash { 0% { box-shadow: 0 0 0 rgba(229,192,123,0); } 40% { box-shadow: 0 0 14px rgba(229,192,123,0.6); } 100% { box-shadow: none; } }
#b-send-btn { padding: 0 16px; font-size: 0.85rem; }

@media (pointer: coarse) {
  .kanji-card .key-hint { display: none; }
}

/* Phones */
@media (max-width: 680px) {
  #view-battle { gap: 6px; }
  .bb-info .badge { padding: 2px 5px; }
  .enemy-stage { gap: 10px; padding: 8px 10px; }
  .boss-card { width: 64px; height: 76px; }
  .boss-kanji { font-size: 2.4rem; }
  .boss-kanji.multi { font-size: 1.4rem; }
  .enemy-hand-wrap .mini-label { display: none; }
  .kanji-card.enemy-sm { width: 34px; height: 42px; }
  .kanji-card.enemy-sm .char { font-size: 1.15rem; }
  .gm-box { padding: 8px; font-size: 0.8rem; }
  .log-entry { padding: 6px 8px; }
  .player-dock { padding: 7px 8px; gap: 7px; }
  .deck-pile { display: none; }
  .card-row { gap: 7px; }
  .kanji-card { width: 58px; height: 74px; }
  .kanji-card .char { font-size: 2rem; }
  .cmd-chips { gap: 5px; }
  .chip { flex: 1; padding: 7px 4px; font-size: 0.72rem; text-align: center; }
  #b-send-btn { padding: 0 12px; }
}

/* On-screen keyboard open: keep only what is needed to write the spell. */
body.kb-open .topbar { display: none; }
body.kb-open .cmd-chips,
body.kb-open .deck-pile,
body.kb-open .boss-tags,
body.kb-open #b-player-state { display: none; }
body.kb-open .enemy-stage { padding: 6px 10px; }
body.kb-open .boss-card { width: 46px; height: 52px; }
body.kb-open .boss-kanji { font-size: 1.8rem; }
body.kb-open .boss-info { gap: 5px; }
body.kb-open #b-player-hand .kanji-card { width: 50px; height: 58px; }
body.kb-open #b-player-hand .kanji-card .char { font-size: 1.65rem; }
body.kb-open #b-player-hand .kanji-card .dict-link { display: none; }
body.kb-open .kanji-card.enemy-sm { width: 30px; height: 36px; }
body.kb-open .kanji-card.enemy-sm .char { font-size: 1rem; }
body.kb-open .player-dock { gap: 6px; padding: 6px 8px; }
body.kb-open .gm-box { min-height: 48px; }

/* ---- Beats: victory intermission & run end (js/game/beats.js) ---- */
.dock-action { display: none; gap: 8px; width: 100%; justify-content: center; flex-wrap: wrap; }
.dock-action .btn { flex: 1; min-width: 110px; padding: 12px 10px; font-size: 0.86rem; }
#view-battle.intermission .dock-action,
#view-battle.run-over .dock-action { display: flex; }
#view-battle.intermission .prompt-row,
#view-battle.intermission .cmd-chips,
#view-battle.run-over .prompt-row,
#view-battle.run-over .cmd-chips { display: none; }
#view-battle.intermission .hand-table,
#view-battle.run-over .hand-table,
#view-battle.intermission .enemy-hand-wrap,
#view-battle.run-over .enemy-hand-wrap { opacity: 0.3; pointer-events: none; }
#view-battle.run-over .player-stat-row { opacity: 0.6; }

.beat-log { text-align: center; border-left: none; padding: 12px 10px; }
.beat-title { font-family: 'Noto Serif JP', serif; font-size: 1.15rem; font-weight: 900; letter-spacing: 2px; margin-bottom: 6px; }
.beat-line { font-size: 0.8rem; }
.victory-log {
  border: 1px solid #6e5931;
  background: linear-gradient(90deg, rgba(229,192,123,0.04), rgba(229,192,123,0.14), rgba(229,192,123,0.04));
}
.victory-log .beat-title { color: var(--gold); text-shadow: 0 0 14px rgba(229,192,123,0.5); }
.death-log {
  border: 1px solid var(--crimson);
  background: linear-gradient(180deg, rgba(90, 10, 22, 0.55), rgba(22, 10, 14, 0.85));
  text-align: left;
}
.death-log .beat-title { color: var(--crimson); text-align: center; text-shadow: 0 0 16px rgba(215,58,73,0.7); }
.death-log .beat-line { padding: 2px 0; }
.death-log .beat-line:last-child { margin-top: 6px; color: var(--muted); text-align: center; }

/* Defeated boss: drained, stamped with 斬 */
.boss-card.defeated { border-color: #4a3036; box-shadow: none; }
.boss-card.defeated .boss-kanji { color: #5a4a4e; text-shadow: none; transition: color 0.4s ease; }
.boss-card.defeated::after {
  content: "斬";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Noto Serif JP', serif;
  font-weight: 900;
  font-size: 2.6rem;
  color: #ff4d5e;
  transform: rotate(-14deg);
  text-shadow: 0 0 12px rgba(0,0,0,0.9), 0 0 18px rgba(255,77,94,0.6);
  animation: stampIn 0.35s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
@keyframes stampIn { from { opacity: 0; transform: rotate(-14deg) scale(2.4); } to { opacity: 1; transform: rotate(-14deg) scale(1); } }
.boss-card.enter { animation: bossEnter 0.6s cubic-bezier(0.2, 0.9, 0.3, 1); }
@keyframes bossEnter {
  0% { opacity: 0; transform: scale(1.5); filter: blur(6px) brightness(3); }
  100% { opacity: 1; transform: scale(1); filter: none; }
}
