:root {
  --ink: #1f2523;
  --muted: #5e6862;
  --paper: #fbf7ef;
  --panel: #fffdf7;
  --line: #d9d0bf;
  --blue: #2e7c97;
  --green: #5f8f58;
  --copper: #b6623f;
  --gold: #d5a13b;
  --red: #a84a45;
  --shadow: 0 18px 50px rgba(31, 37, 35, 0.18);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  background: #242623;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  min-height: 100svh;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.deck {
  width: min(100vw, 1366px);
  height: min(100svh, 960px);
  aspect-ratio: 4 / 3;
  position: relative;
  background: var(--paper);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.slide {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: 0.9fr 1.1fr;
  gap: clamp(18px, 3vw, 54px);
  padding: clamp(38px, 6vw, 76px);
  opacity: 0;
  transform: translateX(4%);
  pointer-events: none;
  transition: opacity 260ms ease, transform 260ms ease;
}

.slide.active {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}

.slide-copy {
  align-self: center;
  z-index: 2;
}

.eyebrow {
  margin: 0 0 12px;
  text-transform: uppercase;
  font-size: clamp(12px, 1.3vw, 15px);
  font-weight: 800;
  color: var(--copper);
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
  line-height: 0.98;
  letter-spacing: 0;
}

h1 {
  max-width: 720px;
  font-size: clamp(54px, 9vw, 104px);
}

h2 {
  max-width: 620px;
  font-size: clamp(38px, 5.6vw, 72px);
}

h3 {
  margin: 0 0 14px;
  font-size: clamp(22px, 2.2vw, 32px);
}

p {
  font-size: clamp(18px, 1.7vw, 25px);
  line-height: 1.36;
}

.lead {
  max-width: 620px;
  color: var(--muted);
  font-size: clamp(22px, 2.2vw, 32px);
}

.hero-scene,
.battle-stage,
.formula-board,
.crowding-panel,
.widget-board,
.coef-diagram,
.lane-table,
.flow-grid,
.skill-grid,
.two-panel,
.notes-grid,
.closing-equation {
  align-self: center;
  justify-self: stretch;
}

.hero-scene {
  position: relative;
  min-height: 520px;
  display: grid;
  grid-template-columns: 1fr 160px 1fr;
  align-items: center;
}

.army {
  display: grid;
  gap: 26px;
}

.army-left {
  justify-items: end;
}

.army-right {
  justify-items: start;
}

.unit {
  width: 116px;
  height: 116px;
  display: grid;
  place-items: center;
  position: relative;
  color: white;
  font-weight: 900;
}

.unit::before,
.unit span {
  content: "";
  position: absolute;
  inset: 14px;
  border: 5px solid rgba(255, 255, 255, 0.78);
  background: var(--blue);
  transform: rotate(45deg);
  box-shadow: 0 8px 24px rgba(31, 37, 35, 0.22);
}

.unit b {
  position: relative;
  z-index: 1;
  font-size: 20px;
  align-self: end;
  margin-bottom: 9px;
  padding: 3px 6px;
  border-radius: 5px;
  background: rgba(31, 37, 35, 0.72);
}

.unit img {
  position: relative;
  z-index: 1;
  width: 72%;
  height: 72%;
  object-fit: contain;
  image-rendering: auto;
  filter: drop-shadow(0 5px 7px rgba(31, 37, 35, 0.22));
}

.unit.inf::before,
.unit.inf span {
  background: var(--blue);
}

.unit.lanc::before,
.unit.lanc span {
  background: var(--green);
}

.unit.mark::before,
.unit.mark span {
  background: var(--copper);
}

.pulse-core {
  width: 132px;
  height: 132px;
  border: 3px solid var(--line);
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--muted);
  font-weight: 900;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(0.96); background: #fff9ec; }
  50% { transform: scale(1.06); background: #efe2c9; }
}

.flow-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.step-card,
.chip-card,
.notes-grid div,
.info-panel,
.widget-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  box-shadow: 0 10px 24px rgba(31, 37, 35, 0.08);
}

.step-card span {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--ink);
  color: white;
  font-weight: 900;
  margin-bottom: 18px;
}

.step-card strong,
.chip-card strong,
.notes-grid strong {
  display: block;
  font-size: clamp(18px, 1.8vw, 25px);
}

.step-card p,
.chip-card span,
.notes-grid p,
.info-panel p,
.widget-card p {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: clamp(15px, 1.35vw, 19px);
}

.lane-table {
  display: grid;
  gap: 20px;
}

.lane-row {
  display: grid;
  grid-template-columns: 126px 1fr;
  align-items: center;
  gap: 20px;
  padding: 18px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
}

.lane-row .unit {
  width: 96px;
  height: 96px;
}

.formation-explain {
  display: grid;
  gap: 22px;
}

.formation-column {
  display: grid;
  gap: 14px;
}

.rank-card {
  display: grid;
  grid-template-columns: 104px 110px 1fr;
  align-items: center;
  gap: 18px;
  padding: 14px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.rank-card .unit {
  width: 86px;
  height: 86px;
}

.rank-card strong {
  font-size: clamp(18px, 1.8vw, 24px);
}

.rank-card span {
  color: var(--muted);
  font-size: clamp(17px, 1.6vw, 22px);
  font-weight: 800;
}

.rank-card.front {
  border-left: 8px solid var(--blue);
}

.rank-card.middle {
  border-left: 8px solid var(--green);
}

.rank-card.back {
  border-left: 8px solid var(--copper);
}

.formation-note {
  padding: 18px 20px;
  border-radius: 8px;
  background: #fff8e8;
  border: 1px solid var(--line);
  color: var(--muted);
  font-weight: 900;
  font-size: clamp(17px, 1.6vw, 22px);
}

.formation-stage {
  position: relative;
  height: 560px;
  border: 1px solid var(--line);
  background:
    linear-gradient(90deg, rgba(46, 124, 151, 0.08), transparent 42%, rgba(181, 98, 63, 0.08)),
    var(--panel);
  border-radius: 8px;
  overflow: hidden;
}

.animated-diagram {
  width: 100%;
  max-width: 860px;
  aspect-ratio: 860 / 500;
  align-self: center;
  justify-self: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  object-fit: contain;
}

.formation-title {
  position: absolute;
  top: 22px;
  z-index: 3;
  color: var(--muted);
  font-weight: 900;
}

.formation-title.left {
  left: 42px;
}

.formation-title.right {
  right: 42px;
}

.stack {
  position: absolute;
  width: 230px;
  height: 380px;
  top: 86px;
}

.stack.mine {
  left: 70px;
}

.stack.enemy {
  right: 70px;
}

.single-lancer {
  top: 100px;
}

.battle-unit {
  position: absolute;
  width: 126px;
  height: 126px;
  display: grid;
  place-items: center;
}

.battle-unit img {
  max-width: 94px;
  max-height: 118px;
  z-index: 2;
  filter: drop-shadow(0 8px 10px rgba(31, 37, 35, 0.22));
}

.battle-unit::before {
  content: "";
  position: absolute;
  inset: 12px;
  border-radius: 8px;
  background: #f7efe0;
  border: 2px solid var(--line);
  box-shadow: 0 10px 24px rgba(31, 37, 35, 0.1);
}

.battle-unit span {
  position: absolute;
  left: 50%;
  bottom: -28px;
  transform: translateX(-50%);
  min-width: 132px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  font-weight: 900;
}

.stack.mine .rank-1,
.stack.enemy .rank-1 {
  top: 0;
  left: 98px;
  z-index: 5;
}

.stack.mine .rank-2,
.stack.enemy .rank-2 {
  top: 126px;
  left: 52px;
  z-index: 4;
}

.stack.mine .rank-3,
.stack.enemy .rank-3 {
  top: 252px;
  left: 6px;
  z-index: 3;
}

.stack.enemy {
  transform: scaleX(-1);
}

.stack.enemy .battle-unit {
  transform: scaleX(-1);
}

.target-front::before,
.target-back::before {
  border-color: var(--copper);
  box-shadow: 0 0 0 9px rgba(181, 98, 63, 0.18), 0 10px 24px rgba(31, 37, 35, 0.1);
}

.skipped {
  opacity: 0.45;
}

.defeated {
  opacity: 0.34;
  filter: grayscale(0.8);
}

.focus-arrows,
.ambush-arrow {
  position: absolute;
  inset: 70px 0 0 0;
  width: 100%;
  height: 440px;
  pointer-events: none;
  z-index: 2;
}

.focus-arrows path {
  fill: none;
  stroke: var(--gold);
  stroke-width: 7;
  stroke-linecap: round;
  stroke-dasharray: 16 14;
  animation: dash 1.2s linear infinite;
}

.focus-arrows .from-lanc {
  stroke: var(--green);
  animation-delay: 120ms;
}

.focus-arrows .from-mark {
  stroke: var(--copper);
  animation-delay: 240ms;
}

.focus-stage .target-front::before,
.progression-stage .target-front::before,
.target-back::before {
  animation: target-pulse 1.6s ease-in-out infinite;
}

@keyframes target-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.lane-row p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: clamp(16px, 1.5vw, 21px);
}

.battle-stage {
  position: relative;
  height: 560px;
  border: 1px solid var(--line);
  background: linear-gradient(90deg, #fffaf0 0%, #fffaf0 49.8%, #e7ded0 50%, #fffdf7 50.2%, #fffdf7 100%);
  border-radius: 8px;
  overflow: hidden;
}

.side-label {
  position: absolute;
  top: 20px;
  font-weight: 900;
  color: var(--muted);
}

.side-label.left {
  left: 28px;
}

.side-label.right {
  right: 28px;
}

.lane {
  position: absolute;
  left: 0;
  right: 0;
  height: 120px;
}

.y1 { top: 96px; }
.y2 { top: 224px; }
.y3 { top: 352px; }

.left-unit {
  position: absolute;
  left: 72px;
  top: 0;
}

.right-unit {
  position: absolute;
  right: 72px;
  top: 0;
}

.bolt {
  position: absolute;
  top: 54px;
  width: 32%;
  height: 4px;
  background: var(--gold);
  transform-origin: center;
  opacity: 0;
}

.bolt::after {
  content: "";
  position: absolute;
  right: -2px;
  top: -7px;
  border-left: 14px solid var(--gold);
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
}

.bolt.a {
  left: 190px;
  animation: shoot-right 1.8s ease-in-out infinite;
}

.bolt.b {
  right: 190px;
  transform: rotate(180deg);
  animation: shoot-left 1.8s ease-in-out infinite;
}

@keyframes shoot-right {
  0%, 18%, 100% { opacity: 0; transform: translateX(-60px) scaleX(0.25); }
  35%, 65% { opacity: 1; transform: translateX(40px) scaleX(1); }
}

@keyframes shoot-left {
  0%, 18%, 100% { opacity: 0; transform: rotate(180deg) translateX(-60px) scaleX(0.25); }
  35%, 65% { opacity: 1; transform: rotate(180deg) translateX(40px) scaleX(1); }
}

.front-note,
.ambush-badge {
  position: absolute;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  padding: 10px 14px;
  border: 1px solid var(--line);
  background: #fff8e8;
  border-radius: 8px;
  font-weight: 800;
}

.ghost-slot {
  position: absolute;
  left: 80px;
  top: 32px;
  color: var(--muted);
  font-weight: 800;
}

.ambusher {
  animation: nudge 1.8s ease-in-out infinite;
}

@keyframes nudge {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(18px); }
}

.faded {
  opacity: 0.35;
}

.target span {
  box-shadow: 0 0 0 8px rgba(181, 98, 63, 0.18), 0 8px 24px rgba(31, 37, 35, 0.22);
}

.ambush-arrow {
  position: absolute;
  inset: 70px 0 0 0;
  width: 100%;
  height: 440px;
  pointer-events: none;
  z-index: 2;
}

.ambush-arrow path {
  fill: none;
  stroke: var(--gold);
  stroke-width: 9;
  stroke-linecap: round;
  stroke-dasharray: 20 18;
  animation: dash 1.3s linear infinite;
}

.ambush-arrow polygon {
  fill: var(--gold);
}

@keyframes dash {
  to { stroke-dashoffset: -76; }
}

.formula-board,
.crowding-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: clamp(28px, 4vw, 48px);
}

.formula {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  font-size: clamp(24px, 3vw, 42px);
  font-weight: 900;
}

.formula.small {
  font-size: clamp(20px, 2vw, 30px);
}

.frac {
  display: grid;
  gap: 12px;
  text-align: center;
}

.frac i {
  font-style: normal;
  padding: 8px 18px;
}

.frac i:first-child {
  border-bottom: 3px solid var(--ink);
}

.formula-notes {
  display: grid;
  gap: 14px;
  margin-top: 34px;
}

.formula-notes p {
  margin: 0;
  color: var(--muted);
  font-size: clamp(17px, 1.55vw, 22px);
}

.crowd-bars {
  display: grid;
  gap: 20px;
  margin-top: 44px;
}

.bar-wrap {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 16px;
  align-items: center;
  font-weight: 800;
}

.bar {
  height: 38px;
  border-radius: 6px;
  background: var(--green);
  animation: grow 1.4s ease forwards;
}

.b1 { width: 28%; }
.b2 { width: 56%; background: var(--blue); }
.b3 { width: 84%; background: var(--copper); }

@keyframes grow {
  from { transform: scaleX(0.12); transform-origin: left; }
}

.caption {
  color: var(--muted);
  font-weight: 800;
}

.two-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
}

.info-panel {
  min-height: 430px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.mini-stack {
  display: grid;
  gap: 12px;
}

.mini-stack span,
.effect-strip span {
  display: block;
  padding: 12px 14px;
  background: #f3eadb;
  border-radius: 6px;
  font-weight: 900;
}

.rally {
  border-top: 8px solid var(--copper);
}

.defense {
  border-top: 8px solid var(--blue);
}

.skill-grid,
.notes-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}

.coef-diagram {
  display: grid;
  grid-template-columns: 1fr 92px 1fr;
  grid-template-rows: 1fr auto;
  align-items: center;
  gap: 18px;
}

.coef-box {
  min-height: 220px;
  display: grid;
  place-items: center;
  text-align: center;
  border-radius: 8px;
  color: white;
  font-weight: 900;
  font-size: clamp(24px, 2.4vw, 34px);
  line-height: 1.3;
}

.coef-box.attack { background: var(--green); }
.coef-box.defense { background: var(--blue); }

.coef-op {
  font-weight: 900;
  text-align: center;
  color: var(--muted);
}

.coef-result {
  grid-column: 1 / -1;
  justify-self: center;
  padding: 16px 20px;
  border-radius: 8px;
  background: #fff8e8;
  border: 1px solid var(--line);
  font-weight: 900;
}

.effect-strip {
  position: absolute;
  bottom: clamp(38px, 6vw, 76px);
  right: clamp(38px, 6vw, 76px);
  left: clamp(38px, 6vw, 76px);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  text-align: center;
}

.widget-board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
}

.widget-card {
  min-height: 300px;
}

.rally-widget {
  border-top: 8px solid var(--gold);
}

.defense-widget {
  border-top: 8px solid var(--green);
}

.widget-meter {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: auto repeat(5, 1fr) auto;
  gap: 12px;
  align-items: center;
  font-weight: 900;
}

.widget-meter i {
  height: 22px;
  border-radius: 6px;
  background: var(--gold);
  animation: meter 1.8s ease-in-out infinite;
}

.widget-meter i:nth-of-type(2) { animation-delay: 120ms; }
.widget-meter i:nth-of-type(3) { animation-delay: 240ms; }
.widget-meter i:nth-of-type(4) { animation-delay: 360ms; }
.widget-meter i:nth-of-type(5) { animation-delay: 480ms; }

@keyframes meter {
  0%, 100% { opacity: 0.42; transform: scaleY(0.7); }
  50% { opacity: 1; transform: scaleY(1); }
}

.closing-slide {
  grid-template-columns: 1fr;
  text-align: center;
}

.closing-slide .slide-copy {
  justify-self: center;
}

.closing-slide h2,
.closing-slide p {
  margin-left: auto;
  margin-right: auto;
}

.closing-equation {
  justify-self: center;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: center;
}

.closing-equation span {
  padding: 18px 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: clamp(20px, 2vw, 30px);
  font-weight: 900;
}

.closing-equation b {
  color: var(--copper);
  font-size: 34px;
}

.deck-nav {
  position: fixed;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: auto minmax(120px, 280px) auto auto;
  align-items: center;
  gap: 12px;
  padding: 10px;
  background: rgba(251, 247, 239, 0.92);
  border: 1px solid rgba(217, 208, 191, 0.86);
  border-radius: 8px;
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 32px rgba(31, 37, 35, 0.2);
}

button {
  border: 0;
  border-radius: 6px;
  padding: 11px 16px;
  background: var(--ink);
  color: white;
  font-weight: 900;
  font-size: 15px;
}

.progress {
  height: 9px;
  border-radius: 999px;
  background: #e7decf;
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  width: 8%;
  background: var(--copper);
  transition: width 220ms ease;
}

output {
  color: var(--muted);
  font-weight: 900;
  min-width: 64px;
}

@media (max-width: 820px) {
  .deck {
    width: 100vw;
    height: 100svh;
    aspect-ratio: auto;
  }

  .slide {
    grid-template-columns: 1fr;
    overflow-y: auto;
    padding: 32px 20px 96px;
  }

  .hero-scene {
    min-height: 380px;
    grid-template-columns: 1fr 96px 1fr;
  }

  .unit {
    width: 84px;
    height: 84px;
  }

  .unit b {
    font-size: 14px;
  }

  .flow-grid,
  .two-panel,
  .skill-grid,
  .notes-grid,
  .widget-board {
    grid-template-columns: 1fr;
  }

  .battle-stage {
    height: 520px;
  }

  .formation-stage {
    height: 500px;
  }

  .formation-title.left {
    left: 20px;
  }

  .formation-title.right {
    right: 20px;
  }

  .stack {
    width: 160px;
    height: 330px;
    top: 82px;
  }

  .stack.mine {
    left: 18px;
  }

  .stack.enemy {
    right: 18px;
  }

  .battle-unit {
    width: 104px;
    height: 104px;
  }

  .battle-unit img {
    max-width: 80px;
    max-height: 98px;
  }

  .battle-unit span {
    min-width: 112px;
    font-size: 12px;
    bottom: -23px;
  }

  .stack.mine .rank-1,
  .stack.enemy .rank-1 {
    left: 56px;
  }

  .stack.mine .rank-2,
  .stack.enemy .rank-2 {
    top: 112px;
    left: 28px;
  }

  .stack.mine .rank-3,
  .stack.enemy .rank-3 {
    top: 224px;
    left: 0;
  }

  .focus-arrows,
  .ambush-arrow {
    inset: 72px 0 0 0;
    height: 380px;
  }

  .front-note,
  .ambush-badge {
    bottom: 18px;
    max-width: calc(100% - 32px);
    text-align: center;
  }

  .left-unit { left: 18px; }
  .right-unit { right: 18px; }
  .bolt.a { left: 108px; }
  .bolt.b { right: 108px; }
  .effect-strip {
    position: static;
    grid-template-columns: 1fr 1fr;
    margin-top: 22px;
  }

  .deck-nav {
    width: calc(100vw - 20px);
    grid-template-columns: auto 1fr auto auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}
