:root {
      --bg: #0d1218;
      --panel: rgba(10, 15, 21, 0.82);
      --panel-soft: rgba(10, 15, 21, 0.58);
      --line: rgba(231, 211, 160, 0.26);
      --gold: #d7b96e;
      --gold-bright: #f0d997;
      --text: #f2efe7;
      --muted: #b6bdc4;
      --good: #77c89d;
      --warn: #e5bd66;
      --bad: #d86c73;
      --hp: #c85a65;
      --mp: #5c90c9;
      --world-a: #13333b;
      --world-b: #1c2028;
      --world-c: #0b1720;
      --safe-bottom: max(10px, env(safe-area-inset-bottom));
      --safe-left: max(10px, env(safe-area-inset-left));
      --safe-right: max(10px, env(safe-area-inset-right));
      --safe-top: max(8px, env(safe-area-inset-top));
    }

    * { box-sizing: border-box; }
    html, body {
      width: 100%;
      height: 100%;
      margin: 0;
      background: var(--bg);
      color: var(--text);
      font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
      overflow: hidden;
      touch-action: manipulation;
    }

    button, select, input { font: inherit; }
    button { -webkit-tap-highlight-color: transparent; }

    #app {
      position: relative;
      width: 100%;
      height: 100%;
      min-height: 320px;
      overflow: hidden;
      background:
        radial-gradient(circle at 65% 22%, rgba(79, 145, 151, 0.28), transparent 26%),
        linear-gradient(180deg, var(--world-a), var(--world-b) 55%, var(--world-c));
    }

    .world {
      position: absolute;
      inset: 0;
      overflow: hidden;
    }

    .world::before {
      content: "";
      position: absolute;
      inset: 0;
      background:
        linear-gradient(90deg, transparent 0 10%, rgba(4,8,10,.22) 10% 12%, transparent 12% 30%, rgba(4,8,10,.22) 30% 33%, transparent 33% 67%, rgba(4,8,10,.26) 67% 70%, transparent 70% 88%, rgba(4,8,10,.22) 88% 90%, transparent 90%),
        radial-gradient(ellipse at 50% 88%, rgba(57, 113, 120, 0.45), transparent 56%);
      opacity: .65;
      pointer-events: none;
    }

    .temple-columns {
      position: absolute;
      inset: 9% 4% 14%;
      display: grid;
      grid-template-columns: repeat(6, 1fr);
      gap: 7%;
      opacity: .35;
      pointer-events: none;
    }

    .column {
      position: relative;
      border-left: 6px solid rgba(182, 191, 179, .18);
      border-right: 6px solid rgba(182, 191, 179, .10);
      background: linear-gradient(90deg, rgba(200,210,197,.06), rgba(255,255,255,.02), rgba(200,210,197,.05));
      border-radius: 10px 10px 2px 2px;
    }
    .column::before, .column::after {
      content: "";
      position: absolute;
      left: -12px;
      right: -12px;
      height: 12px;
      border: 1px solid rgba(216,224,212,.16);
      background: rgba(142,156,148,.10);
    }
    .column::before { top: 0; border-radius: 8px 8px 2px 2px; }
    .column::after { bottom: 0; }

    .floor {
      position: absolute;
      left: 0;
      right: 0;
      bottom: 0;
      height: 34%;
      background:
        radial-gradient(ellipse at 50% 42%, rgba(87, 151, 151, .22), transparent 52%),
        repeating-linear-gradient(165deg, rgba(230,230,220,.04) 0 2px, transparent 2px 52px),
        linear-gradient(180deg, rgba(16,31,37,.25), rgba(5,10,14,.88));
      border-top: 1px solid rgba(188,214,204,.16);
      transform: perspective(520px) rotateX(18deg);
      transform-origin: bottom;
    }

    .topbar {
      position: absolute;
      z-index: 20;
      left: var(--safe-left);
      right: var(--safe-right);
      top: var(--safe-top);
      height: 44px;
      display: flex;
      align-items: center;
      gap: 8px;
      pointer-events: none;
    }

    .topbar > * { pointer-events: auto; }

    .brand {
      min-width: 172px;
      max-width: 260px;
      padding: 8px 12px;
      border: 1px solid var(--line);
      background: var(--panel-soft);
      backdrop-filter: blur(10px);
      border-radius: 12px;
      line-height: 1.05;
    }

    .brand strong { display: block; font-size: 13px; letter-spacing: .035em; }
    .brand span { display: block; color: var(--muted); font-size: 11px; margin-top: 3px; }

    .run-status {
      margin-left: auto;
      display: flex;
      gap: 6px;
      align-items: center;
      padding: 6px 9px;
      border: 1px solid var(--line);
      background: var(--panel-soft);
      backdrop-filter: blur(10px);
      border-radius: 12px;
      font-size: 12px;
      white-space: nowrap;
    }

    .chip {
      border: 1px solid rgba(255,255,255,.12);
      border-radius: 999px;
      padding: 4px 8px;
      color: var(--muted);
      background: rgba(255,255,255,.04);
    }

    .icon-button {
      width: 44px;
      height: 44px;
      border: 1px solid var(--line);
      background: var(--panel);
      color: var(--text);
      border-radius: 12px;
      display: grid;
      place-items: center;
      font-size: 20px;
    }

    .battlefield {
      position: absolute;
      z-index: 5;
      inset: 50px 0 76px;
      display: grid;
      grid-template-columns: minmax(154px, 19%) 1fr minmax(170px, 22%);
      gap: 8px;
      padding: 0 var(--safe-right) 0 var(--safe-left);
      align-items: stretch;
    }

    .party-rail {
      display: flex;
      flex-direction: column;
      justify-content: center;
      gap: 6px;
      padding: 4px 0;
      z-index: 8;
    }

    .unit-card {
      position: relative;
      min-height: 54px;
      display: grid;
      grid-template-columns: 42px 1fr;
      gap: 8px;
      align-items: center;
      padding: 6px 8px;
      border: 1px solid rgba(255,255,255,.11);
      background: rgba(8, 12, 17, .66);
      backdrop-filter: blur(7px);
      border-radius: 11px;
      overflow: hidden;
    }

    .unit-card.dead { opacity: .45; filter: grayscale(.75); }
    .unit-card.recommended { border-color: rgba(215,185,110,.55); }

    .portrait {
      position: relative;
      width: 42px;
      height: 42px;
      border-radius: 10px;
      border: 1px solid rgba(255,255,255,.16);
      background:
        radial-gradient(circle at 50% 32%, var(--skin, #d9ae95) 0 19%, transparent 20%),
        linear-gradient(135deg, var(--hair, #272228) 0 36%, transparent 37%),
        linear-gradient(180deg, transparent 0 38%, var(--armor, #3b4350) 39% 100%);
      overflow: hidden;
    }

    .portrait::after {
      content: "";
      position: absolute;
      left: 12px;
      right: 12px;
      bottom: 4px;
      height: 13px;
      border-radius: 50% 50% 30% 30%;
      background: var(--under, #4a2737);
      opacity: var(--damage-opacity, 0);
    }

    .unit-meta { min-width: 0; }
    .unit-name-row { display: flex; align-items: baseline; gap: 5px; min-width: 0; }
    .unit-name {
      font-size: 12px;
      font-weight: 650;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .role {
      font-size: 9px;
      color: var(--gold-bright);
      letter-spacing: .06em;
      text-transform: uppercase;
    }

    .bars { margin-top: 5px; }
    .bar {
      position: relative;
      height: 6px;
      border-radius: 999px;
      background: rgba(255,255,255,.08);
      overflow: hidden;
    }
    .bar > span {
      position: absolute;
      inset: 0 auto 0 0;
      width: 100%;
      border-radius: inherit;
      transition: width .28s ease;
      background: linear-gradient(90deg, #9d3c48, var(--hp));
    }
    .bar.enemy > span { background: linear-gradient(90deg, #92313e, #d36b71); }
    .tiny-line {
      display: flex;
      justify-content: space-between;
      margin-top: 3px;
      color: var(--muted);
      font-size: 9px;
    }

    .arena {
      position: relative;
      overflow: visible;
      min-width: 0;
    }

    .combatants {
      position: absolute;
      inset: 0;
      display: flex;
      align-items: flex-end;
      justify-content: space-between;
      gap: 5%;
      padding: 3% 1% 1%;
    }

    .heroes, .enemies {
      position: relative;
      display: flex;
      align-items: flex-end;
      justify-content: center;
      min-width: 0;
      height: 100%;
      flex: 1 1 50%;
    }

    .heroes { justify-content: flex-start; padding-left: 1%; }
    .enemies { justify-content: flex-end; padding-right: 1%; }

    .figure-wrap {
      position: relative;
      width: clamp(88px, 12vw, 170px);
      height: min(82%, 410px);
      min-height: 180px;
      transform-origin: center bottom;
      transition: transform .25s ease, opacity .25s ease, filter .25s ease;
    }

    .figure-wrap.small {
      width: clamp(70px, 9vw, 130px);
      height: min(70%, 340px);
      margin-left: -4%;
    }

    .figure-wrap.dead {
      transform: translateY(18px) rotate(5deg) scale(.94);
      opacity: .45;
      filter: saturate(.45);
    }

    .figure-wrap.attacking { animation: lunge .46s ease; }
    .figure-wrap.hit { animation: hit .46s ease; }

    @keyframes lunge {
      0%,100% { transform: translateX(0) scale(1); }
      45% { transform: translateX(18px) scale(1.035); }
    }
    .enemies .figure-wrap.attacking {
      animation-name: lungeEnemy;
    }
    @keyframes lungeEnemy {
      0%,100% { transform: translateX(0) scale(1); }
      45% { transform: translateX(-18px) scale(1.035); }
    }
    @keyframes hit {
      0%,100% { transform: translateX(0); filter: brightness(1); }
      30% { transform: translateX(-7px); filter: brightness(1.55); }
      60% { transform: translateX(6px); }
    }

    .figure-nameplate {
      position: absolute;
      left: 50%;
      bottom: -4px;
      transform: translateX(-50%);
      width: min(145%, 210px);
      text-align: center;
      font-size: 10px;
      color: var(--text);
      padding: 4px 6px;
      border: 1px solid rgba(255,255,255,.11);
      border-radius: 999px;
      background: rgba(7,11,15,.66);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      z-index: 5;
    }

    .figure-svg {
      width: 100%;
      height: 100%;
      overflow: visible;
      filter: drop-shadow(0 10px 14px rgba(0,0,0,.32));
    }

    .skin { fill: var(--skin, #d2a182); }
    .skin-shadow { fill: color-mix(in srgb, var(--skin, #d2a182), #4b2630 26%); }
    .hair { fill: var(--hair, #2a2228); }
    .armor { fill: var(--armor, #303743); transition: opacity .3s ease, transform .3s ease; }
    .armor2 { fill: var(--armor2, #b08c45); transition: opacity .3s ease; }
    .under { fill: var(--under, #4b2437); transition: opacity .3s ease; }
    .weapon { fill: var(--weapon, #c6ccd2); }
    .shield { fill: var(--shield, #343b48); stroke: var(--armor2, #b08c45); stroke-width: 4; }
    .scale { fill: var(--scale, #477b72); }
    .accent-stroke { stroke: var(--armor2, #b08c45); stroke-width: 4; fill: none; stroke-linecap: round; }

    .damage-0 .armor, .damage-0 .armor2 { opacity: 1; }
    .damage-0 .under { opacity: .05; }
    .damage-1 .armor { opacity: .76; }
    .damage-1 .armor2 { opacity: .55; }
    .damage-1 .under { opacity: .4; }
    .damage-2 .armor { opacity: .34; }
    .damage-2 .armor2 { opacity: .26; }
    .damage-2 .under { opacity: .82; }
    .damage-3 .armor { opacity: .08; }
    .damage-3 .armor2 { opacity: .08; }
    .damage-3 .under { opacity: 1; }

    .damage-pop {
      position: absolute;
      z-index: 30;
      transform: translate(-50%, -50%);
      font-weight: 800;
      font-size: 22px;
      text-shadow: 0 2px 6px #000;
      pointer-events: none;
      animation: pop 1.5s ease-out forwards;
    }
    .damage-pop.heal { color: #8fe1b1; }
    .damage-pop.damage { color: #ffd0d4; }
    .damage-pop.special { color: #ffe4a8; }

    @keyframes pop {
      0% { opacity: 0; transform: translate(-50%, -35%) scale(.8); }
      12% { opacity: 1; transform: translate(-50%, -52%) scale(1.06); }
      68% { opacity: 1; transform: translate(-50%, -82%) scale(1); }
      100% { opacity: 0; transform: translate(-50%, -118%) scale(.96); }
    }

    .enemy-rail {
      display: flex;
      flex-direction: column;
      justify-content: center;
      gap: 7px;
      z-index: 8;
    }

    .enemy-card {
      padding: 7px 8px;
      border: 1px solid rgba(255,255,255,.11);
      background: rgba(8, 12, 17, .64);
      backdrop-filter: blur(7px);
      border-radius: 11px;
    }
    .enemy-card.dead { opacity: .42; }
    .enemy-title { display: flex; justify-content: space-between; gap: 6px; font-size: 11px; }
    .enemy-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .state-label { color: var(--muted); font-size: 9px; margin-top: 4px; }

    .bottom-ui {
      position: absolute;
      z-index: 22;
      left: var(--safe-left);
      right: var(--safe-right);
      bottom: var(--safe-bottom);
      min-height: 58px;
      display: flex;
      align-items: flex-end;
      justify-content: center;
      pointer-events: none;
    }

    .control-strip {
      pointer-events: auto;
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 7px;
      padding: 7px;
      border: 1px solid var(--line);
      border-radius: 15px;
      background: var(--panel);
      backdrop-filter: blur(10px);
      max-width: min(96vw, 760px);
    }

    .control-btn {
      min-width: 46px;
      height: 42px;
      border: 1px solid rgba(255,255,255,.12);
      border-radius: 11px;
      color: var(--text);
      background: rgba(255,255,255,.045);
      padding: 0 11px;
    }
    .control-btn.primary {
      border-color: rgba(215,185,110,.46);
      background: rgba(215,185,110,.13);
      color: var(--gold-bright);
    }
    .control-btn.active {
      background: var(--gold);
      color: #1b1710;
      border-color: var(--gold-bright);
      font-weight: 700;
    }
    .control-btn:disabled { opacity: .42; }

    .mode-select {
      height: 42px;
      border: 1px solid rgba(255,255,255,.12);
      border-radius: 11px;
      background: #171d24;
      color: var(--text);
      padding: 0 9px;
      max-width: 158px;
    }

    .toast-stack {
      position: absolute;
      z-index: 40;
      left: 50%;
      top: 60px;
      transform: translateX(-50%);
      width: min(92vw, 480px);
      display: grid;
      gap: 7px;
      pointer-events: none;
    }
    .toast {
      padding: 10px 12px;
      border: 1px solid rgba(215,185,110,.35);
      background: rgba(10,15,21,.92);
      border-radius: 12px;
      color: var(--text);
      font-size: 12px;
      box-shadow: 0 12px 30px rgba(0,0,0,.28);
      animation: toastIn .25s ease;
    }
    .toast strong { color: var(--gold-bright); }
    @keyframes toastIn {
      from { opacity: 0; transform: translateY(-8px); }
      to { opacity: 1; transform: translateY(0); }
    }

    .drawer {
      position: absolute;
      z-index: 60;
      top: 0;
      bottom: 0;
      width: min(420px, 92vw);
      padding: calc(var(--safe-top) + 8px) 14px var(--safe-bottom);
      background: rgba(8,12,17,.97);
      backdrop-filter: blur(16px);
      border-left: 1px solid var(--line);
      transform: translateX(105%);
      right: 0;
      transition: transform .25s ease;
      overflow-y: auto;
    }
    .drawer.open { transform: translateX(0); }
    .drawer h2 { margin: 0 0 12px; font-size: 18px; }
    .drawer h3 { margin: 18px 0 8px; font-size: 14px; color: var(--gold-bright); }
    .drawer p, .drawer li { color: var(--muted); font-size: 13px; line-height: 1.45; }
    .drawer-close {
      float: right;
      width: 42px;
      height: 42px;
      border-radius: 11px;
      border: 1px solid rgba(255,255,255,.12);
      background: rgba(255,255,255,.05);
      color: var(--text);
      font-size: 20px;
    }

    .settings-grid { display: grid; gap: 9px; }
    .setting {
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 10px;
      padding: 9px 10px;
      border: 1px solid rgba(255,255,255,.09);
      border-radius: 11px;
      background: rgba(255,255,255,.03);
    }
    .setting label { font-size: 12px; }
    .setting select {
      min-width: 130px;
      border: 1px solid rgba(255,255,255,.12);
      background: #171d24;
      color: var(--text);
      border-radius: 9px;
      padding: 7px 8px;
    }

    .log {
      display: grid;
      gap: 7px;
    }
    .log-entry {
      border-left: 2px solid rgba(215,185,110,.42);
      padding: 6px 8px;
      background: rgba(255,255,255,.025);
      color: var(--muted);
      font-size: 12px;
      line-height: 1.4;
    }

    .modal {
      position: absolute;
      z-index: 80;
      inset: 0;
      display: none;
      place-items: center;
      padding: 18px;
      background: rgba(2,5,8,.62);
      backdrop-filter: blur(5px);
    }
    .modal.open { display: grid; }
    .modal-card {
      width: min(660px, 94vw);
      max-height: 88vh;
      overflow-y: auto;
      border: 1px solid var(--line);
      border-radius: 17px;
      background: rgba(10,15,21,.98);
      padding: 18px;
      box-shadow: 0 20px 60px rgba(0,0,0,.45);
    }
    .modal-card h2 { margin: 0; font-size: 20px; }
    .modal-card p { color: var(--muted); line-height: 1.45; }
    .choice-grid {
      margin-top: 12px;
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: 10px;
    }
    .choice {
      min-height: 90px;
      text-align: left;
      padding: 12px;
      border: 1px solid rgba(255,255,255,.12);
      border-radius: 13px;
      background: rgba(255,255,255,.035);
      color: var(--text);
    }
    .choice strong { display: block; color: var(--gold-bright); margin-bottom: 5px; }
    .choice small { display: block; color: var(--muted); line-height: 1.4; }
    .choice.recommended { border-color: rgba(119,200,157,.55); }
    .choice.locked { opacity: .5; }

    .loot-list { display: grid; gap: 9px; margin-top: 12px; }
    .loot-row {
      border: 1px solid rgba(255,255,255,.10);
      border-radius: 12px;
      padding: 10px;
      background: rgba(255,255,255,.03);
    }
    .loot-row strong { color: var(--gold-bright); }
    .loot-reason { color: var(--muted); font-size: 12px; margin-top: 5px; }

    .big-action {
      width: 100%;
      min-height: 48px;
      margin-top: 14px;
      border: 1px solid rgba(215,185,110,.55);
      border-radius: 12px;
      background: rgba(215,185,110,.16);
      color: var(--gold-bright);
      font-weight: 700;
    }

    .boss-intro {
      display: grid;
      grid-template-columns: 140px 1fr;
      gap: 16px;
      align-items: center;
    }
    .boss-sigil {
      height: 150px;
      border-radius: 14px;
      display: grid;
      place-items: center;
      font-size: 72px;
      border: 1px solid rgba(215,185,110,.32);
      background: radial-gradient(circle at 50% 45%, rgba(215,185,110,.18), transparent 60%);
    }

    .orientation {
      position: absolute;
      z-index: 100;
      inset: 0;
      display: none;
      place-items: center;
      text-align: center;
      padding: 24px;
      background: #0c1117;
    }
    .orientation .box {
      max-width: 420px;
      border: 1px solid var(--line);
      border-radius: 16px;
      padding: 22px;
      background: rgba(255,255,255,.03);
    }
    .orientation .rotate { font-size: 48px; margin-bottom: 10px; }

    .ui-hidden .party-rail,
    .ui-hidden .enemy-rail,
    .ui-hidden .topbar,
    .ui-hidden .bottom-ui {
      opacity: 0;
      pointer-events: none;
    }

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

    @media (max-height: 520px) {
      .battlefield { inset: 48px 0 66px; }
      .unit-card { min-height: 46px; grid-template-columns: 36px 1fr; padding: 4px 6px; }
      .portrait { width: 36px; height: 36px; }
      .figure-wrap { min-height: 150px; }
      .control-btn, .mode-select { height: 38px; }
      .control-strip { padding: 5px; }
    }

    @media (max-width: 740px) {
      .brand { min-width: 142px; padding: 7px 9px; }
      .brand strong { font-size: 11px; }
      .brand span { font-size: 9px; }
      .run-status .chip:nth-child(2) { display: none; }
      .battlefield { grid-template-columns: minmax(128px, 20%) 1fr minmax(140px, 22%); }
      .unit-card { grid-template-columns: 34px 1fr; gap: 6px; padding: 5px 6px; }
      .portrait { width: 34px; height: 34px; }
      .unit-name { font-size: 10px; }
      .role, .tiny-line, .state-label { font-size: 8px; }
      .enemy-title { font-size: 9px; }
      .control-btn { padding: 0 8px; min-width: 42px; font-size: 12px; }
      .mode-select { max-width: 132px; font-size: 12px; }
      .choice-grid { grid-template-columns: 1fr; }
    }

    /* v0.1.2: compact identification and clearer attack targeting */
    .figure-nameplate {
      left: 50%;
      bottom: 0;
      width: auto;
      min-width: 48px;
      max-width: 76px;
      padding: 3px 5px;
      font-size: 9px;
      font-weight: 700;
      line-height: 1;
      overflow: visible;
      text-overflow: clip;
      box-shadow: 0 2px 8px rgba(0,0,0,.35);
    }

    .figure-nameplate.hero-label {
      border-color: rgba(215,185,110,.34);
      background: rgba(7,11,15,.78);
    }

    .figure-nameplate.enemy-label {
      max-width: 88px;
      border-color: rgba(216,108,115,.32);
      background: rgba(20,8,12,.76);
    }

    .plate-index {
      display: inline-grid;
      place-items: center;
      width: 14px;
      height: 14px;
      margin-right: 3px;
      border-radius: 50%;
      color: #17130d;
      background: var(--gold-bright);
      font-size: 8px;
      vertical-align: middle;
    }

    .action-layer {
      position: absolute;
      z-index: 19;
      inset: 0;
      overflow: hidden;
      pointer-events: none;
    }

    .attack-trace {
      position: absolute;
      height: 3px;
      border-radius: 999px;
      transform-origin: 0 50%;
      background: linear-gradient(90deg, rgba(240,217,151,.15), rgba(240,217,151,.95));
      box-shadow: 0 0 9px rgba(240,217,151,.62);
      animation: traceFlash .82s ease forwards;
    }

    .attack-trace::after {
      content: "";
      position: absolute;
      right: -1px;
      top: 50%;
      width: 9px;
      height: 9px;
      border-top: 3px solid currentColor;
      border-right: 3px solid currentColor;
      color: var(--gold-bright);
      transform: translateY(-50%) rotate(45deg);
    }

    .attack-trace.heal {
      background: linear-gradient(90deg, rgba(119,200,157,.15), rgba(119,200,157,.95));
      box-shadow: 0 0 9px rgba(119,200,157,.62);
    }

    .attack-trace.heal::after {
      color: var(--good);
    }

    @keyframes traceFlash {
      0% { opacity: 0; filter: brightness(.8); }
      18% { opacity: 1; filter: brightness(1.5); }
      72% { opacity: .85; }
      100% { opacity: 0; }
    }

    .action-cue {
      position: absolute;
      z-index: 24;
      left: 50%;
      top: calc(54px + var(--safe-top));
      transform: translateX(-50%);
      max-width: min(58vw, 380px);
      padding: 5px 10px;
      border: 1px solid rgba(215,185,110,.35);
      border-radius: 999px;
      background: rgba(7,11,15,.84);
      color: var(--gold-bright);
      text-align: center;
      font-size: 10px;
      font-weight: 700;
      letter-spacing: .015em;
      opacity: 0;
      pointer-events: none;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .action-cue.show {
      animation: cueShow 1.15s ease forwards;
    }

    .action-cue.heal {
      color: #9fe1b8;
      border-color: rgba(119,200,157,.42);
    }

    @keyframes cueShow {
      0% { opacity: 0; transform: translate(-50%, -5px); }
      15%, 70% { opacity: 1; transform: translate(-50%, 0); }
      100% { opacity: 0; transform: translate(-50%, -3px); }
    }

    @media (max-height: 430px) {
      .brand strong { font-size: 10px; }
      .brand span { font-size: 8px; }
      .run-status { font-size: 10px; padding: 5px 7px; }
      .chip { padding: 3px 6px; }
      .unit-name { font-size: 9px; }
      .role, .tiny-line, .state-label { font-size: 7px; }
      .enemy-title { font-size: 8px; }
      .control-btn,
      .mode-select { font-size: 10px; }
      .action-cue {
        top: calc(48px + var(--safe-top));
        font-size: 9px;
        padding: 4px 8px;
      }
    }

    /* v0.1.3: reliable iPhone lock/background recovery */
    .resume-overlay {
      position: absolute;
      z-index: 180;
      inset: 0;
      display: none;
      place-items: center;
      padding:
        calc(20px + var(--safe-top))
        calc(20px + var(--safe-right))
        calc(20px + var(--safe-bottom))
        calc(20px + var(--safe-left));
      background: rgba(5, 9, 13, .84);
      backdrop-filter: blur(7px);
      -webkit-backdrop-filter: blur(7px);
      pointer-events: none;
    }

    .resume-overlay.open {
      display: grid;
      pointer-events: auto;
    }

    .resume-panel {
      width: min(420px, 88vw);
      padding: 18px;
      border: 1px solid rgba(215,185,110,.42);
      border-radius: 18px;
      background: rgba(10,15,21,.98);
      text-align: center;
    }

    .resume-panel strong {
      display: block;
      color: var(--gold-bright);
      font-size: 18px;
      margin-bottom: 7px;
    }

    .resume-panel p {
      margin: 0;
      color: var(--muted);
      font-size: 12px;
      line-height: 1.45;
    }

    #resumeGameBtn {
      width: 100%;
      min-height: 58px;
      margin-top: 15px;
      border: 1px solid rgba(215,185,110,.65);
      border-radius: 14px;
      background: rgba(215,185,110,.19);
      color: var(--gold-bright);
      font-size: 16px;
      font-weight: 800;
      touch-action: manipulation;
    }

    .wake-refresh {
      transform: none;
      will-change: auto;
    }

    .app-suspended .action-cue,
    .app-suspended .attack-trace,
    .app-suspended .damage-pop {
      display: none !important;
    }

    /* v0.1.4: native iOS layout — no JS viewport sizing or fixed body */
    html {
      width: 100%;
      height: 100%;
      overflow: hidden;
      overscroll-behavior: none;
      background: var(--bg);
    }

    body {
      position: static;
      width: 100%;
      height: 100%;
      min-height: 100%;
      overflow: hidden;
      overscroll-behavior: none;
      background: var(--bg);
    }

    #app {
      position: relative;
      inset: auto;
      width: 100%;
      height: 100vh;
      min-height: 100vh;
      max-height: none;
      overflow: hidden;
    }

    @supports (height: 100dvh) {
      #app {
        height: 100dvh;
        min-height: 100dvh;
      }
    }

    .topbar {
      top: var(--safe-top);
      left: var(--safe-left);
      right: var(--safe-right);
      pointer-events: none;
    }

    .topbar > * {
      pointer-events: auto;
    }

    .icon-button {
      width: 48px;
      height: 48px;
      min-width: 48px;
      min-height: 48px;
      position: static;
      touch-action: auto;
    }

    .battlefield {
      inset:
        calc(52px + var(--safe-top))
        0
        calc(66px + var(--safe-bottom))
        0;
    }

    .bottom-ui {
      bottom: var(--safe-bottom);
    }

    .icon-button,
    .control-btn,
    .big-action,
    .choice,
    select,
    input,
    #resumeGameBtn {
      touch-action: auto;
    }

    @media (max-height: 430px) {
      .battlefield {
        inset:
          calc(49px + var(--safe-top))
          0
          calc(57px + var(--safe-bottom))
          0;
      }

      .control-strip {
        gap: 4px;
        padding: 4px;
        max-width: calc(100% - var(--safe-left) - var(--safe-right));
      }

      .control-btn,
      .mode-select {
        height: 36px;
        min-height: 36px;
        font-size: 10px;
      }

      .control-btn {
        padding: 0 7px;
      }

      .mode-select {
        max-width: 126px;
      }
    }

  

/* v0.2.0 foundation systems */
.loading-screen {
  position: fixed;
  z-index: 500;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 50% 35%, rgba(61,126,133,.28), transparent 38%),
    #091017;
  opacity: 1;
  visibility: visible;
  transition: opacity .35s ease, visibility .35s ease;
}

.loading-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-panel {
  width: min(390px, 82vw);
  padding: 22px;
  border: 1px solid rgba(215,185,110,.38);
  border-radius: 18px;
  background: rgba(9,15,21,.92);
  text-align: center;
}

.loading-mark {
  color: var(--gold-bright);
  font-size: 34px;
  line-height: 1;
  animation: loadingPulse 1.35s ease-in-out infinite;
}

.loading-panel strong {
  display: block;
  margin-top: 9px;
  color: var(--gold-bright);
  font-size: 17px;
}

.loading-panel span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
}

.loading-track {
  height: 7px;
  margin-top: 15px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255,255,255,.09);
}

.loading-fill {
  width: 8%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--gold), var(--gold-bright));
  transition: width .24s ease;
}

@keyframes loadingPulse {
  0%,100% { opacity: .55; transform: scale(.96) rotate(0deg); }
  50% { opacity: 1; transform: scale(1.08) rotate(180deg); }
}

.drawer-note {
  margin-top: -4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.audio-settings input[type="range"] {
  width: 100%;
  accent-color: var(--gold);
}

.audio-enable-row {
  grid-template-columns: 1fr auto;
}

.small-action,
.file-action {
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid rgba(215,185,110,.42);
  border-radius: 10px;
  background: rgba(215,185,110,.10);
  color: var(--gold-bright);
  font-weight: 700;
  text-align: center;
  cursor: pointer;
}

.small-action.active {
  border-color: rgba(119,200,157,.55);
  background: rgba(119,200,157,.12);
  color: #9fe1b8;
}

.backup-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}
