/* Use the available desk space while keeping the cast directly below the duel. */
.tutorial-caption { margin:0 0 .8rem; padding:.75rem 1rem; color:#f2e6d7; background:#2e2630; border-inline-start:3px solid #dcc08b; text-align:start; }
.tutorial-caption p { margin:.4rem 0; line-height:1.45; white-space:pre-line; }
.tutorial-tools { display:flex; align-items:center; gap:.65rem; flex-wrap:wrap; }
.tutorial-tools strong { color:var(--gold); margin-inline-end:auto; }
.tutorial-tools button { background:transparent; border:1px solid #8c7881; color:var(--text); border-radius:4px; padding:.3rem .55rem; }
.tutorial-tools button[aria-pressed=true] { border-color:var(--gold); color:var(--gold); }
#duel-view .tutorial-target, dialog .tutorial-target {
  outline: 3px solid #ffda83;
  outline-offset: -2px;
  box-shadow: inset 0 0 0 4px #56390c, 0 0 12px #e9a93880;
}
@media (prefers-reduced-motion: no-preference) {
  .tutorial-target { animation: mentor-highlight 1.35s ease-out 2; }
  @keyframes mentor-highlight {
    50% { outline-color: #fff4c8; box-shadow: inset 0 0 0 4px #56390c, 0 0 18px 3px #ffc15daf; }
  }
}
.shell {
  --edge: clamp(12px, 1.8vw, 80px);
  width: calc(100% - 2 * var(--edge));
}

.game-layout {
  --panel-gap: clamp(12px, 1.05vw, 32px);
  display: grid;
  gap: var(--panel-gap);
  grid-template-columns: minmax(0, 1fr) minmax(260px, 25%);
  grid-template-rows: min-content 1fr auto;
  grid-template-areas:
    'arena   grimoire'
    'casting grimoire'
    'reports reports';
  margin-bottom: var(--panel-gap);
}
.intro { flex-wrap: wrap; }
.intro > div { min-width: 0; overflow-wrap: anywhere; }

.battle-reports {
  grid-area: reports;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  gap: var(--panel-gap);
  min-width: 0;
  margin: 0;
}

.arena {
  position: relative;
  display: flex;
  flex-direction: column;
  container: arena / inline-size;
}

.duel-stage {
  /* The width limit keeps both silhouettes grounded on very tall windows. */
  --auto-height: min(56cqi, clamp(228px, calc(84svh - 315px), 65svh));
  height: clamp(min(160px, 40cqi), var(--duel-arena-height, var(--auto-height)), 70cqi);
  min-height: 0;
  max-height: none;
  aspect-ratio: auto;
}

.combatants {
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: clamp(6px, 1.8cqi, 2rem);
  padding-inline: clamp(10px, 1.7cqi, 36px);
}
.round-display { min-width: clamp(2.4rem, 4.5cqi, 4.5rem); }
.fighter-hud { min-width: 0; max-width: min(100%, 27rem); }
.hud-portrait { width: clamp(28px, 3.4cqi, 3.2rem); }
.hud-name { flex-wrap: wrap; }
.hud-name > b { white-space: normal; overflow-wrap: anywhere; }
.arena-status { flex-wrap: wrap; }
.arena-status > span { min-width: 0; overflow-wrap: anywhere; }

.spell-list { height: clamp(230px, 38svh, 25rem); }
.spell-glyph {
  width: clamp(38px, 3.1vw, 3.3rem);
  height: auto;
  aspect-ratio: 1;
}
.section-heading h2, .phase-label { min-width: 0; overflow-wrap: anywhere; }
.casting-heading, .cast-modes, .typing-metrics { flex-wrap: wrap; }
.cast-modes { max-width: 100%; }
.cast-modes button { white-space: normal; }
.counter-list { grid-template-columns: repeat(auto-fit, minmax(min(100%, 9rem), 1fr)); }
.counter-button { overflow-wrap: anywhere; }
.status-panel { grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr)); }
.world-panel, .battle-log { overflow-wrap: anywhere; }
.world-panel { margin: 0; }
.log-entry > span:last-child { min-width: 0; }
.battle-log ol { max-height: max(180px, 33svh); }
.spell-list, .battle-log ol { overscroll-behavior-y: contain; }

/* Side rails leave the spell, both fighters and the latest events in view together. */
@media (min-width: 112em) and (min-aspect-ratio: 17/10), (min-width: 153em) {
  .intro { padding-block: clamp(10px, 1svh, 18px); }
  .game-layout {
    grid-template-columns: minmax(0, 16fr) minmax(0, 64fr) minmax(0, 20fr);
    grid-template-rows: min-content 1fr;
    grid-template-areas:
      'reports arena   grimoire'
      'reports casting grimoire';
  }
  .battle-reports {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: 'field' 'chronicle';
  }
  .world-panel { grid-area: field; max-height: 47svh; overflow-y: auto; }
  .battle-log { grid-area: chronicle; }
  .grimoire, .casting, .world-panel, .battle-log { padding: clamp(18px, 1.1vw, 36px); }
  .casting { padding-block: clamp(16px, 1.2svh, 22px); }
  .duel-stage { --auto-height: min(56cqi, clamp(228px, calc(84svh - 355px), 65svh)); }
  .spell-list { height: clamp(280px, 40svh, 27rem); }
}

/* Keep a small viewport's width for the arena and the keyboard exercise. */
@media (max-width: 56em) {
  .game-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto;
    grid-template-areas: 'arena' 'casting' 'grimoire' 'reports';
  }
  .duel-stage { --auto-height: min(52cqi, 49svh); }
}

@container arena (max-width: 34rem) {
  .combatants {
    position: static;
    order: -1;
    align-items: center;
    padding-block: 9px;
    border-bottom: 1px solid var(--line);
    background: #201a24;
  }
  .hud-portrait { display: none; }
  .hud-name { gap: 2px 8px; }
}

@media (max-width: 42.5em) {
  .battle-reports { grid-template-columns: minmax(0, 1fr); }
  .grimoire-nav, .typing-entry { flex-wrap: wrap; }
  .typing-entry textarea { flex: 1 1 min(12rem, 100%); }
  .typing-entry .cast-button { flex: 1 0 auto; }
}
