:root {
  color-scheme: dark;
  --bg: #111816;
  --panel: #1a2622;
  --panel-2: #23352f;
  --line: rgba(238, 223, 174, .17);
  --text: #f6efd7;
  --muted: #b9c3af;
  --gold: #e5c35f;
  --jade: #5fc27d;
  --blue: #74c7dc;
  --red: #d8665d;
  --stone: #9e9a86;
  --shadow: 0 18px 48px rgba(0, 0, 0, .35);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  overscroll-behavior-x: none;
  touch-action: pan-x pan-y;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  touch-action: pan-x pan-y;
  user-select: none;
}

input,
textarea {
  -webkit-user-select: text;
  user-select: text;
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .08);
  color: var(--text);
  font: inherit;
  padding: 0 12px;
  outline: none;
}

label span {
  display: block;
  margin: 12px 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--gold);
  color: #21190a;
  font: inherit;
  font-weight: 800;
  min-height: 42px;
  padding: 0 16px;
  cursor: pointer;
  box-shadow: 0 8px 16px rgba(229, 195, 95, .2);
}

button:disabled {
  cursor: not-allowed;
  filter: grayscale(.65);
  opacity: .55;
  box-shadow: none;
  cursor: pointer;
}

.game-shell {
  width: min(100%, 480px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
  background: #111816;
}

.game-shell.locked {
  display: none;
}

.auth-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 18px;
  background: #101715;
}

.auth-screen.hidden {
  display: none;
}

.auth-card {
  width: min(100%, 420px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(26, 38, 34, .94);
  box-shadow: var(--shadow);
  padding: 18px;
}

.auth-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.auth-actions button:last-child {
  background: rgba(255, 255, 255, .1);
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: none;
}

.auth-message {
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 800;
}

.policy-line {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 32px;
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  font-size: 15px;
  line-height: 1.2;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  min-width: 42px;
  padding: 0;
  background: rgba(255, 255, 255, .1);
  color: var(--gold);
  border: 1px solid var(--line);
  box-shadow: none;
}

.resource-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.resource-strip article,
.status-grid article {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(26, 38, 34, .84);
  padding: 9px 8px;
}

.resource-strip span,
.status-grid span,
.action-row p,
.raid-card p {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.resource-strip strong,
.status-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 16px;
  line-height: 1;
  overflow-wrap: anywhere;
}

.map-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px;
  background: #0f1719;
  box-shadow: var(--shadow);
}

.map-stage {
  position: relative;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: 6px;
  isolation: isolate;
  touch-action: manipulation;
}

.map-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
  pointer-events: none;
}

.fog-ring {
  position: absolute;
  inset: -8%;
  z-index: 2;
  border: 32px solid rgba(18, 27, 30, .34);
  border-radius: 50%;
  pointer-events: none;
  animation: breathe 6s ease-in-out infinite;
}

.building-node {
  position: absolute;
  z-index: 5;
  display: grid;
  place-items: center;
  min-width: 54px;
  min-height: 38px;
  border: 1px solid rgba(255, 239, 182, .55);
  border-radius: 8px;
  background: rgba(28, 33, 27, .8);
  color: #fff4c0;
  font-size: 11px;
  font-weight: 800;
  box-shadow: 0 8px 16px rgba(0, 0, 0, .28);
}

.building-node::before {
  content: "";
  position: absolute;
  top: -30px;
  width: 42px;
  height: 42px;
  background: center / contain no-repeat;
  z-index: -1;
}

.building-node[data-building="shrine"]::before {
  background-image: url("assets/effects/building-shrine.png?v=20260619b");
}

.building-node[data-building="field"]::before {
  background-image: url("assets/effects/building-field.png?v=20260619b");
}

.building-node[data-building="mine"]::before {
  background-image: url("assets/effects/building-mine.png?v=20260619b");
}

.building-node[data-building="lodge"]::before {
  background-image: url("assets/effects/building-lodge.png?v=20260619b");
}

.building-node[data-building="barracks"]::before {
  background-image: url("assets/effects/building-barracks.png?v=20260619b");
}

.building-node[data-building="wall"]::before {
  background-image: url("assets/effects/building-wall.png?v=20260619b");
}

.building-node em {
  display: block;
  margin-top: 1px;
  color: #ffe79a;
  font-size: 10px;
  font-style: normal;
  line-height: 1;
}

.building-node.upgrading {
  border-color: rgba(116, 199, 220, .85);
  box-shadow: 0 0 0 2px rgba(116, 199, 220, .2), 0 8px 16px rgba(0, 0, 0, .28);
}

.building-node.upgrading::after {
  content: "";
  position: absolute;
  inset: -6px;
  border: 1px solid rgba(116, 199, 220, .5);
  border-radius: 12px;
  animation: buildPulse 1.4s ease-in-out infinite;
}

.shrine { left: 46%; top: 46%; --node-color: #f2d472; }
.field { left: 20%; top: 66%; --node-color: #d9c35d; }
.mine { left: 66%; top: 31%; --node-color: #80c7d9; }
.lodge { left: 34%; top: 70%; --node-color: #c58a5d; }
.barracks { left: 72%; top: 54%; --node-color: #ca625b; }
.wall { left: 79%; top: 42%; --node-color: #9e9a86; }

.work-burst {
  position: absolute;
  left: 36%;
  top: 39%;
  z-index: 8;
  display: none;
  border: 1px solid rgba(116, 199, 220, .55);
  border-radius: 999px;
  background: rgba(20, 42, 42, .82);
  color: #d9fbff;
  padding: 5px 9px;
  font-size: 11px;
  font-weight: 800;
  pointer-events: none;
  animation: floatNotice 1.8s ease-out both;
}

.work-burst.active {
  display: block;
}

.monster.active {
  display: block;
}

.raid-slash {
  position: absolute;
  left: 66%;
  top: 42%;
  z-index: 9;
  display: none;
  width: 78px;
  height: 78px;
  background: url("assets/effects/raid-slash.png?v=20260619b") center / contain no-repeat;
  pointer-events: none;
}

.raid-slash::before,
.raid-slash::after {
  display: none;
}

.raid-slash.active {
  display: block;
  animation: slashPop .55s ease-out both;
}

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

.status-grid strong {
  font-size: 14px;
}

.tabbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  padding: 6px 0 10px;
  background: rgba(19, 29, 26, .96);
  backdrop-filter: blur(10px);
}

.tab {
  min-height: 38px;
  padding: 0 8px;
  background: rgba(255, 255, 255, .08);
  color: var(--muted);
  border: 1px solid var(--line);
  box-shadow: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.tab.active {
  background: var(--gold);
  color: #21190a;
}

.panel {
  display: none;
  padding-bottom: 12px;
  contain: layout paint;
}

.panel.active {
  display: block;
}

.action-row,
.build-item,
.raid-card,
.tribe-card,
.auto-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 72px;
  margin-bottom: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(26, 38, 34, .9);
  padding: 12px;
}

.action-row div,
.build-item div,
.tribe-card div,
.auto-card div {
  min-width: 0;
}

.action-row p,
.build-item p,
.tribe-card p,
.auto-card p,
.policy-card span {
  margin-top: 5px;
}

.build-list,
.tribe-list {
  display: grid;
  gap: 9px;
}

.policy-grid {
  display: grid;
  gap: 9px;
  margin-bottom: 9px;
}

.policy-card {
  display: block;
  width: 100%;
  min-height: 68px;
  border: 1px solid var(--line);
  background: rgba(26, 38, 34, .9);
  color: var(--text);
  text-align: left;
  box-shadow: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.policy-card strong,
.policy-card span {
  display: block;
}

.policy-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.35;
}

.policy-card.active {
  border-color: rgba(229, 195, 95, .72);
  background: rgba(95, 82, 42, .82);
  color: #fff3bf;
}

.auto-card strong,
#workerSplit {
  color: var(--gold);
  white-space: nowrap;
}

.build-item {
  position: relative;
  display: block;
}

.build-item::after {
  content: attr(data-plan);
  position: absolute;
  right: 12px;
  top: 12px;
  border-radius: 999px;
  background: rgba(116, 199, 220, .14);
  color: #bcecf5;
  padding: 4px 7px;
  font-size: 10px;
  font-weight: 800;
}

.raid-card {
  display: block;
}

.world-card,
.target-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(26, 38, 34, .9);
  padding: 12px;
}

.world-card p,
.target-card p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.world-card button,
.target-card button {
  min-width: 74px;
}

.world-map {
  position: relative;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10191c url("assets/world-map.png?v=20260619d") center / cover no-repeat;
  touch-action: none;
}

.world-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.march-line {
  position: absolute;
  z-index: 2;
  height: 96px;
  margin-top: -48px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  padding: 0;
  transform-origin: left center;
  pointer-events: auto;
  box-shadow: none;
  --route-color: #ffd35a;
  --route-glow: rgba(255, 87, 64, .5);
  --route-curve: 28px;
}

.march-line::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: calc(50% - var(--route-curve));
  height: var(--route-curve);
  border-top: 2px dashed var(--route-color);
  border-radius: 50% 50% 0 0 / 100% 100% 0 0;
  background: none;
  filter: drop-shadow(0 0 4px var(--route-glow)) drop-shadow(0 0 9px var(--route-glow));
  opacity: .92;
}

.march-line.fighting::before {
  --route-color: #ff6357;
  --route-glow: rgba(255, 59, 52, .68);
}

.march-line.support::before {
  --route-color: #79f0a1;
  --route-glow: rgba(99, 236, 142, .58);
}

.march-line.cancelable::after {
  content: "取消";
  position: absolute;
  right: 8px;
  top: -18px;
  border-radius: 999px;
  background: rgba(15, 21, 21, .82);
  color: #ffe7a2;
  padding: 2px 6px;
  font-size: 10px;
  font-weight: 800;
}

.troop-flow {
  position: absolute;
  z-index: 5;
  width: 34px;
  height: 34px;
  margin-left: -17px;
  margin-top: -17px;
  background: none;
  filter: drop-shadow(0 4px 5px rgba(0, 0, 0, .55));
  pointer-events: none;
}

.troop-flow::after {
  content: attr(data-troops);
  position: absolute;
  left: 21px;
  top: -2px;
  border-radius: 999px;
  background: rgba(24, 31, 30, .88);
  color: var(--gold);
  padding: 1px 5px;
  font-size: 10px;
  font-weight: 900;
}

.march-line.support.cancelable::after {
  content: "撤援";
  color: #b9ffd0;
}

.troop-flow.single {
  width: 26px;
  height: 26px;
  margin-left: -13px;
  margin-top: -13px;
}

.troop-flow.single::after {
  display: none;
}

.troop-flow.single.incoming {
  filter: drop-shadow(0 4px 5px rgba(0, 0, 0, .55)) drop-shadow(0 0 8px rgba(229, 80, 67, .42));
}

.realm-node {
  position: absolute;
  z-index: 8;
  width: 96px;
  height: 92px;
  min-height: 0;
  margin-left: -48px;
  margin-top: -46px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  padding: 0;
  text-align: center;
  user-select: none;
  box-shadow: none;
}

.realm-node::before {
  content: none;
  display: none;
}

.realm-art {
  display: block;
  width: 90px;
  height: 72px;
  margin: 0 auto;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  filter: drop-shadow(0 7px 7px rgba(0, 0, 0, .48));
}

.realm-node.own {
  z-index: 9;
  border-color: transparent;
  box-shadow: none;
}

.realm-node.npc {
  border-color: rgba(116, 199, 220, .42);
}

.realm-node strong,
.realm-node span {
  display: block;
  position: absolute;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.realm-node strong {
  left: 50%;
  bottom: -6px;
  max-width: 88px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: rgba(13, 19, 19, .78);
  color: #fff3bf;
  padding: 2px 6px;
  font-size: 10px;
  line-height: 1.2;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .7);
}

.realm-node span {
  left: 50%;
  top: 2px;
  transform: translateX(-50%);
  min-width: 54px;
  border-radius: 999px;
  background: rgba(13, 19, 19, .76);
  color: var(--gold);
  padding: 1px 5px;
  font-size: 10px;
  font-weight: 800;
  text-align: center;
}

.drag-line {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 50%;
  display: none;
  height: 3px;
  border-radius: 999px;
  background: var(--gold);
  transform-origin: left center;
  pointer-events: none;
  box-shadow: 0 0 10px rgba(229, 195, 95, .55);
}

.drag-line.active {
  display: block;
}

.target-card {
  display: block;
  margin-top: 9px;
}

.target-card button {
  width: 100%;
  margin-top: 10px;
}

.raid-card button {
  width: 100%;
  margin-top: 12px;
  background: var(--red);
  color: #fff8ed;
  box-shadow: 0 8px 16px rgba(216, 102, 93, .2);
}

.log-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.log-list li {
  border-left: 3px solid var(--gold);
  border-radius: 6px;
  background: rgba(255, 255, 255, .07);
  padding: 9px 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 50;
  max-width: min(420px, calc(100vw - 28px));
  transform: translate(-50%, 18px);
  border-radius: 8px;
  background: rgba(245, 233, 183, .94);
  color: #1a201c;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes breathe {
  50% { transform: scale(1.03); opacity: .74; }
}

@keyframes pulse {
  50% { transform: scale(1.14); }
}

@keyframes buildPulse {
  50% { transform: scale(1.08); opacity: .35; }
}

@keyframes floatNotice {
  0% { opacity: 0; transform: translateY(8px); }
  20% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-24px); }
}

@keyframes slashPop {
  0% { opacity: 0; transform: scale(.65) rotate(-8deg); }
  35% { opacity: 1; transform: scale(1.08) rotate(2deg); }
  100% { opacity: 0; transform: scale(1.24) rotate(8deg); }
}

@media (max-width: 360px) {
  .game-shell {
    padding-left: 10px;
    padding-right: 10px;
  }

  .resource-strip,
  .status-grid {
    gap: 6px;
  }

  .resource-strip article,
  .status-grid article {
    padding: 8px 6px;
  }

  .resource-strip strong,
  .status-grid strong {
    font-size: 13px;
  }

  button {
    padding: 0 12px;
  }
}
