@media (min-width: 1024px) and (max-width: 1920px) {
  :root {
    /* 40% smaller for main UI */
    --fs: 9.6px; /* 60% of 16px */
    --fs-sm: 8.4px; /* 60% of 14px */
    --fs-lg: 10.8px; /* 60% of 18px */
    --gap: 7.2px; /* 60% of 12px */
    --pad: 7.2px; /* 60% of 12px */
    --r: 9.6px; /* 60% of 16px */
    --r2: 10.8px; /* 60% of 18px */
    /* Reduce other custom sizes if needed */
  }
  .combat-log {
    height: 102px;
  }
  .used-words-list {
    max-height: 96px;
  }
  .hero-image-wrap img,
  .monster-image-wrap img {
    padding: 7.2px;
  }
  .pill {
    font-size: 7.5px;
    padding: 2.4px 4.2px;
  }

  /* Footer: only 25% smaller (75% scale) */
  .footer,
  .footer .btn,
  .footer #continueBtn,
  .footer #castBtn,
  .footer #startBtn,
  .footer .midi-select,
  .footer select.midi-select {
    font-size: 75%;
  }
  .footer .btn,
  .footer #continueBtn,
  .footer #castBtn,
  .footer #startBtn {
    min-height: 36px; /* 75% of 48px */
  }
  .footer .midi-select,
  .footer select.midi-select {
    min-height: 36px;
  }
}
@keyframes flashYellow {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 209, 102, 0);
  }
  20% {
    box-shadow:
      0 0 0 6px rgba(255, 209, 102, 0.22),
      0 0 26px rgba(255, 209, 102, 0.16);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(255, 209, 102, 0);
  }
}
.monster-image-card {
  position: relative;
}
.hero-card {
  position: relative;
}
.monster-image-card.shake {
  animation: wobble 240ms ease;
}
.hero-card.shake {
  animation: wobble 240ms ease;
}
.monster-image-card.damage-flash::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  border-radius: inherit;
  animation: flashRed 180ms ease;
  z-index: 99;
}
.hero-card.damage-flash::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  border-radius: inherit;
  animation: flashYellow 180ms ease;
  z-index: 99;
}
/* =========================================================
   Word Battle - Mobile First (Portrait)
   Goal: Perfect on smartphones (S24 etc.)
   - Single column
   - Sticky bottom controls
   - Large tap targets
   - No "bottom cut off" issues
   ========================================================= */

:root {
  --bg: #070a10;
  --panel: rgba(18, 24, 34, 0.8);
  --panel2: rgba(10, 14, 20, 0.78);
  --border: rgba(255, 255, 255, 0.1);

  --text: rgba(245, 247, 255, 0.92);
  --muted: rgba(245, 247, 255, 0.7);

  --accent: #7aa7ff;
  --good: #45f0a8;
  --bad: #ff5a7d;
  --warn: #ffd166;

  --r: 16px;
  --r2: 18px;

  /* smartphone-friendly sizing */
  --fs: 16px; /* keep >=16px to avoid iOS focus zoom */
  --fs-sm: 14px;
  --fs-lg: 18px;

  --gap: 12px;
  --pad: 12px;

  --shadow: 0 10px 26px rgba(0, 0, 0, 0.45);
  --shadow-soft: 0 8px 18px rgba(0, 0, 0, 0.3);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(5, 7, 12, 0.62), rgba(7, 10, 16, 0.82)),
    url('/assets/img/bg/crypt.png');
  background-position: center;
  /*background-repeat: no-repeat;*/
  background-size: cover;

  color: var(--text);
  font:
    500 var(--fs)/1.35 system-ui,
    -apple-system,
    Segoe UI,
    Roboto,
    Arial,
    sans-serif;
  -webkit-font-smoothing: antialiased;
}

img {
  display: block;
  max-width: 100%;
}
button,
input,
select {
  font: inherit;
}
:focus-visible {
  outline: 2px solid rgba(122, 167, 255, 0.85);
  outline-offset: 2px;
  border-radius: 12px;
}

/* =========================
   Core app layout
   ========================= */

/* IMPORTANT: 100svh prevents mobile URL bar cut-off issues */
#app.app {
  min-height: 100svh;
  display: flex;
  flex-direction: column;

  padding: var(--pad);
  gap: var(--gap);

  /* leave room for safe area + sticky footer */
  padding-bottom: calc(var(--pad) + env(safe-area-inset-bottom, 0px));
}

/* Keep everything single-column on phones */
.topbar,
.arena {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
}

/* Top area */
.topbar {
  display: grid;
  gap: var(--gap);
}

.title h1 {
  margin: 2px 0 0 0;
  font-size: 22px;
  letter-spacing: 0.3px;
}
.subtitle {
  margin: 4px 0 0 0;
  color: var(--muted);
  font-size: var(--fs-sm);
}

/* HUD: stacked cards, easy reading */
.hud {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.hud-item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r2);
  box-shadow: var(--shadow-soft);
  padding: 12px;
  backdrop-filter: blur(10px);
}

.hud-item .label {
  font-size: 12px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.hud-item .value {
  font-weight: 900;
  font-size: var(--fs-lg);
}

.bar {
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.06);
  margin-bottom: 8px;
}
.fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(69, 240, 168, 0.95), rgba(122, 167, 255, 0.85));
  transition: width 180ms ease;
}
.fill.monster {
  background: linear-gradient(90deg, rgba(255, 90, 125, 0.95), rgba(255, 209, 102, 0.85));
}

/* =========================
   Arena: scrollable main content
   ========================= */

.arena {
  flex: 1;
  min-height: 0; /* enables scrolling */
  overflow: auto;
  display: grid;
  gap: var(--gap);
  padding-bottom: 10px; /* breathing room above footer */
}

/* Standard card surfaces */
.monster-card,
.spell-panel,
.hero-card,
.monster-image-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r2);
  box-shadow: var(--shadow);
  padding: 12px;
  backdrop-filter: blur(10px);
}

/* Monster text */
.monster-name {
  font-weight: 950;
  font-size: 18px;
  letter-spacing: 0.2px;
}
.monster-desc {
  margin-top: 4px;
  color: var(--muted);
  font-size: var(--fs-sm);
}

/* Combat log: fixed-ish height so you can always reach controls */
.combat-log {
  margin-top: 12px;
  background: var(--panel2);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--r);
  padding: 10px 10px;

  /* great on phones: not too tall */
  height: 170px;
  overflow: auto;
}

.log-line {
  margin: 0 0 6px 0;
  color: rgba(245, 247, 255, 0.86);
  font-size: var(--fs-sm);
}
.log-line:last-child {
  margin-bottom: 0;
}
.log-good {
  color: rgba(69, 240, 168, 0.98);
}
.log-bad {
  color: rgba(255, 90, 125, 0.98);
}
.log-warn {
  color: rgba(255, 209, 102, 0.98);
}

/* Spell input area */
.input-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

#wordInput {
  width: 100%;
  min-height: 48px;
  padding: 12px 12px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(6, 9, 13, 0.7);
  color: var(--text);
  font-size: 16px; /* keep 16px */
}

#wordInput::placeholder {
  color: rgba(245, 247, 255, 0.45);
}

/* Used words panel */
.used-words-panel {
  margin-top: 12px;
  border-radius: var(--r);
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(10, 14, 20, 0.65);
  overflow: hidden;
}
.used-words-header {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-weight: 900;
}
.used-words-list {
  padding: 10px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 160px;
  overflow: auto;
}
.pill {
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: rgba(245, 247, 255, 0.9);
  font-size: 12.5px;
}

/* Monster / hero images: large and centered on phone */
.hero-image-wrap,
.monster-image-wrap {
  border-radius: var(--r);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.22);
}

.hero-image-wrap img,
.monster-image-wrap img {
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  padding: 12px;
  filter: drop-shadow(0 10px 16px rgba(0, 0, 0, 0.45));
}

/* =========================
   Sticky footer controls (phone-perfect)
   ========================= */

.footer {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;

  position: sticky;
  bottom: 0;

  background: rgba(7, 10, 16, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--r2);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);

  padding: 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));

  display: grid;
  gap: 10px;
}

/* Big tappable buttons */
.btn,
#continueBtn,
#castBtn,
#startBtn {
  width: 100%;
  min-height: 48px;
  border-radius: 16px;
  border: 1px solid rgba(122, 167, 255, 0.32);
  background: linear-gradient(180deg, rgba(122, 167, 255, 0.22), rgba(122, 167, 255, 0.1));
  color: rgba(245, 247, 255, 0.95);
  font-weight: 900;
  letter-spacing: 0.3px;
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    transform 120ms ease,
    filter 120ms ease,
    border-color 120ms ease;
}

.btn:active,
#continueBtn:active,
#castBtn:active,
#startBtn:active {
  transform: translateY(1px);
}

.btn:disabled,
#continueBtn:disabled,
#castBtn:disabled,
#startBtn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Music player: stack neatly */
.midi-player {
  display: grid;
  gap: 10px;
  color: var(--muted);
  font-size: var(--fs-sm);
}

.midi-select,
select.midi-select {
  width: 100%;
  min-height: 48px;
  padding: 12px 12px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(6, 9, 13, 0.7);
  color: rgba(245, 247, 255, 0.92);
}

/* =========================
   Effects from your JS
   ========================= */
@keyframes wobble {
  0% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-6px);
  }
  40% {
    transform: translateX(6px);
  }
  60% {
    transform: translateX(-4px);
  }
  80% {
    transform: translateX(4px);
  }
  100% {
    transform: translateX(0);
  }
}
@keyframes flashRed {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 90, 125, 0);
  }
  20% {
    box-shadow:
      0 0 0 6px rgba(255, 90, 125, 0.22),
      0 0 26px rgba(255, 90, 125, 0.16);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(255, 90, 125, 0);
  }
}
@keyframes dissolve {
  0% {
    opacity: 1;
    filter: saturate(1) contrast(1);
    transform: translateY(0);
  }
  70% {
    opacity: 0.55;
    filter: saturate(0.6) contrast(1.1);
  }
  100% {
    opacity: 0.1;
    filter: saturate(0.2) blur(1px);
    transform: translateY(6px);
  }
}

.monster-image-card {
  position: relative;
}
.monster-image-card.shake {
  animation: wobble 240ms ease;
}
.monster-image-card.damage-flash::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  border-radius: inherit;
  animation: flashRed 180ms ease;
  z-index: 99;
}
.monster-image-card.defeated .monster-image-wrap img {
  animation: dissolve 520ms ease forwards;
}

.tiny-top-margin {
  margin-top: 6px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

/* Tiny phones: tighten spacing a bit */
@media (max-width: 360px) {
  :root {
    --gap: 10px;
    --pad: 10px;
  }
  .combat-log {
    height: 155px;
  }
}

/* =========================================
   Minimized footer (after Start Fight)
   ========================================= */

.footer {
  transition:
    transform 160ms ease,
    max-height 160ms ease,
    padding 160ms ease,
    opacity 160ms ease;
}

/* When minimized, footer becomes a small tappable "tab" */
.footer.minimized {
  max-height: 56px;
  padding-top: 8px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  overflow: hidden;
}

/* Hide most controls while minimized */
.footer.minimized > * {
  opacity: 0;
  pointer-events: none;
}

/* Show a visible handle/tab even though children are hidden */
.footer.minimized::before {
  content: '▲ Controls (tap)';
  display: flex;
  align-items: center;
  justify-content: center;

  opacity: 1;
  pointer-events: auto;

  height: 40px;
  margin: 0 auto;

  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.06);

  color: rgba(245, 247, 255, 0.92);
  font-weight: 900;
  letter-spacing: 0.3px;
}

/* ==================================================
   Desktop Grid Layout (1024px+)
   Left: Topbar + Arena
   Right: Characters (spans both rows)
   Bottom: Footer spans full width
   ================================================== */

@media (min-width: 1024px) {
  #app.app {
    max-width: 1200px;
    margin: 0 auto;

    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas:
      'topbar characters'
      'arena  characters'
      'footer footer';

    height: 100svh; /* stable viewport height */
  }

  .topbar {
    grid-area: topbar;
    max-width: none;
    margin: 0;
  }

  .arena {
    grid-area: arena;
    max-width: none;
    margin: 0;

    min-height: 0;
    overflow: auto; /* arena scrolls */
  }

  .character-row {
    grid-area: characters;
    max-width: none;
    margin: 0;

    min-height: 0;
    overflow: auto; /* sidebar scrolls if needed */
    display: grid;
    gap: var(--gap);
    align-content: start;
  }

  .footer {
    grid-area: footer;
    max-width: none;
    margin: 0;

    position: sticky;
    bottom: 0;
  }
}

@media (min-width: 1400px) {
  #app.app {
    max-width: 1400px;
    grid-template-columns: minmax(0, 1fr) 440px;
  }
}
