/* ── ROOT VARIABLES ────────────────────────────────────────────────────────── */
:root {
  --bg:           #0d0d1a;
  --surface:      #1a1a2e;
  --surface2:     #16213e;
  --text:         #e8d5b7;
  --text-dim:     #9a8a6a;
  --text-dark:    #4a3f30;
  --border:       #2e2e4a;
  --red:          #b03020;
  --red-bg:       #2a0f0a;
  --red-bright:   #e74c3c;
  --blue:         #1a4f72;
  --blue-bg:      #0a1a2e;
  --blue-bright:  #2980b9;
  --purple:       #5a2a80;
  --purple-bg:    #1a0a2e;
  --purple-bright:#8e44ad;
  --gold:         #c8961a;
  --gold-bright:  #f39c12;
  --green:        #1e7a3a;
  --green-bright: #27ae60;
  --grey:         #3a3a4a;
  --grey-bright:  #666688;
  --hp-high:      #27ae60;
  --hp-mid:       #e67e22;
  --hp-low:       #e74c3c;
  --radius:       8px;
  --radius-lg:    12px;
  --shadow:       0 2px 8px rgba(0,0,0,0.6);
  --shadow-lg:    0 4px 16px rgba(0,0,0,0.8);
  --tap-min:      44px;
  --font-min:     14px;
}

/* ── RESET ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  background: #111;
  color: var(--text);
  font-family: 'Georgia', 'Times New Roman', serif;
  font-size: 14px;
  line-height: 1.4;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ── PHONE FRAME (desktop: centered portrait window) ───────────────────────── */
#phone-frame {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #111;
}

/* ── APP SHELL ─────────────────────────────────────────────────────────────── */
#app {
  position: relative;
  overflow: hidden;
  background: var(--bg);
  /* Phone dimensions: fill viewport on mobile, fixed portrait on desktop */
  /* Use dvh (dynamic viewport height) so mobile Chrome browser chrome is accounted for */
  width: min(390px, 100vw);
  height: min(844px, 100dvh);
  border-radius: 0;
}

/* On desktop (viewport wider than phone): show phone chrome */
@media (min-width: 420px) {
  #app {
    border-radius: 16px;
    box-shadow: 0 0 0 1px #2a2a3a, 0 8px 48px rgba(0,0,0,0.9);
  }
}

/* ── GAME HEADER (logo bar, always visible) ────────────────────────────────── */
#game-header {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 48px;
  z-index: 200;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

#game-header img {
  height: 100%;
  width: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
}

.screen {
  position: absolute;
  top: 48px; left: 0; right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.screen.hidden { display: none !important; }

/* ── TYPOGRAPHY ────────────────────────────────────────────────────────────── */
h1 { font-size: 1.8rem; letter-spacing: 0.08em; }
h2 { font-size: 1.3rem; letter-spacing: 0.06em; }
h3 { font-size: 1.1rem; }

.text-gold   { color: var(--gold-bright); }
.text-red    { color: var(--red-bright); }
.text-blue   { color: var(--blue-bright); }
.text-purple { color: var(--purple-bright); }
.text-green  { color: var(--green-bright); }
.text-dim    { color: var(--text-dim); }

/* ── BUTTONS ───────────────────────────────────────────────────────────────── */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap-min);
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: var(--font-min);
  font-weight: bold;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.97); filter: brightness(0.85); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn:disabled:active { transform: none; filter: none; }

.btn-primary {
  background: linear-gradient(135deg, #8B1A1A, #c0392b);
  color: var(--text);
  box-shadow: var(--shadow);
  text-transform: uppercase;
}

.btn-gold {
  background: linear-gradient(135deg, #7a5c10, #c8961a);
  color: #1a1000;
  box-shadow: var(--shadow);
  text-transform: uppercase;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.btn-danger {
  background: linear-gradient(135deg, #6b1010, #a02020);
  color: var(--text);
}

/* ── HP BAR ────────────────────────────────────────────────────────────────── */
.hp-bar {
  width: 100%;
  height: 6px;
  background: #333;
  border-radius: 3px;
  overflow: hidden;
}
.hp-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease;
}
.hp-fill.high  { background: var(--hp-high); }
.hp-fill.mid   { background: var(--hp-mid); }
.hp-fill.low   { background: var(--hp-low); box-shadow: 0 0 4px var(--hp-low); }

/* ── PORTRAIT ──────────────────────────────────────────────────────────────── */
.portrait-wrap {
  position: relative;
  flex-shrink: 0;
  width: 100%;
  height: 100%;
}
.portrait-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface2);
  border-radius: var(--radius);
  font-size: 1.2rem;
  font-weight: bold;
  color: var(--text-dim);
  letter-spacing: 0;
}
.portrait-placeholder.hidden { display: none; }

.portrait {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--radius);
  position: relative;
  z-index: 1;
}

/* ── STATUS BADGES ─────────────────────────────────────────────────────────── */
.status-row {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  min-height: 16px;
}
.status-badge {
  font-size: 10px;
  padding: 1px 4px;
  border-radius: 3px;
  font-weight: bold;
  letter-spacing: 0;
}
.status-badge.poison  { background: #1a4a1a; color: #5a0; }
.status-badge.burn    { background: #4a1a00; color: #f80; }
.status-badge.stun    { background: #4a4a00; color: #ff0; }
.status-badge.weaken  { background: #3a1a3a; color: #c8a; }
.status-badge.fragile { background: #2a2a3a; color: #88c; }
.status-badge.buff    { background: #1a2a1a; color: #8f8; }
.status-badge.slow    { background: #1a1a3a; color: #88f; }
.status-badge.fear    { background: #2a1a2a; color: #f8f; }
.status-badge.block   { background: #1a2a3a; color: #4af; }
.status-badge.reflect { background: #2a2a1a; color: #ff8; }
.status-badge.protect { background: #3a2a1a; color: #fc8; }

/* ── CARD COLOR CODING ─────────────────────────────────────────────────────── */
.card-red    { border-color: var(--red-bright) !important; background: var(--red-bg) !important; }
.card-blue   { border-color: var(--blue-bright) !important; background: var(--blue-bg) !important; }
.card-purple { border-color: var(--purple-bright) !important; background: var(--purple-bg) !important; }
.card-blank  { border-color: var(--grey) !important; background: #111 !important; opacity: 0.5; }

/* ── ANIMATIONS ────────────────────────────────────────────────────────────── */
@keyframes fadeIn  { from { opacity:0; } to { opacity:1; } }
@keyframes slideUp { from { transform:translateY(20px); opacity:0; } to { transform:translateY(0); opacity:1; } }
@keyframes shake   { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-4px)} 75%{transform:translateX(4px)} }
@keyframes pulse   { 0%,100%{opacity:1} 50%{opacity:0.5} }
@keyframes cardFlip {
  0%   { transform: rotateY(0); }
  50%  { transform: rotateY(90deg); }
  100% { transform: rotateY(0); }
}
@keyframes hitFlash {
  0%   { box-shadow: 0 0 0 3px #e74c3c, 0 0 16px rgba(231,76,60,0.9); transform: translateX(-6px); }
  25%  { box-shadow: 0 0 0 3px rgba(231,76,60,0.8), 0 0 10px rgba(231,76,60,0.6); transform: translateX(6px); }
  55%  { box-shadow: 0 0 0 2px rgba(231,76,60,0.4), 0 0 6px rgba(231,76,60,0.3); transform: translateX(-3px); }
  80%  { box-shadow: 0 0 0 1px rgba(231,76,60,0.15); transform: translateX(1px); }
  100% { box-shadow: none; transform: translateX(0); }
}
@keyframes healFlash {
  0%   { box-shadow: 0 0 0 3px #27ae60, 0 0 14px rgba(39,174,96,0.8); }
  60%  { box-shadow: 0 0 0 2px rgba(39,174,96,0.4), 0 0 6px rgba(39,174,96,0.3); }
  100% { box-shadow: none; }
}

.anim-fade-in  { animation: fadeIn  0.3s ease; }
.anim-slide-up { animation: slideUp 0.3s ease; }
.anim-shake    { animation: shake   0.3s ease; }
.anim-pulse    { animation: pulse   1s infinite; }
.anim-flip     { animation: cardFlip 0.4s ease; }
.anim-hit      { animation: hitFlash  0.45s ease-out; }
.anim-heal     { animation: healFlash 0.55s ease-out; }

/* ── FLOATING DAMAGE TEXT ──────────────────────────────────────────────────── */
@keyframes floatDmg {
  0%   { opacity: 1; transform: translateY(0) scale(1); }
  25%  { opacity: 1; transform: translateY(-16px) scale(1.3); }
  100% { opacity: 0; transform: translateY(-44px) scale(0.9); }
}
.float-dmg {
  position: absolute;
  pointer-events: none;
  z-index: 350;
  font-size: 22px;
  font-weight: bold;
  font-family: 'Georgia', serif;
  text-shadow: 0 2px 6px rgba(0,0,0,0.9), 0 0 12px currentColor;
  animation: floatDmg 0.85s ease-out forwards;
  white-space: nowrap;
}
.float-dmg.hit  { color: #ff4422; }
.float-dmg.heal { color: #2ecc71; }

/* ── OVERLAY ───────────────────────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 100;
  display: flex;
  align-items: flex-end;
}
.overlay.hidden { display: none; }

/* ── SCROLLABLE LOG ────────────────────────────────────────────────────────── */
.battle-log {
  overflow-y: auto;
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.5;
  padding: 4px 8px;
}
.battle-log .log-line { padding: 1px 0; }
.battle-log .log-line.damage  { color: #e87060; }
.battle-log .log-line.heal    { color: var(--green-bright); }
.battle-log .log-line.status  { color: var(--purple-bright); }
.battle-log .log-line.special { color: var(--gold-bright); }
