/* Shared application foundation. Battle-only rules live in styles/battle.css. */

:root {
  color-scheme: dark;
  --ink: #24231f;
  --ink-soft: #5b584e;
  --paper: #d8d2bd;
  --paper-light: #eee9d8;
  --paper-dark: #b8b29f;
  --metal: #aaa99d;
  --metal-dark: #77766d;
  --frame-light: #f7f3e3;
  --frame-mid: #8e8b7f;
  --frame-dark: #4f4d46;
  --navy: #35444f;
  --navy-deep: #202b32;
  --gold: #b38a3e;
  --gold-light: #e1c277;
  --link: #24477f;
  --link-hover: #142b51;
  --health: #4b7d4f;
  --health-dark: #294f2f;
  --enemy: #913b32;
  --enemy-dark: #5e241f;
  --danger: #a13830;
  --safe-top: max(8px, env(safe-area-inset-top));
  --safe-right: max(8px, env(safe-area-inset-right));
  --safe-bottom: max(8px, env(safe-area-inset-bottom));
  --safe-left: max(8px, env(safe-area-inset-left));
  --mono: "Courier New", Courier, monospace;
  /* Shared game-facing design tokens. Legacy paper tokens above remain only as
     fallbacks for battle components that have not yet been migrated. */
  --game-coal: #101212;
  --game-coal-deep: #090b0b;
  --game-panel: rgba(25, 25, 23, 0.96);
  --game-panel-top: rgba(43, 39, 33, 0.96);
  --game-brass: #b89552;
  --game-brass-bright: #e3ca88;
  --game-teal: #68a5a0;
  --game-copper: #c66e5d;
  --game-parchment: #f5ead3;
  --game-muted: #b9ad96;
  --game-line: rgba(226, 199, 136, 0.24);
  --game-display: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --game-ui: "Avenir Next", "Segoe UI", sans-serif;
  --ui: var(--game-ui);
  --title: var(--game-display);
  --game-radius-control: 5px;
  --game-radius-panel: 8px;
  --game-control-height: 46px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  color: var(--ink);
  background: #202524;
  font-family: var(--ui);
  font-size: 13px;
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  background:
    repeating-linear-gradient(0deg, rgb(255 255 255 / 2%) 0 1px, transparent 1px 4px),
    repeating-linear-gradient(90deg, transparent 0 23px, rgb(0 0 0 / 4%) 23px 24px),
    #202524;
}

button,
input {
  font: inherit;
}

button,
a,
label,
summary {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 2px dotted #111;
  outline-offset: 2px;
}

.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;
}

.ambient-track {
  display: none;
}

.mini-app-shell {
  position: relative;
  width: min(100%, 470px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  background:
    repeating-linear-gradient(0deg, rgb(74 68 51 / 3%) 0 1px, transparent 1px 3px),
    var(--paper);
  border-inline: 2px solid var(--frame-dark);
  box-shadow: 0 0 0 1px #171b1d, 0 12px 45px rgb(0 0 0 / 40%);
}

.app-header {
  min-height: 48px;
  padding: var(--safe-top) var(--safe-right) 6px var(--safe-left);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: #f5f0df;
  background:
    linear-gradient(180deg, #56636a 0, #35444f 14%, #2a3841 75%, #1d2930 100%);
  border-top: 1px solid #89949a;
  border-bottom: 2px solid var(--gold);
  box-shadow: inset 0 -1px #11191e;
}

.brand {
  min-width: 0;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: inherit;
  text-decoration: none;
}

.brand__mark {
  width: 28px;
  height: 28px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: end;
  gap: 1px;
  padding: 3px;
  background: #262f34;
  border: 1px solid #171e22;
  box-shadow: inset 1px 1px #78858b, inset -1px -1px #11171a;
}

.brand__mark i {
  height: 14px;
  border: 1px solid var(--gold-light);
  background: #786239;
}

.brand__mark i:nth-child(2) {
  height: 20px;
}

.brand b {
  display: block;
  font-family: var(--title);
  font-size: 17px;
  line-height: 1;
  letter-spacing: 0.04em;
  text-shadow: 1px 1px #111;
}

.brand small {
  display: block;
  margin-top: 3px;
  color: #c9c7ba;
  font-family: var(--ui);
  font-size: 9px;
}

.connection-chip {
  min-height: 28px;
  padding: 5px 7px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: #fff0e7;
  background: #67312c;
  border: 1px solid #321815;
  box-shadow: inset 1px 1px #a8655d, inset -1px -1px #321815;
  font-size: 9px;
  font-weight: 700;
}

.connection-chip > span {
  width: 7px;
  height: 7px;
  background: #df6b5e;
  border: 1px solid #411f1b;
}

.connection-chip b {
  font: inherit;
}

.connection-chip--waiting {
  color: #fff2c9;
  background: #5c4a27;
  border-color: #2e2514;
  box-shadow: inset 1px 1px #9b8247, inset -1px -1px #2e2514;
}

.connection-chip--waiting > span {
  background: var(--gold-light);
  border-color: #59451f;
  animation: search-pulse 900ms steps(2, end) infinite;
}

.app-main {
  min-width: 0;
  padding: 8px var(--safe-right) 12px var(--safe-left);
}

.app-main:focus {
  outline: none;
}

.screen {
  min-height: calc(100dvh - 70px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: screen-in 120ms steps(2, end) both;
}

@keyframes screen-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.screen-heading {
  padding: 8px 9px;
  background: rgb(238 233 216 / 75%);
  border: 1px solid var(--frame-mid);
  box-shadow:
    inset 1px 1px var(--frame-light),
    inset -1px -1px var(--frame-dark);
}

.screen-heading--center {
  text-align: center;
}

.screen-heading h1,
.screen-heading h2 {
  margin: 0;
  font-family: var(--title);
  font-size: clamp(21px, 6vw, 27px);
  line-height: 1.05;
  font-weight: 700;
  color: #25241f;
}

.screen-heading > p:last-child {
  max-width: 35em;
  margin: 6px auto 0;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.4;
}

.eyebrow {
  margin: 0 0 4px;
  color: #584a2d;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.field-label,
.mark-choice legend {
  display: block;
  margin-bottom: 4px;
  font-size: 11px;
  font-weight: 700;
}

.field-help,
.form-error {
  margin: 3px 0 0;
  font-size: 10px;
  color: var(--ink-soft);
}

.form-error {
  color: var(--danger);
  font-weight: 700;
}

.text-input {
  width: 100%;
  min-height: 42px;
  padding: 8px 9px;
  font-size: 16px;
  color: var(--ink);
  background: #fffef7;
  border: 1px solid var(--frame-dark);
  border-radius: 0;
  box-shadow: inset 1px 1px 2px rgb(0 0 0 / 28%), inset -1px -1px #fff;
}

.text-input::placeholder {
  color: #898477;
}

.text-input[aria-invalid="true"] {
  border-color: var(--danger);
  background: #fff0ed;
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid var(--frame-dark);
  border-radius: 0;
  font-weight: 700;
  cursor: pointer;
  box-shadow:
    inset 1px 1px var(--frame-light),
    inset -2px -2px var(--frame-dark);
}

.primary-button {
  color: #181713;
  background: linear-gradient(#dfca94, #b79b5f);
  border-color: #554728;
}

.primary-button:hover {
  background: linear-gradient(#ead9aa, #c7ab6a);
}

.primary-button:active {
  padding-top: 10px;
  padding-bottom: 8px;
  box-shadow: inset 2px 2px #6e5a30, inset -1px -1px #f5e7c3;
}

.primary-button:disabled {
  color: #777267;
  background: #c5c2b5;
  border-color: #8f8b80;
  cursor: not-allowed;
  box-shadow: inset 1px 1px #e8e5da, inset -1px -1px #7e7a70;
}

.secondary-button {
  color: var(--link);
  background: #d4d1c4;
}

.secondary-button:hover {
  color: var(--link-hover);
  text-decoration: underline;
}

.danger-button {
  color: #fff5e9;
  background: #843c34;
  border-color: #431c18;
  box-shadow: inset 1px 1px #bd766b, inset -2px -2px #421b17;
}

.text-button {
  min-height: 36px;
  padding: 5px 8px;
  color: var(--link);
  background: transparent;
  border: 0;
  text-decoration: underline;
  cursor: pointer;
}

.app-footer {
  padding: 4px var(--safe-right) var(--safe-bottom) var(--safe-left);
  text-align: center;
  background: var(--paper-dark);
  border-top: 1px solid var(--frame-dark);
  box-shadow: inset 0 1px var(--frame-light);
}

.action-stack {
  margin-top: auto;
  display: grid;
  gap: 5px;
}

/* Arrival */

.arrival-screen {
  justify-content: flex-start;
}

.arrival-art {
  position: relative;
  height: 128px;
  overflow: hidden;
  background:
    linear-gradient(180deg, #6e7e83 0 54%, #756c57 54% 70%, #514a3c 70%);
  border: 1px solid var(--frame-dark);
  box-shadow:
    inset 1px 1px #b8c1c0,
    inset -1px -1px #242a2b;
}

.arrival-sky {
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(105deg, transparent 0 36px, rgb(255 255 255 / 8%) 36px 37px),
    linear-gradient(180deg, rgb(255 255 255 / 6%), transparent);
}

.arrival-sky i {
  position: absolute;
  width: 3px;
  height: 3px;
  background: #d1c9a8;
}

.arrival-sky i:nth-child(1) { top: 18px; left: 20%; }
.arrival-sky i:nth-child(2) { top: 12px; left: 65%; }
.arrival-sky i:nth-child(3) { top: 34px; left: 83%; }

.arrival-caravan {
  position: absolute;
  left: 8%;
  right: 4%;
  bottom: 24px;
  height: 45px;
  display: grid;
  grid-template-columns: 1fr 1.35fr 1fr;
  align-items: end;
  gap: 3px;
}

.arrival-caravan span {
  position: relative;
  height: 34px;
  background: #3e4748;
  border: 1px solid #161c1e;
  box-shadow: inset 1px 1px #7b8583;
}

.arrival-caravan span:nth-child(2) {
  height: 45px;
}

.arrival-caravan span::before {
  content: "";
  position: absolute;
  inset: 8px 8px auto;
  height: 7px;
  background: repeating-linear-gradient(90deg, #c49a50 0 6px, transparent 6px 12px);
}

.arrival-caravan span::after {
  content: "";
  position: absolute;
  left: 7px;
  right: 7px;
  bottom: -8px;
  height: 12px;
  background:
    radial-gradient(circle at 8px 6px, #1d2223 0 5px, #88908b 5px 7px, transparent 7px),
    radial-gradient(circle at calc(100% - 8px) 6px, #1d2223 0 5px, #88908b 5px 7px, transparent 7px);
}

.arrival-rail {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 9px;
  height: 5px;
  border-block: 1px solid #26231d;
  background: repeating-linear-gradient(90deg, #9c8a5e 0 10px, #473e31 10px 15px);
}

.arrival-mark {
  position: absolute;
  top: 14px;
  left: 14px;
  width: 43px;
  height: 43px;
  display: grid;
  place-items: center;
  color: #211e17;
  background: #c1a460;
  border: 1px solid #4d3b1e;
  box-shadow: inset 1px 1px #f1d899, inset -2px -2px #725526;
  font-family: var(--title);
  font-size: 22px;
  font-weight: 700;
}

.arrival-mark::after {
  content: attr(data-symbol);
}

.hero-form {
  padding: 8px;
  display: grid;
  background: rgb(238 233 216 / 75%);
  border: 1px solid var(--frame-dark);
  box-shadow: inset 1px 1px var(--frame-light), inset -1px -1px var(--frame-mid);
}

.hero-form .primary-button {
  margin-top: 9px;
}

.mark-choice {
  min-width: 0;
  margin: 10px 0 0;
  padding: 0;
  border: 0;
}

.mark-choice__grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.mark-choice input,
.body-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.mark-choice label {
  min-height: 54px;
  display: grid;
  place-items: center;
  align-content: center;
  background: #cfccbf;
  border: 1px solid var(--frame-dark);
  box-shadow: inset 1px 1px var(--frame-light), inset -1px -1px var(--frame-mid);
  cursor: pointer;
}

.mark-choice label b {
  font-family: var(--title);
  font-size: 19px;
}

.mark-choice label small {
  margin-top: 2px;
  font-size: 9px;
}

.mark-choice input:checked + label {
  background: #b7c1b5;
  box-shadow: inset 2px 2px #667363, inset -1px -1px #eef3e9;
}

.mark-choice input:focus-visible + label,
.body-zone input:focus-visible + label {
  outline: 2px dotted #111;
  outline-offset: 2px;
}

.hero-stats {
  margin-top: 10px;
  color: #e9dfcd;
  background: linear-gradient(180deg, #302f2a, #171a19);
  border: 1px solid #665a42;
  box-shadow: inset 0 1px rgb(255 255 255 / 9%), 0 2px 5px rgb(0 0 0 / 22%);
}

.hero-stats > header {
  min-height: 43px;
  padding: 7px 9px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid rgb(208 181 121 / 28%);
}

.hero-stats > header span {
  display: grid;
  gap: 2px;
}

.hero-stats > header b {
  font-family: var(--title);
  font-size: 15px;
}

.hero-stats > header small {
  color: #aaa291;
  font-size: 9px;
}

.hero-stats > header strong {
  min-width: 38px;
  height: 30px;
  display: grid;
  place-items: center;
  color: #201a10;
  background: linear-gradient(#e2c77f, #a98746);
  border: 1px solid #5d4826;
  font-family: var(--title);
  font-size: 18px;
}

.hero-stats__rows {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.hero-stat-row {
  min-width: 0;
  min-height: 55px;
  padding: 5px 7px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 5px;
  border-bottom: 1px solid rgb(205 184 141 / 14%);
}

.hero-stat-row:nth-child(odd) {
  border-right: 1px solid rgb(205 184 141 / 14%);
}

.hero-stat-row > span:first-child {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.hero-stat-row > span:first-child b {
  overflow: hidden;
  font-size: 11px;
  text-overflow: ellipsis;
}

.hero-stat-row > span:first-child small {
  color: #9e9788;
  font-size: 8px;
}

.hero-stat-row__controls {
  display: grid;
  grid-template-columns: 40px 26px 40px;
  align-items: center;
}

.hero-stat-row__controls button {
  width: 40px;
  height: 42px;
  display: grid;
  place-items: center;
  color: #efe4cd;
  background: #3a3b36;
  border: 1px solid #76694f;
  font-size: 19px;
  font-weight: 700;
}

@media (max-width: 420px) {
  .hero-stats__rows {
    grid-template-columns: 1fr;
  }

  .hero-stat-row:nth-child(odd) {
    border-right: 0;
  }

  .hero-stat-row > span:first-child b {
    font-size: 12px;
  }
}

.hero-stat-row__controls button:disabled {
  color: #68655c;
  background: #242623;
  border-color: #45443d;
}

.hero-stat-row__controls output {
  color: #e5c77f;
  font-family: var(--title);
  font-size: 18px;
  font-weight: 700;
  text-align: center;
}

.hero-stats__derived {
  padding: 7px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
}

.hero-stats__derived span {
  min-width: 0;
  min-height: 40px;
  display: grid;
  place-items: center;
  align-content: center;
  background: rgb(4 7 7 / 42%);
  border: 1px solid rgb(192 166 109 / 20%);
}

.hero-stats__derived small {
  color: #9f9788;
  font-size: 8px;
}

.hero-stats__derived b {
  margin-top: 2px;
  color: #e5c77f;
  font-size: 13px;
}

.rule-peek,
.battle-review {
  background: rgb(238 233 216 / 65%);
  border: 1px solid var(--frame-mid);
}

.rule-peek summary,
.battle-review summary {
  min-height: 38px;
  padding: 9px;
  color: var(--link);
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}

.rule-peek p,
.battle-review > div {
  margin: 0;
  padding: 0 9px 9px;
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.45;
}

/* Shared portraits */

.fighter-portrait {
  --fighter-color: #647f78;
  --fighter-dark: #2e4d49;
  position: relative;
  width: 84px;
  height: 118px;
  margin: 0 auto;
  filter: saturate(.76);
}

.fighter-portrait--opponent {
  --fighter-color: #9a5a51;
  --fighter-dark: #63352f;
}

.fighter-portrait__halo {
  position: absolute;
  inset: 5px 5px 0;
  background:
    linear-gradient(135deg, rgb(255 255 255 / 14%), transparent),
    #8a8d82;
  border: 1px solid #55574f;
  box-shadow: inset 1px 1px #c7c8ba;
}

.fighter-portrait__head {
  position: absolute;
  z-index: 2;
  top: 12px;
  left: 30px;
  width: 24px;
  height: 27px;
  background: #d5c6aa;
  border: 2px solid var(--fighter-dark);
  border-radius: 45% 45% 35% 35%;
  box-shadow: inset 2px 2px #eee4cf, inset -2px -2px #a7967c;
}

.fighter-portrait__body {
  position: absolute;
  z-index: 2;
  top: 39px;
  left: 23px;
  width: 38px;
  height: 43px;
  display: grid;
  place-items: center;
  color: #eee9db;
  background:
    repeating-linear-gradient(0deg, rgb(255 255 255 / 8%) 0 2px, transparent 2px 5px),
    var(--fighter-color);
  border: 2px solid var(--fighter-dark);
  font-family: var(--title);
  font-weight: 700;
}

.fighter-portrait__body::after {
  content: attr(data-symbol);
}

.fighter-portrait__arm,
.fighter-portrait__leg {
  position: absolute;
  z-index: 1;
  background: var(--fighter-color);
  border: 2px solid var(--fighter-dark);
}

.fighter-portrait__arm {
  top: 43px;
  width: 13px;
  height: 50px;
}

.fighter-portrait__arm--left {
  left: 13px;
  transform: rotate(8deg);
}

.fighter-portrait__arm--right {
  right: 13px;
  transform: rotate(-8deg);
}

.fighter-portrait__leg {
  top: 79px;
  width: 16px;
  height: 32px;
}

.fighter-portrait__leg--left { left: 24px; }
.fighter-portrait__leg--right { right: 24px; }

.impact-marker {
  position: absolute;
  z-index: 5;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  color: #fff3df;
  background: var(--danger);
  border: 1px solid #4b1915;
  box-shadow: inset 1px 1px #dc877e;
  font-family: var(--mono);
  font-weight: 700;
}

.impact-marker--head { top: 8px; right: 12px; }
.impact-marker--body { top: 48px; right: 6px; }
.impact-marker--legs { bottom: 4px; right: 12px; }

/* Home */

.home-screen {
  gap: 7px;
}

.home-status {
  min-height: 28px;
  padding: 5px 7px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #c8c5b7;
  border: 1px solid var(--frame-mid);
  box-shadow: inset 1px 1px var(--frame-light);
  font-size: 10px;
}

.home-status span {
  font-weight: 700;
}

.home-status i {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 4px;
  background: var(--health);
  border: 1px solid var(--health-dark);
}

.home-status small {
  color: var(--ink-soft);
}

.home-hero {
  padding: 7px;
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 9px;
  align-items: center;
  background: #e3decb;
  border: 1px solid var(--frame-dark);
  box-shadow: inset 1px 1px var(--frame-light), inset -1px -1px var(--frame-mid);
}

.home-hero .fighter-portrait {
  transform: scale(.76);
  margin: -14px auto;
}

.home-hero h1 {
  margin: 0;
  color: #2c2921;
  font-family: var(--title);
  font-size: 25px;
}

.home-hero p:last-child {
  margin: 5px 0 0;
  color: var(--health-dark);
  font-size: 10px;
}

.arena-gate {
  display: grid;
  grid-template-columns: 105px 1fr;
  grid-template-areas:
    "art copy"
    "button button"
    "training training";
  background: #bebbad;
  border: 1px solid var(--frame-dark);
  box-shadow: inset 1px 1px var(--frame-light), inset -1px -1px #69665d;
}

.arena-gate__art {
  grid-area: art;
  position: relative;
  min-height: 128px;
  overflow: hidden;
  background:
    linear-gradient(180deg, #4f595c 0 62%, #3a3932 62%);
  border-right: 1px solid #5b5a52;
}

.arena-gate__arch {
  position: absolute;
  left: 16px;
  right: 16px;
  top: 16px;
  height: 83px;
  border: 5px solid #898c84;
  border-bottom: 0;
  border-radius: 50px 50px 0 0;
  box-shadow: inset 0 0 0 2px #2a3032;
}

.arena-gate__fighter {
  position: absolute;
  bottom: 17px;
  width: 16px;
  height: 47px;
  border: 2px solid #c7c7b9;
  border-radius: 8px 8px 2px 2px;
}

.arena-gate__fighter::before {
  content: "";
  position: absolute;
  top: -17px;
  left: 1px;
  width: 10px;
  height: 12px;
  border: 2px solid #c7c7b9;
  border-radius: 50%;
}

.arena-gate__fighter--left { left: 32px; }
.arena-gate__fighter--right { right: 32px; border-color: #bd7770; }
.arena-gate__fighter--right::before { border-color: #bd7770; }

.arena-gate__light {
  position: absolute;
  left: 50%;
  top: 27px;
  width: 18px;
  height: 18px;
  background: #b9954c;
  border: 1px solid #59451f;
  transform: translateX(-50%) rotate(45deg);
}

.arena-gate__copy {
  grid-area: copy;
  padding: 10px;
}

.arena-gate__copy h2 {
  margin: 0;
  font-family: var(--title);
  font-size: 23px;
  line-height: 1.05;
}

.arena-gate__copy > p:last-child {
  margin: 7px 0 0;
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.4;
}

.arena-gate .primary-button {
  grid-area: button;
  margin: 6px;
}

.arena-gate__training {
  grid-area: training;
  margin: 0 6px 6px;
}

.home-hint,
.search-rule,
.ready-rule {
  margin: 0;
  padding: 7px 8px;
  background: #e8e3d2;
  border: 1px solid var(--frame-mid);
  box-shadow: inset 1px 1px var(--frame-light);
  color: var(--ink-soft);
  font-size: 10px;
  line-height: 1.35;
}

.home-hint > span,
.search-rule > span {
  margin-right: 5px;
  color: var(--health-dark);
  font-weight: 700;
}

/* Search and ready */

.search-screen,
.ready-screen,
.disconnect-screen,
.result-screen {
  justify-content: flex-start;
}

.empty-arena {
  position: relative;
  height: 180px;
  overflow: hidden;
  background:
    linear-gradient(180deg, #606a69 0 59%, #67604f 59% 75%, #403c33 75%);
  border: 1px solid var(--frame-dark);
  box-shadow: inset 1px 1px #aeb4ae, inset -1px -1px #252823;
}

.empty-arena__ring {
  position: absolute;
  left: 50%;
  top: 26px;
  width: 116px;
  height: 116px;
  border: 4px double #b8b6a6;
  border-radius: 50%;
  transform: translateX(-50%);
}

.empty-arena__door {
  position: absolute;
  bottom: 31px;
  width: 45px;
  height: 68px;
  background: #30383a;
  border: 3px ridge #84877e;
}

.empty-arena__door--left { left: 13%; }
.empty-arena__door--right { right: 13%; }

.empty-arena__pulse {
  position: absolute;
  left: 50%;
  top: 70px;
  width: 13px;
  height: 13px;
  background: var(--gold-light);
  border: 1px solid #5c471f;
  transform: translateX(-50%) rotate(45deg);
  animation: search-pulse 900ms steps(2, end) infinite;
}

@keyframes search-pulse {
  50% { opacity: .35; }
}

.search-rule {
  display: flex;
  align-items: flex-start;
}

.search-rule p {
  margin: 0;
}

.live-room-card {
  padding: 12px;
  display: grid;
  justify-items: center;
  gap: 4px;
  color: #eae5d5;
  background:
    linear-gradient(135deg, rgb(175 143 77 / 12%), transparent 45%),
    #273033;
  border: 1px solid #151b1d;
  box-shadow: inset 1px 1px #687477, inset -1px -1px #111719;
}

.live-room-card small {
  color: #b8b6a8;
  font-size: 10px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.live-room-card strong {
  color: var(--gold-light);
  font-family: var(--mono);
  font-size: clamp(28px, 10vw, 40px);
  letter-spacing: .14em;
  line-height: 1.1;
  text-shadow: 1px 2px #111;
}

.live-room-card span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: #b9d8c3;
  font-size: 10px;
}

.live-room-card i {
  width: 7px;
  height: 7px;
  background: var(--health);
  border: 1px solid var(--health-dark);
}

.live-invite-cancel {
  justify-self: center;
}

.invite-feedback {
  min-height: 18px;
  margin: -5px 0 0;
  color: var(--health-dark);
  font-size: 11px;
  text-align: center;
}

.live-room-loading {
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.live-room-loading i {
  width: 10px;
  height: 10px;
  background: var(--gold);
  border: 1px solid #59451f;
  animation: search-pulse 900ms steps(2, end) infinite;
}

.live-room-loading i:nth-child(2) { animation-delay: 150ms; }
.live-room-loading i:nth-child(3) { animation-delay: 300ms; }

.live-form-error {
  margin-top: -3px;
}

.faceoff {
  min-height: 214px;
  padding: 8px;
  display: grid;
  grid-template-columns: 1fr 42px 1fr;
  align-items: center;
  background:
    linear-gradient(90deg, rgb(75 125 79 / 9%) 0 49.5%, #8d887a 49.5% 50.5%, rgb(145 59 50 / 9%) 50.5%),
    #c9c6b8;
  border: 1px solid var(--frame-dark);
  box-shadow: inset 1px 1px var(--frame-light), inset -1px -1px var(--frame-mid);
}

.faceoff__fighter {
  min-width: 0;
  display: grid;
  justify-items: center;
}

.faceoff__fighter b {
  max-width: 100%;
  margin-top: 2px;
  overflow: hidden;
  color: var(--health-dark);
  font-family: var(--title);
  font-size: 17px;
  text-overflow: ellipsis;
}

.faceoff__fighter--opponent b {
  color: var(--enemy-dark);
}

.faceoff__fighter small {
  margin-top: 2px;
  color: var(--ink-soft);
  font-size: 9px;
}

.faceoff__versus {
  align-self: stretch;
  display: grid;
  place-items: center;
  color: #463a21;
  font-family: var(--title);
  font-weight: 700;
  border-inline: 1px solid #888478;
}

.faceoff__versus i {
  display: none;
}

.ready-rule {
  display: grid;
  grid-template-columns: 38px 1fr;
  align-items: center;
}

.ready-rule > span {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  color: #45371c;
  background: #c7a862;
  border: 1px solid #5e4a24;
  font-family: var(--mono);
  font-weight: 700;
}

.ready-rule p,
.ready-rule b,
.ready-rule small {
  margin: 0;
  display: block;
}

.ready-rule small {
  margin-top: 2px;
}

/* Disconnect */

.broken-signal {
  position: relative;
  width: 118px;
  height: 118px;
  margin: 8px auto 0;
  display: grid;
  place-items: center;
  color: #fff1e9;
  background: #a55147;
  border: 5px double #5d2520;
  border-radius: 50%;
  box-shadow: inset 0 0 0 11px #d1cbbc;
}

.broken-signal span,
.broken-signal i {
  position: absolute;
  width: 72px;
  height: 3px;
  background: #662924;
}

.broken-signal span { transform: rotate(45deg); }
.broken-signal i { transform: rotate(-45deg); }

.broken-signal b {
  z-index: 2;
  font-family: var(--mono);
  font-size: 25px;
}

.return-countdown {
  display: grid;
  justify-items: center;
  color: #3d1d1a;
}

.return-countdown strong {
  font-family: var(--mono);
  font-size: 42px;
  line-height: .9;
}

.return-countdown span {
  font-size: 9px;
}

/* Result */

.result-emblem {
  width: 82px;
  height: 82px;
  margin: 10px auto 0;
  display: grid;
  place-items: center;
  color: #40201d;
  background: #c5bfae;
  border: 4px double var(--enemy);
  border-radius: 50%;
  font-family: var(--title);
  font-size: 34px;
}

.result-emblem--win {
  color: #233d28;
  border-color: var(--health);
}

.result-emblem--draw {
  color: #3e392c;
  border-color: var(--gold);
}

.final-score {
  min-height: 76px;
  padding: 6px;
  display: grid;
  grid-template-columns: 1fr 22px 1fr;
  align-items: end;
  background: #c4c1b4;
  border: 1px solid var(--frame-dark);
  box-shadow: inset 1px 1px var(--frame-light), inset -1px -1px var(--frame-mid);
}

.final-score > span {
  display: grid;
  justify-items: center;
}

.final-score small {
  max-width: 100%;
  overflow: hidden;
  color: var(--ink-soft);
  font-size: 9px;
  text-overflow: ellipsis;
}

.final-score b {
  font-family: var(--mono);
  font-size: 35px;
  line-height: 1;
}

.final-score > span:first-child b {
  color: var(--health-dark);
}

.final-score > span:last-child b {
  color: var(--enemy-dark);
}

.final-score > i {
  align-self: center;
  color: var(--ink-soft);
  font-family: var(--title);
  font-size: 22px;
  font-style: normal;
  text-align: center;
}

.result-numbers {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--frame-dark);
}

.result-numbers span {
  min-width: 0;
  min-height: 55px;
  padding: 5px;
  display: grid;
  place-items: center;
  align-content: center;
  background: #dbd7ca;
  box-shadow: inset 1px 1px var(--frame-light), inset -1px -1px var(--frame-mid);
}

.result-numbers span + span {
  border-left: 1px solid var(--frame-mid);
}

.result-numbers b {
  font-family: var(--mono);
  font-size: 18px;
}

.result-numbers small {
  font-size: 8px;
}

.rematch-card {
  padding: 10px;
  display: grid;
  gap: 7px;
  color: #e9e4d5;
  background:
    linear-gradient(135deg, rgb(181 145 70 / 12%), transparent 46%),
    #293134;
  border: 1px solid #151a1c;
  box-shadow: inset 1px 1px #687376, inset -1px -1px #111719;
}

.rematch-card .eyebrow {
  color: #c3aa6c;
}

.rematch-card h2 {
  margin: 0;
  color: #f4e5bd;
  font-family: var(--title);
  font-size: 21px;
  line-height: 1.1;
}

.rematch-card > p:not(.eyebrow) {
  margin: 0;
  color: #c8c5b9;
  font-size: 11px;
  line-height: 1.35;
}

.rematch-card [data-rematch-countdown] {
  color: var(--gold-light);
  font-family: var(--mono);
  font-size: 15px;
}

.rematch-card--incoming {
  border-color: #8d6c31;
  box-shadow: inset 1px 1px #b59958, inset -1px -1px #17130d;
}

.rematch-card--accepted {
  justify-items: center;
  padding-block: 14px;
  color: #d8efe0;
  background:
    radial-gradient(circle at 50% 0, rgb(105 170 125 / 18%), transparent 58%),
    #24332b;
  border-color: #496c53;
  text-align: center;
}

.rematch-card--accepted [data-rematch-countdown] {
  display: inline-grid;
  width: 30px;
  height: 30px;
  place-items: center;
  color: #e5f5e9;
  background: #355a40;
  border: 1px solid #7aa488;
  border-radius: 50%;
  font-size: 18px;
}

.rematch-card--closed {
  color: #d7d2c4;
  background: #343638;
  border-color: #5e5e59;
}

.result-exit {
  align-self: center;
  justify-self: center;
  min-height: 40px;
}

.review-row {
  min-height: 42px;
  padding: 4px 0;
  display: grid;
  grid-template-columns: 24px 1fr 20px;
  gap: 5px;
  align-items: center;
  border-top: 1px solid #aaa598;
}

.review-row > span {
  width: 21px;
  height: 21px;
  display: grid;
  place-items: center;
  background: #c6c2b5;
  border: 1px solid #77746b;
  font-family: var(--mono);
  font-size: 9px;
}

.review-row b,
.review-row small {
  display: block;
}

.review-row small {
  margin-top: 2px;
  font-size: 8px;
}

.review-row i {
  font-style: normal;
  color: var(--enemy-dark);
}

.review-row i.is-positive {
  color: var(--health-dark);
}

/* Dialog */

.confirm-dialog {
  width: min(calc(100% - 28px), 390px);
  padding: 0;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--frame-dark);
  border-radius: 0;
  box-shadow:
    inset 1px 1px var(--frame-light),
    inset -1px -1px var(--frame-mid),
    7px 9px 0 rgb(0 0 0 / 28%);
}

.confirm-dialog::backdrop {
  background: rgb(18 21 22 / 65%);
}

.confirm-dialog form {
  padding: 12px;
}

.confirm-dialog h2 {
  margin: 0;
  font-family: var(--title);
  font-size: 22px;
}

.confirm-dialog form > p:not(.eyebrow) {
  margin: 7px 0 12px;
  color: var(--ink-soft);
  line-height: 1.4;
}

@media (max-width: 360px) {
  .app-main {
    padding-inline: max(6px, env(safe-area-inset-left));
  }

  .screen {
    gap: 6px;
  }

  .app-header {
    min-height: 43px;
  }

  .brand b {
    font-size: 15px;
  }

  .brand small {
    font-size: 8px;
  }

  .arrival-art {
    height: 105px;
  }

  .arrival-caravan {
    bottom: 20px;
    height: 38px;
  }

  .arrival-caravan span {
    height: 29px;
  }

  .arrival-caravan span:nth-child(2) {
    height: 38px;
  }

  .screen-heading {
    padding: 6px 7px;
  }

  .screen-heading h1,
  .screen-heading h2 {
    font-size: 20px;
  }

  .screen-heading > p:last-child {
    margin-top: 4px;
    font-size: 10px;
  }

  .empty-arena {
    height: 132px;
  }

  .empty-arena__ring {
    top: 17px;
    width: 92px;
    height: 92px;
  }

  .empty-arena__door {
    bottom: 21px;
    width: 36px;
    height: 54px;
  }

  .empty-arena__pulse {
    top: 51px;
  }

  .faceoff {
    min-height: 181px;
  }

  .faceoff .fighter-portrait {
    transform: scale(.84);
    margin-block: -9px;
  }

  .fight-heading > p {
    display: none;
  }

  .fight-heading h1 {
    font-size: 17px;
  }

  .body-choice {
    padding: 4px;
  }

  .body-choice legend {
    width: calc(100% + 8px);
    margin: -4px -4px 0;
    padding: 4px;
  }

  .choice-owner small {
    max-width: 53px;
  }

  .choice-portrait {
    height: 74px;
  }

  .choice-portrait .fighter-portrait {
    transform: scale(.59);
  }

  .equipment-figure {
    grid-template-columns: 20px minmax(0, 1fr) 20px;
    padding: 2px;
  }

  .equipment-slots {
    gap: 2px;
  }

  .item-slot {
    width: 20px;
    height: 20px;
  }

  .item-slot i {
    font-size: 12px;
  }

  .body-zone label {
    min-height: 38px;
    padding-left: 26px;
  }

  .body-zone label::before {
    left: 6px;
  }

  .impact-arena {
    min-height: 176px;
  }

  .impact-fighter__figure {
    height: 109px;
  }

  .impact-fighter .fighter-portrait {
    transform: scale(.9);
    transform-origin: bottom center;
  }

  .combat-explanation p {
    padding: 5px 6px;
  }
}

/* Iteration AL.2: three readable full-width exchange rows. */

.battle-memory__heading {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
}

.battle-memory__sides {
  min-width: 0;
  padding-inline: 27px 7px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
  color: #a9a091;
  text-align: center;
}

.battle-memory__sides b {
  overflow: hidden;
  font-family: var(--battle-ui);
  font-size: 9px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.battle-memory__sides b:first-child { color: #a9d4ce; }
.battle-memory__sides b:last-child { color: #e1a08f; }

.battle-memory__rounds {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2px;
}

.battle-memory-round {
  min-height: 31px;
  padding: 2px 3px;
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) 1px minmax(0, 1fr);
  align-items: center;
  gap: 3px;
}

.battle-memory-round__number {
  position: static;
  min-width: 20px;
  height: 20px;
  transform: none;
  font-size: 10px;
}

.battle-memory-round__divider {
  height: 24px;
}

.battle-memory-action {
  min-height: 25px;
  padding: 1px 3px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 30px;
  grid-template-rows: minmax(0, 1fr);
  gap: 3px;
}

.battle-memory-action > b {
  display: none;
}

.battle-memory-action__moves {
  grid-column: 1;
  grid-row: 1;
  display: grid;
  grid-template-columns: repeat(2, minmax(27px, 1fr));
  gap: 3px;
}

.battle-memory-action__move {
  min-height: 25px;
  padding: 1px 3px;
  grid-template-columns: 14px 14px;
  justify-content: center;
  gap: 2px;
}

.battle-memory-action__move > i {
  width: 14px;
  height: 17px;
}

.battle-memory-action__move .memory-zone-glyph {
  width: 14px;
  height: 21px;
}

.battle-memory-action em {
  grid-column: 2;
  grid-row: 1;
  align-self: center;
  font-size: 10px;
  text-align: center;
}

.mini-app-shell[data-screen="fight"] .fight-screen--choice .arena-shell {
  min-height: clamp(330px, 48dvh, 420px);
}

@media (max-height: 760px) {
  .mini-app-shell[data-screen="fight"] .fight-screen--choice .arena-shell {
    min-height: 330px;
  }

  .mini-app-shell[data-screen="fight"] .fight-screen--choice .paper-doll-wrap {
    height: 220px;
  }

  .mini-app-shell[data-screen="fight"] .fight-screen--choice .battle-action legend {
    height: 44px;
  }

  .mini-app-shell[data-screen="fight"] .fight-screen--choice .battle-zone label {
    min-height: 44px;
  }
}

/* Iteration AM: history is an on-demand battle overlay, not a compressed HUD. */

.battle-history-trigger {
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 4px 9px;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  color: #e8dfcf;
  appearance: none;
  text-align: left;
  background: linear-gradient(180deg, rgb(57 53 45 / 97%), rgb(27 28 25 / 98%));
  border: 1px solid rgb(194 169 113 / 48%);
  border-radius: 6px;
  box-shadow: inset 0 1px rgb(255 255 255 / 7%);
  cursor: pointer;
}

.battle-history-trigger:hover {
  border-color: rgb(224 196 132 / 74%);
}

.battle-history-trigger:focus-visible {
  outline: 2px solid var(--battle-brass-light);
  outline-offset: 2px;
}

.battle-history-trigger__icon {
  width: 30px;
  height: 30px;
  padding: 5px;
  display: grid;
  place-items: center;
  color: #d8bd78;
  background: rgb(11 16 16 / 56%);
  border: 1px solid rgb(200 174 111 / 38%);
  border-radius: 50%;
}

.battle-history-trigger__icon svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.battle-history-trigger span:nth-child(2) {
  min-width: 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.battle-history-trigger b {
  font-family: var(--battle-display);
  font-size: 14px;
}

.battle-history-trigger small {
  overflow: hidden;
  color: #bdb2a0;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.battle-history-trigger > i {
  color: #d8bd78;
  font-family: var(--battle-display);
  font-size: 22px;
  font-style: normal;
  line-height: 1;
}

.battle-journal-dialog form {
  grid-template-rows: auto minmax(0, 1fr);
}

dialog.fight-overlay {
  inset: max(54px, env(safe-area-inset-top)) 0 0 !important;
  max-height: calc(100dvh - max(64px, env(safe-area-inset-top))) !important;
  margin: auto !important;
}

dialog.fight-overlay::backdrop {
  background: linear-gradient(
    180deg,
    transparent 0,
    transparent max(46px, env(safe-area-inset-top)),
    rgb(5 8 9 / 72%) max(60px, env(safe-area-inset-top)),
    rgb(5 8 9 / 82%) 100%
  ) !important;
  backdrop-filter: none !important;
}

.battle-journal-dialog.fight-overlay form {
  max-height: calc(100dvh - max(66px, env(safe-area-inset-top)));
}

@media (max-height: 760px) {
  .mini-app-shell[data-screen="fight"] .fight-screen--choice .arena-shell {
    min-height: 370px;
  }

  .mini-app-shell[data-screen="fight"] .fight-screen--choice .paper-doll-wrap {
    height: 290px;
  }
}

/* Iteration AL.4: keep the larger fighters while fitting the confirmation on 320×700. */

.battle-memory-round {
  min-height: 28px;
}

.battle-memory-action {
  min-height: 22px;
}

.battle-memory-action__move {
  min-height: 22px;
}

.battle-memory-action__move .memory-zone-glyph {
  height: 19px;
}

@media (max-height: 760px) {
  .mini-app-shell[data-screen="fight"] .fight-screen--choice .arena-shell {
    min-height: 303px;
  }

  .mini-app-shell[data-screen="fight"] .fight-screen--choice .combat-form {
    padding-top: 4px;
  }
}

@media (min-width: 700px) {
  .mini-app-shell {
    margin-block: 18px;
    min-height: calc(100vh - 36px);
    min-height: calc(100dvh - 36px);
    border: 2px solid var(--frame-dark);
  }
}

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