:root {
  color-scheme: dark;
  --ink-950: #08141d;
  --ink-900: #102733;
  --ink-800: #163846;
  --sky-100: #d9f5f4;
  --sky-300: #8fd8df;
  --bone: #f7eccf;
  --jade: #41d8b4;
  --jade-deep: #168f86;
  --ember: #f05f5d;
  --ember-deep: #a62e42;
  --gold: #e7c66a;
  --violet: #a478ff;
  --panel: rgba(9, 25, 34, 0.88);
  --line: rgba(247, 236, 207, 0.22);
  --display: "STKaiti", "KaiTi", "FangSong", serif;
  --body: "Microsoft YaHei UI", "Microsoft YaHei", system-ui, sans-serif;
  --number: "Bahnschrift", "DIN Alternate", "Consolas", sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--ink-950);
  color: var(--bone);
  font-family: var(--body);
}

button {
  color: inherit;
  font: inherit;
}

button:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

button:not(:disabled) {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

#app,
.screen {
  width: 100%;
  height: 100%;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  overflow: hidden;
}

.screen.is-active {
  display: block;
  animation: screen-in 420ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--gold);
  font-family: var(--number);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.26em;
  text-transform: uppercase;
}

.primary-button,
.secondary-button,
.back-button,
.icon-button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 999px;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.primary-button {
  padding: 13px 34px;
  border-color: rgba(255, 245, 205, 0.72);
  background: linear-gradient(135deg, #ebcb72, #b98132);
  box-shadow: 0 12px 32px rgba(84, 50, 12, 0.32), inset 0 1px rgba(255, 255, 255, 0.46);
  color: #17222a;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.primary-button:hover,
.secondary-button:hover,
.back-button:hover,
.icon-button:hover {
  transform: translateY(-2px);
}

.primary-button--small {
  min-height: 40px;
  padding: 10px 22px;
  font-size: 13px;
}

.secondary-button,
.back-button,
.icon-button {
  border-color: var(--line);
  background: rgba(8, 20, 29, 0.52);
}

.secondary-button,
.back-button {
  padding: 10px 19px;
}

.icon-button {
  width: 42px;
  padding: 0;
  font-family: var(--display);
}

/* Splash */
.splash-screen {
  isolation: isolate;
  background:
    radial-gradient(circle at 50% 28%, rgba(255, 247, 200, 0.96) 0 5%, rgba(255, 247, 200, 0.2) 6%, transparent 18%),
    linear-gradient(180deg, #8bd8e2 0%, #d7f2ee 52%, #7fb8b1 53%, #142c36 100%);
}

.splash-screen::before,
.splash-screen::after {
  content: "";
  position: absolute;
  inset: auto -8% 0;
  height: 42%;
  background: var(--ink-900);
  clip-path: polygon(0 48%, 7% 22%, 14% 44%, 22% 5%, 30% 42%, 39% 15%, 46% 52%, 58% 8%, 66% 46%, 75% 20%, 84% 52%, 92% 10%, 100% 38%, 100% 100%, 0 100%);
  opacity: 0.38;
  z-index: -2;
}

.splash-screen::after {
  inset: auto -5% -8%;
  height: 34%;
  opacity: 0.82;
  transform: scaleX(-1);
  filter: blur(1px);
}

.sky-orbit {
  position: absolute;
  left: 50%;
  top: 30%;
  width: min(66vw, 880px);
  aspect-ratio: 1;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 52px rgba(255, 255, 255, 0.05), 0 0 0 112px rgba(255, 255, 255, 0.035);
  animation: breathe 8s ease-in-out infinite;
}

.splash-copy {
  position: absolute;
  z-index: 3;
  left: 50%;
  top: 43%;
  width: min(92vw, 760px);
  text-align: center;
  transform: translate(-50%, -50%);
  color: var(--ink-950);
}

.splash-copy .eyebrow {
  color: #775c20;
}

.splash-copy h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(64px, 10vw, 130px);
  font-weight: 900;
  letter-spacing: -0.08em;
  line-height: 0.9;
  text-shadow: 0 4px 0 rgba(255, 255, 255, 0.42);
}

.splash-copy h1 span {
  position: relative;
  color: transparent;
  -webkit-text-stroke: 2px var(--ink-950);
}

.splash-copy h1 span::after {
  content: "";
  position: absolute;
  left: 4%;
  right: 4%;
  bottom: 9%;
  height: 10%;
  background: var(--ember);
  z-index: -1;
  transform: skewX(-14deg);
}

.splash-lead {
  margin: 22px auto 24px;
  font-size: clamp(15px, 2vw, 20px);
  letter-spacing: 0.16em;
}

.micro-copy {
  margin-top: 15px;
  font-size: 11px;
  color: rgba(8, 20, 29, 0.64);
}

.splash-beasts > div {
  position: absolute;
  z-index: 1;
  bottom: 5%;
  width: min(35vw, 460px);
  height: min(31vw, 370px);
  background: var(--ink-950);
  filter: drop-shadow(0 0 24px rgba(66, 215, 180, 0.42));
}

.beast-shadow--left {
  left: -2%;
  clip-path: polygon(4% 74%, 16% 60%, 10% 38%, 25% 48%, 30% 22%, 38% 44%, 58% 34%, 77% 42%, 96% 64%, 76% 60%, 64% 76%, 42% 69%, 29% 92%, 25% 70%);
  animation: beast-idle 4s ease-in-out infinite;
}

.beast-shadow--right {
  right: -2%;
  clip-path: polygon(4% 64%, 23% 42%, 40% 34%, 54% 45%, 64% 18%, 70% 44%, 87% 34%, 81% 57%, 98% 76%, 70% 68%, 63% 90%, 50% 67%, 28% 77%);
  transform: scaleX(-1);
  animation: beast-idle 4.5s 800ms ease-in-out infinite;
}

/* Shared header and home */
.home-screen,
.panel-screen {
  background:
    linear-gradient(rgba(11, 34, 43, 0.06), rgba(11, 34, 43, 0.38)),
    radial-gradient(circle at 50% 18%, #dff8f4, #90d6d7 42%, #315f69 74%, #0a1b25 100%);
}

.game-header,
.panel-header {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 20px;
  width: 100%;
  min-height: 74px;
  padding: calc(12px + var(--safe-top)) clamp(18px, 3vw, 44px) 12px;
  border-bottom: 1px solid rgba(247, 236, 207, 0.14);
  background: linear-gradient(180deg, rgba(8, 20, 29, 0.88), rgba(8, 20, 29, 0.42));
  backdrop-filter: blur(16px);
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-right: auto;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
}

.brand-mark b,
.brand-mark small {
  display: block;
}

.brand-mark b {
  font-family: var(--display);
  font-size: 19px;
  letter-spacing: 0.12em;
}

.brand-mark small {
  margin-top: 1px;
  color: rgba(247, 236, 207, 0.55);
  font-size: 10px;
}

.brand-sigil {
  display: grid;
  width: 43px;
  height: 43px;
  place-items: center;
  border: 1px solid var(--gold);
  background: rgba(231, 198, 106, 0.12);
  clip-path: polygon(50% 0, 100% 25%, 92% 82%, 50% 100%, 8% 82%, 0 25%);
  color: var(--gold);
  font-family: var(--display);
  font-size: 22px;
}

.resource-strip {
  display: flex;
  gap: 22px;
  font-family: var(--number);
  font-size: 12px;
}

.resource-strip span {
  display: flex;
  align-items: center;
  gap: 7px;
}

.resource-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  box-shadow: 0 0 12px currentColor;
}

.resource-dot--jade { color: var(--jade); background: currentColor; }
.resource-dot--gold { color: var(--gold); background: currentColor; }
.resource-dot--red { color: var(--ember); background: currentColor; }

.home-copy {
  position: absolute;
  z-index: 4;
  left: clamp(22px, 5vw, 74px);
  top: clamp(98px, 16vh, 154px);
  width: min(34vw, 430px);
  color: var(--ink-950);
}

.home-copy .eyebrow { color: #6b5522; }
.home-copy h2 {
  margin: 0 0 10px;
  font-family: var(--display);
  font-size: clamp(30px, 4vw, 56px);
  line-height: 1.06;
}
.home-copy p:last-child { max-width: 360px; color: rgba(8, 20, 29, 0.68); line-height: 1.7; }

.island-map {
  position: absolute;
  left: 50%;
  top: 54%;
  width: min(72vw, 920px);
  height: min(64vh, 590px);
  transform: translate(-40%, -50%);
}

.island-map::before,
.island-map::after {
  content: "";
  position: absolute;
  z-index: -2;
  left: 50%;
  top: 53%;
  width: 76%;
  height: 52%;
  transform: translate(-50%, -50%);
  border: 3px solid rgba(230, 247, 235, 0.7);
  border-radius: 48% 52% 48% 52% / 42% 43% 57% 58%;
  background:
    radial-gradient(circle at 46% 42%, rgba(255, 246, 191, 0.45), transparent 26%),
    linear-gradient(135deg, #6fa75b, #a8c867 48%, #5c8c55);
  box-shadow: inset 0 -22px 0 rgba(26, 66, 62, 0.35), 0 35px 42px rgba(4, 20, 24, 0.34);
}

.island-map::after {
  z-index: -3;
  top: 67%;
  width: 62%;
  height: 30%;
  border: 0;
  border-radius: 0;
  clip-path: polygon(2% 0, 98% 0, 82% 63%, 65% 70%, 53% 100%, 39% 72%, 18% 61%);
  background: linear-gradient(180deg, #31534f, #102731);
}

.island-core {
  position: absolute;
  left: 48%;
  top: 51%;
  width: 170px;
  height: 170px;
  transform: translate(-50%, -50%);
}

.island-ring {
  position: absolute;
  inset: 22%;
  border: 2px solid rgba(255, 247, 195, 0.85);
  border-radius: 50%;
  animation: orbit 13s linear infinite;
}

.island-ring::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -6px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--jade);
  box-shadow: 0 0 18px var(--jade);
}

.island-ring--two {
  inset: 4%;
  opacity: 0.46;
  animation-direction: reverse;
  animation-duration: 20s;
}

.island-crystal {
  position: absolute;
  left: 50%;
  top: 49%;
  width: 48px;
  height: 72px;
  background: linear-gradient(135deg, #efffcc, var(--jade) 45%, #147b80);
  clip-path: polygon(50% 0, 100% 34%, 77% 100%, 20% 88%, 0 30%);
  filter: drop-shadow(0 0 18px rgba(65, 216, 180, 0.7));
  transform: translate(-50%, -50%);
  animation: float 3s ease-in-out infinite;
}

.building {
  position: absolute;
  display: grid;
  grid-template-columns: 58px auto;
  grid-template-rows: auto auto;
  align-items: center;
  min-width: 188px;
  padding: 12px 15px 12px 11px;
  border: 1px solid rgba(247, 236, 207, 0.36);
  border-radius: 18px 8px 18px 8px;
  background: rgba(10, 31, 38, 0.88);
  box-shadow: 0 14px 28px rgba(4, 19, 24, 0.28);
  text-align: left;
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
}

.building:hover {
  z-index: 3;
  border-color: var(--gold);
  box-shadow: 0 18px 38px rgba(4, 19, 24, 0.42), 0 0 22px rgba(231, 198, 106, 0.2);
  transform: translateY(-6px);
}

.building-icon {
  grid-row: 1 / 3;
  display: grid;
  width: 45px;
  height: 52px;
  place-items: center;
  background: linear-gradient(145deg, rgba(65, 216, 180, 0.3), rgba(65, 216, 180, 0.05));
  clip-path: polygon(50% 0, 100% 25%, 87% 100%, 13% 100%, 0 25%);
  color: var(--gold);
  font-family: var(--display);
  font-size: 20px;
}

.building b { font-family: var(--display); font-size: 17px; letter-spacing: 0.08em; }
.building small { margin-top: 3px; color: rgba(247, 236, 207, 0.55); font-size: 10px; }
.building--monsters { left: 2%; top: 34%; }
.building--gods { right: 1%; top: 24%; }
.building--formation { left: 12%; bottom: 12%; }
.building--battle { right: 4%; bottom: 9%; border-color: rgba(240, 95, 93, 0.65); }
.building--battle .building-icon { background: linear-gradient(145deg, rgba(240, 95, 93, 0.52), rgba(166, 46, 66, 0.15)); }

.bottom-nav {
  position: absolute;
  z-index: 12;
  left: 50%;
  bottom: calc(18px + var(--safe-bottom));
  display: flex;
  gap: 5px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(8, 20, 29, 0.88);
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(16px);
  transform: translateX(-50%);
}

.bottom-nav button {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 17px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  font-size: 12px;
}

.bottom-nav button:hover { background: rgba(255, 255, 255, 0.08); }
.bottom-nav__battle { background: rgba(240, 95, 93, 0.18) !important; color: #ffd4c5; }
.bottom-nav button span { color: var(--gold); font-size: 17px; }

/* Collection panels */
.panel-screen {
  padding-bottom: max(20px, var(--safe-bottom));
}

.panel-screen::before {
  content: "";
  position: absolute;
  inset: 74px 0 0;
  background: linear-gradient(150deg, rgba(8, 20, 29, 0.36), rgba(8, 20, 29, 0.78));
}

.panel-header {
  justify-content: space-between;
}

.panel-header h2 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(22px, 2.6vw, 34px);
  letter-spacing: 0.06em;
}

.panel-header > div:nth-child(2) { margin-right: auto; }
.panel-header .eyebrow { margin-bottom: 2px; }
.header-note { max-width: 250px; color: rgba(247, 236, 207, 0.62); font-size: 12px; text-align: right; }

.segmented {
  display: flex;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.22);
}

.segmented button {
  min-width: 74px;
  padding: 8px 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: rgba(247, 236, 207, 0.6);
}

.segmented button.is-active {
  background: var(--bone);
  color: var(--ink-950);
  font-weight: 800;
}

.archive-layout,
.god-layout {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(430px, 1.2fr) minmax(330px, 0.8fr);
  gap: 20px;
  height: calc(100% - 92px);
  padding: 22px clamp(20px, 3vw, 44px);
}

.monster-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(210px, 1fr));
  align-content: start;
  gap: 12px;
  overflow-y: auto;
  padding-right: 5px;
}

.monster-card {
  display: grid;
  grid-template-columns: 96px 1fr;
  min-height: 134px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 20px 7px 20px 7px;
  background: rgba(7, 24, 32, 0.68);
  text-align: left;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.monster-card:hover,
.monster-card.is-selected {
  border-color: var(--team-color, var(--jade));
  background: rgba(7, 24, 32, 0.92);
  transform: translateY(-3px);
}

.portrait-canvas {
  width: 88px;
  height: 104px;
  border-radius: 16px 4px 16px 4px;
  background: radial-gradient(circle at 50% 45%, color-mix(in srgb, var(--team-color, var(--jade)) 25%, transparent), transparent 70%);
}

.monster-card h3 {
  margin: 6px 0 2px;
  font-family: var(--display);
  font-size: 19px;
  letter-spacing: 0.06em;
}

.monster-card p { margin: 0 0 9px; color: rgba(247, 236, 207, 0.55); font-size: 11px; }
.mini-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 5px 10px; font: 11px var(--number); color: rgba(247, 236, 207, 0.78); }
.mini-stats b { color: var(--bone); }

.detail-panel {
  min-width: 0;
  overflow-y: auto;
  padding: clamp(18px, 2.5vw, 30px);
  border: 1px solid var(--line);
  border-radius: 26px 8px 26px 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.035), transparent 30%),
    var(--panel);
  box-shadow: 0 22px 46px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(20px);
}

.detail-hero {
  display: flex;
  align-items: center;
  gap: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.detail-hero canvas {
  width: 118px;
  height: 118px;
  flex: 0 0 118px;
  border: 1px solid color-mix(in srgb, var(--detail-color) 54%, transparent);
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--detail-color) 20%, transparent), transparent 67%);
}

.detail-hero h3 { margin: 2px 0 5px; font: 29px var(--display); letter-spacing: 0.06em; }
.role-chip { display: inline-flex; padding: 5px 10px; border-radius: 999px; background: color-mix(in srgb, var(--detail-color) 22%, transparent); color: var(--detail-color); font-size: 11px; font-weight: 800; }
.detail-hero p { margin: 8px 0 0; color: rgba(247, 236, 207, 0.6); font-size: 12px; line-height: 1.6; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 18px 0;
}

.stat-tile {
  padding: 11px 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px 4px 12px 4px;
  background: rgba(255, 255, 255, 0.04);
}

.stat-tile span,
.stat-tile b { display: block; }
.stat-tile span { color: rgba(247, 236, 207, 0.48); font-size: 10px; }
.stat-tile b { margin-top: 3px; font: 20px var(--number); }

.skill-list { display: grid; gap: 8px; }
.skill-item { padding: 12px 14px; border-left: 3px solid var(--detail-color); background: rgba(255, 255, 255, 0.035); }
.skill-item header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.skill-item b { font: 16px var(--display); letter-spacing: 0.05em; }
.skill-item em { color: var(--detail-color); font-size: 10px; font-style: normal; }
.skill-item p { margin: 5px 0 0; color: rgba(247, 236, 207, 0.63); font-size: 11px; line-height: 1.55; }

/* Gods */
.god-layout {
  grid-template-columns: minmax(430px, 0.95fr) minmax(400px, 1.05fr);
}

.god-orbit {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-content: center;
  gap: 14px;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 50% 20% 50% 20% / 30% 50% 30% 50%;
  background: radial-gradient(circle, rgba(67, 170, 167, 0.16), rgba(8, 20, 29, 0.72) 62%);
  overflow: hidden;
}

.god-orbit::before,
.god-orbit::after {
  content: "";
  position: absolute;
  inset: 14%;
  border: 1px dashed rgba(143, 216, 223, 0.22);
  border-radius: 50%;
  animation: orbit 60s linear infinite;
  pointer-events: none;
}
.god-orbit::after { inset: 32%; animation-direction: reverse; }

.god-card {
  position: relative;
  z-index: 1;
  min-height: 118px;
  padding: 14px;
  border: 1px solid color-mix(in srgb, var(--god-color) 38%, transparent);
  border-radius: 18px 5px 18px 5px;
  background: rgba(8, 20, 29, 0.78);
  text-align: left;
  transition: transform 160ms ease, background 160ms ease;
}

.god-card:hover,
.god-card.is-selected {
  transform: translateY(-4px);
  background: color-mix(in srgb, var(--god-color) 14%, rgba(8, 20, 29, 0.92));
}

.god-card.is-selected::after {
  content: "";
  position: absolute;
  inset: -3px;
  border: 1px solid var(--god-color);
  border-radius: inherit;
  opacity: 0.72;
}

.god-sigil {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--god-color);
  border-radius: 50%;
  box-shadow: 0 0 18px color-mix(in srgb, var(--god-color) 45%, transparent);
  color: var(--god-color);
  font: 23px var(--display);
}

.god-card b { display: block; margin-top: 8px; font: 17px var(--display); }
.god-card small { color: rgba(247, 236, 207, 0.48); font-size: 10px; }

.god-detail .detail-hero { align-items: flex-start; }
.large-sigil { display: grid; width: 94px; height: 94px; flex: 0 0 94px; place-items: center; border: 1px solid var(--detail-color); border-radius: 50%; color: var(--detail-color); font: 46px var(--display); box-shadow: inset 0 0 30px color-mix(in srgb, var(--detail-color) 18%, transparent), 0 0 28px color-mix(in srgb, var(--detail-color) 16%, transparent); }
.god-meta { display: flex; gap: 10px; margin-top: 8px; font: 11px var(--number); color: rgba(247, 236, 207, 0.6); }
.tier-control { margin: 18px 0; }
.tier-control > span { display: block; margin-bottom: 8px; color: rgba(247, 236, 207, 0.55); font-size: 11px; }
.tier-buttons { display: flex; flex-wrap: wrap; gap: 7px; }
.tier-buttons button { min-width: 46px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 999px; background: rgba(255, 255, 255, 0.04); font: 11px var(--number); }
.tier-buttons button.is-active { border-color: var(--detail-color); background: color-mix(in srgb, var(--detail-color) 22%, transparent); color: var(--bone); }
.tier-list { display: grid; gap: 7px; margin-top: 14px; }
.tier-row { display: grid; grid-template-columns: 42px 1fr; gap: 10px; padding: 9px 11px; border: 1px solid rgba(255, 255, 255, 0.07); border-radius: 11px 4px 11px 4px; color: rgba(247, 236, 207, 0.44); font-size: 11px; line-height: 1.45; }
.tier-row.is-unlocked { color: rgba(247, 236, 207, 0.86); background: rgba(255, 255, 255, 0.035); }
.tier-row b { color: var(--detail-color); font: 12px var(--number); }

/* Formation */
.formation-board {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-rows: 1fr auto 0.72fr;
  gap: 13px;
  height: calc(100% - 130px);
  margin: 20px clamp(28px, 6vw, 100px) 0;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 30px 10px 30px 10px;
  background: rgba(7, 24, 32, 0.74);
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.22);
}

.formation-lane,
.enemy-preview {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.formation-slot,
.enemy-slot {
  position: relative;
  display: grid;
  grid-template-rows: 1fr auto;
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 20px 6px 20px 6px;
  background: rgba(255, 255, 255, 0.035);
  text-align: center;
}

.formation-slot canvas,
.enemy-slot canvas { width: 100%; min-height: 80px; max-height: 128px; }
.formation-slot b,
.enemy-slot b { font: 15px var(--display); }
.formation-order { position: absolute; left: 9px; top: 8px; color: var(--jade); font: 11px var(--number); }
.formation-actions { display: flex; justify-content: center; gap: 5px; margin-top: 7px; }
.formation-actions button { width: 34px; height: 28px; border: 1px solid var(--line); border-radius: 999px; background: rgba(255, 255, 255, 0.06); }
.formation-actions button:disabled { opacity: 0.22; }
.formation-guide { display: grid; grid-template-columns: auto 1fr auto 1fr auto; align-items: center; gap: 10px; color: rgba(247, 236, 207, 0.48); font-size: 10px; }
.formation-guide i { height: 1px; background: linear-gradient(90deg, transparent, var(--gold), transparent); }
.formation-guide strong { color: var(--gold); font-size: 11px; letter-spacing: 0.12em; }
.enemy-preview { opacity: 0.78; }
.enemy-slot { grid-template-rows: 1fr auto; padding: 5px 8px; border-color: rgba(240, 95, 93, 0.2); }
.enemy-slot canvas { min-height: 54px; max-height: 82px; }
.formation-help { position: relative; z-index: 2; margin: 12px auto; text-align: center; color: rgba(247, 236, 207, 0.56); font-size: 11px; }

/* Battle */
.battle-screen {
  background: var(--ink-950);
}

.battle-shell {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(100vw, calc(100vh * 16 / 9));
  aspect-ratio: 16 / 9;
  transform: translate(-50%, -50%);
  overflow: hidden;
  background: #98dadd;
  box-shadow: 0 0 90px rgba(0, 0, 0, 0.55);
}

#battle-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.battle-topbar {
  position: absolute;
  z-index: 4;
  left: 0;
  right: 0;
  top: 0;
  display: grid;
  grid-template-columns: 1fr 150px 1fr;
  align-items: start;
  padding: 14px 24px;
  pointer-events: none;
}

.team-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 42px;
  padding: 0 16px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 12px 3px 12px 3px;
  background: linear-gradient(90deg, rgba(15, 84, 83, 0.92), rgba(8, 20, 29, 0.66));
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.2);
  font-size: 12px;
}

.team-summary--enemy { background: linear-gradient(270deg, rgba(146, 42, 55, 0.92), rgba(8, 20, 29, 0.66)); }
.team-summary b { font: 17px var(--display); letter-spacing: 0.12em; }
.team-summary span { font: 13px var(--number); }
.battle-clock { text-align: center; text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6); }
.battle-clock span { display: block; font: 26px var(--number); }
.battle-clock small { color: rgba(247, 236, 207, 0.7); font-size: 9px; letter-spacing: 0.18em; }

.battle-controls {
  position: absolute;
  z-index: 5;
  left: 18px;
  bottom: 86px;
  display: flex;
  gap: 6px;
}

.battle-controls button {
  min-width: 48px;
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 10px 3px 10px 3px;
  background: rgba(8, 20, 29, 0.82);
  font-size: 10px;
}

.god-console {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: 10px;
  display: grid;
  grid-template-columns: 94px auto;
  gap: 10px;
  align-items: end;
  width: min(83%, 1020px);
  transform: translateX(-50%);
}

.spirit-meter {
  padding: 9px;
  border: 1px solid rgba(231, 198, 106, 0.42);
  border-radius: 12px 4px 12px 4px;
  background: rgba(8, 20, 29, 0.9);
  text-align: center;
}

.spirit-meter span { display: block; color: var(--gold); font-size: 9px; letter-spacing: 0.18em; }
.spirit-meter b { display: block; font: 18px var(--number); }
.spirit-meter i { display: block; height: 4px; margin-top: 5px; border-radius: 999px; overflow: hidden; background: rgba(255, 255, 255, 0.1); }
.spirit-meter em { display: block; width: 55%; height: 100%; background: linear-gradient(90deg, var(--violet), var(--gold)); box-shadow: 0 0 9px var(--gold); transition: width 120ms linear; }

.god-hand {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 7px;
}

.battle-god {
  position: relative;
  min-width: 0;
  height: 66px;
  padding: 6px 4px;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--god-color) 48%, transparent);
  border-radius: 13px 4px 13px 4px;
  background: rgba(8, 20, 29, 0.91);
  text-align: center;
}

.battle-god:hover:not(:disabled) { transform: translateY(-4px); box-shadow: 0 0 18px color-mix(in srgb, var(--god-color) 36%, transparent); }
.battle-god:disabled { filter: grayscale(0.72); opacity: 0.72; }
.battle-god strong { position: relative; z-index: 2; display: block; color: var(--god-color); font: 20px var(--display); }
.battle-god b { position: relative; z-index: 2; display: block; margin-top: 1px; font-size: 10px; }
.battle-god small { position: relative; z-index: 2; color: rgba(247, 236, 207, 0.55); font: 8px var(--number); }
.battle-god .key { position: absolute; z-index: 3; left: 4px; top: 3px; color: rgba(255, 255, 255, 0.52); font: 8px var(--number); }
.cooldown-shade { position: absolute; z-index: 1; inset: 0; background: rgba(3, 8, 12, 0.78); transform-origin: bottom; transform: scaleY(0); }
.cooldown-text { position: absolute; z-index: 4; inset: 0; display: grid; place-items: center; color: white; font: 17px var(--number); text-shadow: 0 2px 5px #000; }

.cast-banner {
  position: absolute;
  z-index: 7;
  left: 50%;
  top: 18%;
  display: grid;
  grid-template-columns: 42px auto;
  grid-template-rows: auto auto;
  align-items: center;
  min-width: 280px;
  padding: 10px 28px 10px 14px;
  border-left: 4px solid var(--cast-color, var(--gold));
  background: linear-gradient(90deg, rgba(8, 20, 29, 0.96), rgba(8, 20, 29, 0.42), transparent);
  opacity: 0;
  pointer-events: none;
  transform: translate(-38%, -16px);
}

.cast-banner.is-visible { animation: banner-in 1.8s ease both; }
.cast-banner span { grid-row: 1 / 3; display: grid; width: 34px; height: 34px; place-items: center; border: 1px solid var(--cast-color, var(--gold)); border-radius: 50%; color: var(--cast-color, var(--gold)); font: 21px var(--display); }
.cast-banner b { font: 23px var(--display); letter-spacing: 0.08em; }
.cast-banner small { color: rgba(247, 236, 207, 0.68); font-size: 9px; letter-spacing: 0.12em; }

.unit-inspector {
  position: absolute;
  z-index: 8;
  right: 16px;
  bottom: 88px;
  width: 210px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px 4px 14px 4px;
  background: rgba(8, 20, 29, 0.9);
  pointer-events: none;
}
.unit-inspector h4 { margin: 0 0 5px; font: 16px var(--display); }
.unit-inspector p { margin: 4px 0; color: rgba(247, 236, 207, 0.66); font: 9px var(--number); }

.result-overlay {
  position: absolute;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(4, 13, 19, 0.7);
  backdrop-filter: blur(7px);
}

.result-overlay[hidden],
.unit-inspector[hidden] { display: none; }

.result-card {
  width: min(88vw, 590px);
  padding: 34px;
  border: 1px solid rgba(231, 198, 106, 0.5);
  border-radius: 28px 8px 28px 8px;
  background: linear-gradient(135deg, rgba(26, 56, 70, 0.96), rgba(8, 20, 29, 0.98));
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.55);
  text-align: center;
}

.result-card h3 { margin: 0; color: var(--gold); font: clamp(52px, 8vw, 82px) var(--display); letter-spacing: 0.12em; }
.result-card > p:not(.eyebrow) { color: rgba(247, 236, 207, 0.66); font-size: 13px; }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 20px 0; }
.result-stats div { padding: 11px; border: 1px solid var(--line); border-radius: 12px 4px 12px 4px; }
.result-stats span,
.result-stats b { display: block; }
.result-stats span { color: rgba(247, 236, 207, 0.48); font-size: 9px; }
.result-stats b { margin-top: 4px; font: 19px var(--number); }
.result-actions { display: flex; justify-content: center; gap: 10px; }

.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: 26px;
  max-width: min(90vw, 520px);
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(8, 20, 29, 0.94);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 180ms ease, transform 180ms ease;
  font-size: 12px;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

.rotate-hint {
  display: none;
  position: fixed;
  z-index: 200;
  inset: 0;
  place-items: center;
  padding: 30px;
  background: var(--ink-950);
  color: var(--bone);
  text-align: center;
}

/* Motion */
@keyframes screen-in { from { opacity: 0; transform: scale(1.015); } to { opacity: 1; transform: scale(1); } }
@keyframes breathe { 50% { transform: translate(-50%, -50%) scale(1.035); opacity: 0.72; } }
@keyframes beast-idle { 50% { translate: 0 -7px; } }
@keyframes float { 50% { transform: translate(-50%, -57%) rotate(2deg); } }
@keyframes orbit { to { transform: rotate(360deg); } }
@keyframes banner-in {
  0% { opacity: 0; transform: translate(-38%, -18px); }
  14%, 72% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-56%, 5px); }
}

@media (max-width: 900px) {
  .resource-strip { display: none; }
  .home-copy { top: 100px; width: 42vw; }
  .home-copy p:last-child { display: none; }
  .island-map { width: 82vw; transform: translate(-44%, -48%); }
  .building { min-width: 156px; grid-template-columns: 46px auto; padding: 9px; }
  .building-icon { width: 38px; height: 44px; }
  .building small { display: none; }
  .archive-layout,
  .god-layout { grid-template-columns: 1fr 0.88fr; gap: 12px; padding: 14px; }
  .monster-grid { grid-template-columns: 1fr; }
  .monster-card { min-height: 108px; grid-template-columns: 78px 1fr; }
  .portrait-canvas { width: 70px; height: 82px; }
  .god-orbit { padding: 14px; gap: 8px; }
  .god-card { min-height: 90px; padding: 9px; }
  .god-sigil { width: 35px; height: 35px; font-size: 18px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (orientation: portrait) and (max-width: 720px) {
  .rotate-hint { display: grid; }
}

@media (max-height: 620px) {
  .game-header,
  .panel-header { min-height: 60px; padding-top: calc(7px + var(--safe-top)); padding-bottom: 7px; }
  .home-copy { top: 76px; }
  .home-copy h2 { font-size: 30px; }
  .island-map { top: 51%; height: 74vh; }
  .bottom-nav { bottom: 9px; }
  .archive-layout,
  .god-layout { height: calc(100% - 66px); padding-top: 10px; }
  .panel-header h2 { font-size: 22px; }
  .panel-header .eyebrow { display: none; }
  .detail-panel { padding: 15px; }
  .detail-hero canvas { width: 82px; height: 82px; flex-basis: 82px; }
  .detail-hero h3 { font-size: 22px; }
  .stat-grid { margin: 10px 0; }
  .skill-item { padding: 8px 10px; }
  .formation-board { height: calc(100% - 92px); margin-top: 10px; padding: 10px; }
  .formation-help { display: none; }
}

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