:root {
  --bg: #070b13;
  --bg-soft: #0f1728;
  --panel: #131c2f;
  --panel-soft: #1a2540;
  --line: #2a3a5d;
  --text: #e8efff;
  --muted: #9eb0d0;
  --green: #4ade80;
  --yellow: #facc15;
  --orange: #fb923c;
  --red: #fb7185;
  --cyan: #38bdf8;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at 20% 0%, #162338 0%, var(--bg) 56%);
  color: var(--text);
  font-family: "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.app {
  width: min(100vw, 560px);
  min-height: 100vh;
  background: linear-gradient(180deg, rgba(15, 23, 40, .95), rgba(9, 14, 26, .97));
  border-inline: 1px solid rgba(92, 121, 170, 0.2);
  position: relative;
}

.app-shell {
  padding: 14px 12px calc(98px + env(safe-area-inset-bottom, 0px));
  display: grid;
  gap: 12px;
}

.brand-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.logo h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 1px;
}

.logo p {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.quick-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.objective-bar {
  border: 1px solid #2c3f62;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(31, 52, 88, .72), rgba(20, 34, 58, .84));
  padding: 10px;
  display: grid;
  gap: 6px;
}

.objective-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.objective-top b {
  font-size: 14px;
}

.objective-desc {
  font-size: 12px;
  color: #d5e3ff;
  line-height: 1.4;
}

.objective-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  border: 1px solid #46649b;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 11px;
  color: #b7ccf2;
  background: rgba(17, 29, 48, .52);
}

.topbar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.topbar::-webkit-scrollbar { display: none; }

.stat {
  min-width: 96px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
  background: rgba(15, 23, 40, .82);
  display: grid;
  gap: 2px;
  flex: 0 0 auto;
}

.stat span {
  font-size: 11px;
  color: var(--muted);
}

.stat b {
  font-size: 18px;
  line-height: 1.1;
}

.threat-board {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px;
  background: rgba(16, 24, 40, 0.86);
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
}

.threat-item {
  min-width: 220px;
  scroll-snap-align: start;
  border: 1px solid #2c3d62;
  border-radius: 10px;
  padding: 8px;
  background: #111b2f;
}

.threat-name {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  margin-bottom: 5px;
}

.threat-tip {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.bar {
  width: 100%;
  height: 10px;
  background: #0b1323;
  border-radius: 999px;
  border: 1px solid #233554;
  overflow: hidden;
}

.fill { height: 100%; transition: width .25s ease; }
.fill.green { background: var(--green); }
.fill.yellow { background: var(--yellow); }
.fill.orange { background: var(--orange); }
.fill.red { background: var(--red); }

.content {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(15, 23, 40, 0.9);
  padding: 12px;
  min-height: 43vh;
  will-change: transform, opacity;
  touch-action: pan-y;
}

.content.tab-enter {
  animation: tab-enter .24s cubic-bezier(.22, .8, .36, 1);
}

@keyframes tab-enter {
  from {
    opacity: .38;
    transform: translateY(8px) scale(.988);
    filter: saturate(.8);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: saturate(1);
  }
}

.panel-title {
  margin: 0 0 8px;
  font-size: 17px;
}

.meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.card {
  border: 1px solid #2b3d61;
  border-radius: 12px;
  background: #101a2f;
  padding: 10px;
}

.card h4 {
  margin: 0 0 6px;
  font-size: 15px;
}

.list-line {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
  font-size: 13px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.split {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  display: block;
  overflow-x: auto;
}

.table thead,
.table tbody,
.table tr { width: 100%; }

.table th,
.table td {
  border-bottom: 1px solid #2a3b5d;
  padding: 8px 6px;
  text-align: left;
  white-space: nowrap;
}

.table th {
  color: #b9cae7;
  font-size: 12px;
}

button {
  border: 1px solid #3a588c;
  border-radius: 11px;
  background: linear-gradient(180deg, #2e4d82, #23406f);
  color: #eef4ff;
  padding: 10px 12px;
  min-height: 42px;
  font-size: 13px;
  cursor: pointer;
}

button:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px); }

button.small {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 12px;
}

button.ghost {
  background: #1a2742;
  border-color: #364d74;
}

button.danger {
  background: linear-gradient(180deg, #8e3245, #6f2535);
  border-color: #b14c61;
}

.tag {
  font-size: 11px;
  border-radius: 999px;
  border: 1px solid #3b4f74;
  color: #b9c8e4;
  padding: 2px 7px;
}

.badge {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid #3b4f74;
  display: inline-block;
}

.badge.red { border-color: #a9475b; color: #ffb4c1; }
.badge.orange { border-color: #ad6c3d; color: #ffd2ac; }
.badge.yellow { border-color: #a48a3d; color: #ffeab2; }
.badge.green { border-color: #3c8f62; color: #b9ffdb; }

hr.soft {
  border: none;
  border-top: 1px dashed #34486e;
  margin: 10px 0;
}

.log-drawer {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(12, 18, 32, 0.95);
  overflow: hidden;
}

.log-drawer > summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px;
  cursor: pointer;
  user-select: none;
  font-weight: 600;
}

.log-drawer > summary::-webkit-details-marker { display: none; }

.log-panel {
  border-top: 1px solid #2a3c5f;
  max-height: 220px;
  overflow: auto;
}

.log-list {
  padding: 8px 10px;
  display: grid;
  gap: 5px;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

.log-item {
  color: #d8e4fc;
  border-left: 2px solid #375181;
  padding-left: 6px;
}

.log-item.warn { border-color: #db7d3d; }
.log-item.bad { border-color: #ef5a74; }
.log-item.good { border-color: #4ade80; }

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(100vw, 560px);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid rgba(93, 122, 171, 0.32);
  background: rgba(8, 12, 22, 0.96);
  backdrop-filter: blur(8px);
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
  z-index: 15;
}

.tab-btn {
  border: 1px solid #30476f;
  border-radius: 11px;
  min-height: 48px;
  padding: 4px 3px;
  background: #15233e;
  color: #d5e4fe;
  display: grid;
  place-items: center;
  gap: 2px;
  transition: transform .18s ease, border-color .2s ease, background .2s ease;
}

.tab-icon {
  font-size: 15px;
  line-height: 1;
}

.tab-label {
  font-size: 11px;
  line-height: 1;
  letter-spacing: .4px;
}

.tab-btn.active {
  border-color: var(--cyan);
  background: linear-gradient(180deg, #1f3d66, #203252);
  color: #f4f9ff;
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(24, 61, 103, .35);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 15, 0.68);
  display: grid;
  place-items: center;
  z-index: 99;
  padding: 10px;
}

.modal.hidden { display: none; }

.modal-card {
  width: min(980px, 100%);
  max-height: 92vh;
  overflow: auto;
  background: #121c2e;
  border: 1px solid #344a74;
  border-radius: 12px;
}

.modal-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  border-bottom: 1px solid #33486d;
  background: #17253d;
}

.modal-head h3 {
  margin: 0;
  font-size: 16px;
}

.modal-body {
  padding: 12px;
  color: #dce8ff;
}

.tutorial-grid {
  display: grid;
  gap: 8px;
}

.tutorial-card {
  border: 1px solid #30466e;
  border-radius: 10px;
  background: rgba(14, 22, 38, .75);
  padding: 9px;
}

.tutorial-card b {
  display: block;
  margin-bottom: 4px;
  color: #e9f1ff;
  font-size: 13px;
}

.tutorial-card p {
  margin: 0;
  color: #bdd0f1;
  font-size: 12px;
  line-height: 1.45;
}

.reg-list {
  display: grid;
  gap: 8px;
}

.reg-item {
  border: 1px solid #334b74;
  border-radius: 10px;
  background: rgba(15, 24, 41, .75);
  padding: 8px;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: start;
  gap: 8px;
}

.reg-item input {
  margin-top: 3px;
}

.reg-item b {
  display: block;
  font-size: 13px;
  margin-bottom: 3px;
}

.reg-item p {
  margin: 0;
  font-size: 12px;
  color: #b9cdef;
  line-height: 1.4;
}

.qa-banner {
  border: 1px solid #355a88;
  border-radius: 10px;
  padding: 8px;
  margin-bottom: 8px;
  display: grid;
  gap: 4px;
  background: rgba(20, 34, 57, .74);
}

.qa-banner.good {
  border-color: #3f9167;
}

.qa-banner.warn {
  border-color: #a06f42;
}

.qa-banner b {
  font-size: 13px;
}

.qa-banner span {
  font-size: 12px;
  color: #c2d6f6;
}

.qa-list {
  margin: 0 0 8px 18px;
  padding: 0;
  color: #ffdcb6;
  font-size: 12px;
  line-height: 1.45;
}

.qa-pre {
  margin: 0;
  border: 1px solid #344b73;
  border-radius: 10px;
  background: rgba(10, 16, 29, .85);
  color: #d7e7ff;
  font-size: 12px;
  padding: 10px;
  white-space: pre-wrap;
  word-break: break-word;
}

.battle-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}

.battle-summary > div {
  border: 1px solid #2a3a59;
  border-radius: 8px;
  background: #10182a;
  padding: 8px;
  display: grid;
  gap: 4px;
}

.battle-summary b {
  font-size: 12px;
  color: #9fb0cc;
}

.battle-scene-wrap {
  border: 1px solid #31456b;
  border-radius: 10px;
  background: #0c1322;
  padding: 8px;
  margin-bottom: 8px;
}

.battle-scene {
  width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid #2b3c5d;
  background: #0b1322;
  display: block;
}

.battle-scene-tip {
  margin-top: 6px;
  color: #9fb0cc;
  font-size: 12px;
}

.battle-controls {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.battle-controls button {
  background: rgba(28, 41, 65, 0.82);
  border-color: #425a86;
  backdrop-filter: blur(4px);
}

.manual-battle-wrap {
  display: grid;
  gap: 8px;
}

.manual-battle-hud {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.manual-prompt {
  color: #cfe0ff;
  font-size: 12px;
  padding: 4px 8px;
  border: 1px solid #334c77;
  border-radius: 8px;
  background: rgba(21, 32, 54, 0.65);
}

.manual-turn-queue {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.turn-chip {
  border: 1px solid #3a5079;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  color: #bfd2f5;
  background: rgba(18, 31, 51, .7);
}

.turn-chip.active {
  border-color: #70d2ff;
  color: #ecf9ff;
  background: rgba(45, 83, 126, .62);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, .2);
}

.turn-chip.dead {
  opacity: .45;
  text-decoration: line-through;
}

.manual-skill-panel,
.manual-target-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 6px;
}

.manual-status-board {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.manual-status-col {
  border: 1px solid #2d4164;
  border-radius: 10px;
  background: rgba(14, 23, 40, .72);
  padding: 8px;
}

.manual-status-title {
  font-size: 12px;
  color: #9fb3d8;
  margin-bottom: 6px;
}

.manual-status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 6px;
}

.debrief-wrap {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  width: 100%;
}

.debrief-card {
  border: 1px solid #2f4468;
  border-radius: 10px;
  background: rgba(14, 22, 37, .72);
  padding: 9px;
}

.debrief-card b {
  display: block;
  margin-bottom: 5px;
  font-size: 13px;
}

.debrief-card p {
  margin: 0 0 4px;
  font-size: 12px;
  color: #bfd2f4;
}

.manual-unit {
  border: 1px solid #3b5076;
  border-radius: 8px;
  padding: 6px;
  background: rgba(22, 34, 55, .74);
}

.manual-unit.ally {
  border-color: #4f7cb5;
}

.manual-unit.enemy {
  border-color: #9a556d;
}

.manual-unit.active {
  box-shadow: 0 0 0 2px rgba(114, 220, 255, .22);
}

.manual-unit.dead {
  opacity: .5;
}

.manual-unit-top {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 4px;
}

.manual-unit-top b {
  font-size: 12px;
}

.manual-unit-top span {
  font-size: 10px;
  color: #9db3d8;
}

.mini-bar {
  height: 6px;
  border-radius: 999px;
  overflow: hidden;
  background: #17243d;
  border: 1px solid #2f4265;
  margin-bottom: 3px;
}

.mini-bar i {
  display: block;
  height: 100%;
  width: 0;
}

.mini-bar.hp i {
  background: linear-gradient(90deg, #58e390, #3fcf84);
}

.mini-bar.energy i {
  background: linear-gradient(90deg, #68d7ff, #49a8ff);
}

.mini-meta {
  font-size: 10px;
  color: #b4c7e9;
  margin-bottom: 3px;
}

.manual-action-btn {
  min-height: 56px;
  display: grid;
  gap: 2px;
  align-content: center;
  text-align: left;
  padding: 8px 10px;
  background: linear-gradient(180deg, #2a4a7f, #213c68);
  border: 1px solid #41629a;
}

.manual-action-btn b {
  font-size: 13px;
  line-height: 1.1;
}

.manual-action-btn span {
  font-size: 11px;
  color: #cfe0ff;
  opacity: .92;
  line-height: 1.2;
}

.manual-action-btn small {
  font-size: 10px;
  color: #9ec3ff;
  opacity: .95;
  line-height: 1.2;
}

.manual-action-btn.is-ready {
  border-color: #4f77bc;
}

.manual-action-btn.is-cd {
  border-color: #6f5f99;
  background: linear-gradient(180deg, #3a3859, #31304b);
}

.manual-action-btn.is-low-energy {
  border-color: #8a6a3f;
  background: linear-gradient(180deg, #4f3f2e, #3f3326);
}

.manual-action-btn.is-selected {
  box-shadow: 0 0 0 2px rgba(113, 218, 255, .28);
  border-color: #75d7ff;
}

.manual-action-btn.is-recommended {
  outline: 1px dashed rgba(144, 235, 255, .65);
  outline-offset: 1px;
}

.manual-action-btn.is-disabled {
  opacity: .58;
  filter: grayscale(.18);
  border-color: #3a4d72;
}

.manual-target-btn {
  text-align: left;
  border-color: #46628c;
}

.manual-target-btn.enemy {
  border-color: #9f4f66;
}

.manual-target-btn.ally {
  border-color: #4d8f77;
}

.manual-target-btn.is-selected {
  box-shadow: 0 0 0 2px rgba(136, 210, 255, .26);
  border-color: #87d4ff;
}

.manual-target-btn.is-recommended {
  outline: 1px dashed rgba(155, 226, 255, .72);
  outline-offset: 1px;
}

.manual-log {
  max-height: 24vh;
}

.battle-state {
  margin-bottom: 6px;
  font-size: 12px;
  color: #cfe0ff;
}

.battle-log {
  border: 1px solid #31456b;
  border-radius: 10px;
  background: #0c1322;
  padding: 8px 10px;
  max-height: 45vh;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  line-height: 1.5;
}

.battle-line-index { color: #7f95bc; }

@media (min-width: 900px) {
  .app {
    width: min(96vw, 1180px);
    min-height: 96vh;
    border-radius: 18px;
    overflow: hidden;
    border: 1px solid #2e3f62;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .4);
  }

  .app-shell {
    padding-inline: 16px;
  }

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

  .split {
    grid-template-columns: 1.05fr 0.95fr;
  }

  .manual-status-board {
    grid-template-columns: 1fr 1fr;
  }

  .debrief-wrap {
    grid-template-columns: 1fr 1fr;
  }

  .threat-board {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    overflow: visible;
  }

  .threat-item {
    min-width: 0;
  }

  .bottom-nav {
    width: min(96vw, 1180px);
  }
}
