:root {
  --bg: #0c0f14;
  --panel: #10161e;
  --panel-light: #1a2330;
  --panel-dark: #0a0e13;
  --text: #d9e2ec;
  --text-dim: #8a97a8;
  --mint: #6ee7b7;
  --mint-dark: #2dd4bf;
  --mint-glow: rgba(45, 212, 191, 0.35);
  --amber: #f59e0b;
  --amber-light: #fbbf24;
  --amber-glow: rgba(245, 158, 11, 0.35);
  --danger: #ef4444;
  --border: #2b3648;
  --border-bright: #3e4d62;
  --radius: 10px;
  --transition: 0.2s ease;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --grid-line: rgba(110, 231, 183, 0.08);
  --grid-dot: rgba(110, 231, 183, 0.18);
  --tactical-line: rgba(245, 158, 11, 0.25);
  --tactical-squad: rgba(110, 231, 183, 0.22);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow-x: hidden;
  min-height: 100vh;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px),
    radial-gradient(circle at 20% 30%, rgba(45, 212, 191, 0.05) 0%, transparent 50%),
    radial-gradient(circle at 80% 70%, rgba(245, 158, 11, 0.04) 0%, transparent 50%);
  background-size: 40px 40px, 40px 40px, 100% 100%, 100% 100%;
  position: relative;
}
body::after {
  content: "";
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(0deg, transparent 0px, transparent 3px, rgba(255,255,255,0.01) 3px, rgba(255,255,255,0.01) 4px);
  pointer-events: none;
  z-index: 9999;
}
button { font-family: inherit; cursor: pointer; }

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

/* Header / HUD */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.4rem;
  background: linear-gradient(180deg, rgba(16, 22, 30, 0.95) 0%, rgba(10, 14, 19, 0.95) 100%);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(4px);
}
.app-title {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--mint);
  letter-spacing: 0.08em;
  text-shadow: 0 0 12px var(--mint-glow);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.app-title::before {
  content: "◭";
  font-size: 1.2em;
  color: var(--amber);
}
.app-buttons {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}
.btn {
  background: var(--panel-light);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}
.btn::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 30%, rgba(255,255,255,0.05) 50%, transparent 70%);
  pointer-events: none;
}
.btn:hover:not(:disabled) {
  background: #233042;
  border-color: var(--mint-dark);
  box-shadow: 0 0 10px rgba(45, 212, 191, 0.25);
}
.btn.primary {
  background: var(--mint-dark);
  color: #0c0f14;
  font-weight: 700;
  border-color: var(--mint);
}
.btn.primary:hover:not(:disabled) {
  background: var(--mint);
  box-shadow: 0 0 15px rgba(110, 231, 183, 0.5);
}
.btn.danger { color: var(--danger); }
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Home */
.home {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.6rem;
  padding: 3rem 2rem;
  text-align: center;
  position: relative;
}
.home::before {
  content: "TACTICAL COMMAND";
  position: absolute;
  top: 8%;
  left: 0;
  right: 0;
  font-size: clamp(3rem, 12vw, 8rem);
  font-weight: 900;
  color: rgba(255,255,255,0.03);
  letter-spacing: 0.2em;
  pointer-events: none;
  z-index: -1;
}
.home h1 {
  font-size: 2.8rem;
  color: var(--mint);
  text-shadow: 0 0 20px rgba(110, 231, 183, 0.4);
  letter-spacing: 0.03em;
}
.home .tagline {
  font-size: 1.2rem;
  color: var(--amber-light);
  border-bottom: 1px dashed var(--amber-glow);
  padding-bottom: 0.6rem;
}
.team-select {
  display: flex;
  flex-wrap: wrap;
  gap: 1.2rem;
  justify-content: center;
}
.team-card {
  background: linear-gradient(145deg, var(--panel) 0%, var(--panel-dark) 100%);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1rem;
  width: 200px;
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
  position: relative;
}
.team-card::before {
  content: "";
  position: absolute;
  top: -2px; left: -2px; right: -2px; bottom: -2px;
  border-radius: calc(var(--radius) + 2px);
  border: 1px solid transparent;
  transition: border-color 0.2s;
}
.team-card:hover::before {
  border-color: var(--mint-dark);
  box-shadow: 0 0 12px var(--mint-glow);
}
.team-card.selected {
  border-color: var(--amber);
  box-shadow: 0 0 18px var(--amber-glow);
}
.team-card.selected::before {
  border-color: var(--amber);
}
.team-card .team-name {
  font-size: 1.3rem;
  font-weight: 800;
  margin-bottom: 0.4rem;
  color: var(--mint);
}
.team-card .team-desc {
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.4;
}
.seed-input {
  background: var(--panel-dark);
  border: 1px solid var(--border-bright);
  color: var(--text);
  padding: 0.6rem 1rem;
  border-radius: 6px;
  width: 280px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}
.seed-input:focus {
  border-color: var(--mint-dark);
  box-shadow: 0 0 8px rgba(45, 212, 191, 0.4);
}
.home-actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}
.nav-links {
  display: flex;
  gap: 1rem;
  font-size: 0.9rem;
}
.nav-links a {
  color: var(--mint);
  text-decoration: none;
  border-bottom: 1px dotted var(--mint-dark);
  transition: color 0.2s;
}
.nav-links a:hover {
  color: var(--amber-light);
}

/* Map */
.map-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 550px;
  background: radial-gradient(ellipse at 50% 40%, rgba(45,212,191,0.06) 0%, transparent 60%),
              repeating-linear-gradient(45deg, rgba(255,255,255,0.01) 0px, rgba(255,255,255,0.01) 2px, transparent 2px, transparent 10px);
}
.map-svg {
  width: 100%;
  height: 100%;
  display: block;
}
.map-edge {
  stroke: #3b4a5a;
  stroke-width: 2;
  fill: none;
  stroke-dasharray: 6 4;
}
.map-node {
  cursor: pointer;
  transition: var(--transition);
}
.map-node circle {
  fill: var(--panel-light);
  stroke: var(--border-bright);
  stroke-width: 2;
  filter: drop-shadow(0 0 2px rgba(0,0,0,0.7));
}
.map-node text {
  fill: var(--text);
  font-size: 11px;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
  font-weight: 400;
}
.map-node.available circle {
  fill: var(--mint-dark);
  stroke: var(--mint);
  animation: nodePulse 2s infinite;
}
.map-node.available text {
  fill: #0c0f14;
  font-weight: 700;
}
.map-node.completed circle {
  fill: #34415a;
  stroke: #5a6a7a;
}
.map-node.current circle {
  stroke: var(--amber);
  stroke-width: 3;
  filter: drop-shadow(0 0 6px var(--amber-glow));
}
@keyframes nodePulse {
  0%, 100% { stroke-opacity: 1; }
  50% { stroke-opacity: 0.5; }
}

/* Battle Arena */
.battle {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  grid-template-rows: 1fr auto;
  gap: 1rem;
  padding: 1.2rem;
  min-height: 0;
  position: relative;
}
.battle::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 10%;
  bottom: 10%;
  width: 2px;
  background: repeating-linear-gradient(to bottom, var(--tactical-line) 0 8px, transparent 8px 16px);
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 0;
}
.enemy-area {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
  z-index: 1;
}
.enemy-box {
  background: linear-gradient(180deg, rgba(26,35,48,0.9) 0%, rgba(16,22,30,0.9) 100%);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius);
  padding: 1rem;
  width: 100%;
  max-width: 400px;
  text-align: center;
  box-shadow: 0 8px 20px rgba(0,0,0,0.6);
}
.enemy-name {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--amber);
  letter-spacing: 0.05em;
  text-shadow: 0 0 8px var(--amber-glow);
}
.enemy-hp {
  font-size: 1rem;
  margin: 0.5rem 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}
.hp-bar {
  flex: 1;
  height: 8px;
  background: #2a3547;
  border-radius: 4px;
  overflow: hidden;
}
.hp-bar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--danger), var(--amber));
  transition: width 0.3s;
}
.enemy-statuses {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 0.3rem;
}
.status-chip {
  display: inline-block;
  background: var(--panel-dark);
  border: 1px solid var(--border-bright);
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  margin-right: 0.3rem;
  cursor: help;
  position: relative;
}
.status-chip:hover::after {
  content: attr(data-desc);
  position: absolute;
  bottom: calc(100% + 5px);
  left: 50%;
  transform: translateX(-50%);
  background: #0c0f14;
  color: var(--text);
  border: 1px solid var(--border-bright);
  border-radius: 4px;
  padding: 0.4rem 0.6rem;
  font-size: 0.75rem;
  white-space: nowrap;
  max-width: 250px;
  z-index: 50;
  pointer-events: none;
}
.intent {
  background: var(--panel-dark);
  border: 1px dashed var(--amber);
  padding: 0.6rem;
  border-radius: 6px;
  font-size: 0.9rem;
  color: var(--amber-light);
  margin-top: 0.5rem;
}
.player-area {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  z-index: 1;
}
.player-box {
  background: linear-gradient(180deg, rgba(26,35,48,0.9) 0%, rgba(16,22,30,0.9) 100%);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius);
  padding: 0.8rem;
  box-shadow: 0 8px 20px rgba(0,0,0,0.6);
}
.player-box .label {
  font-size: 0.8rem;
  color: var(--text-dim);
  letter-spacing: 0.03em;
}
.player-box .value {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--mint);
}
.stance-box {
  background: var(--panel);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius);
  padding: 0.8rem;
}
.stance-box button {
  margin-top: 0.4rem;
}
.battle-actions {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  align-items: center;
  z-index: 1;
}
.preview-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  white-space: pre-wrap;
  max-width: 320px;
}
.hand-area {
  grid-column: 1 / 4;
  grid-row: 3;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  padding: 0.5rem 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 0.5rem;
  z-index: 1;
  min-height: 260px;
}
.hand-card {
  flex: 0 0 auto;
  display: inline-flex;
  flex-direction: column;
  background: var(--panel-light);
  border: 2px solid var(--border-bright);
  border-radius: 8px;
  width: 170px;
  height: 245px;
  padding: 0.5rem;
  cursor: pointer;
  transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition);
  position: relative;
  overflow: hidden;
}
.hand-card:hover {
  transform: translateY(-6px);
  border-color: var(--mint-dark);
  box-shadow: 0 8px 20px rgba(0,0,0,0.6), 0 0 15px rgba(45,212,191,0.3);
}
.hand-card.selected {
  border-color: var(--amber);
  box-shadow: 0 0 15px var(--amber-glow);
  transform: translateY(-6px);
}
.card-art {
  height: 80px;
  background:
    linear-gradient(135deg, rgba(45,212,191,0.15) 0%, transparent 100%),
    repeating-linear-gradient(45deg, rgba(255,255,255,0.03) 0px, rgba(255,255,255,0.03) 2px, transparent 2px, transparent 8px);
  border-bottom: 1px solid var(--border-bright);
  border-radius: 4px 4px 0 0;
  margin: -0.5rem -0.5rem 0.4rem -0.5rem;
  padding: 0.2rem;
  position: relative;
}
.card-art::before {
  content: "";
  position: absolute;
  top: 10%;
  left: 10%;
  right: 10%;
  bottom: 10%;
  border: 1px dashed var(--tactical-line);
  border-radius: 4px;
}
.card-art::after {
  content: "◎";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--amber);
  font-size: 1.4rem;
  opacity: 0.7;
}
.hand-card .card-cost {
  position: absolute;
  top: 4px;
  left: 4px;
  background: var(--mint-dark);
  color: #0c0f14;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  z-index: 2;
}
.hand-card .card-name {
  font-size: 0.9rem;
  font-weight: 700;
  margin-top: 0.2rem;
  color: var(--mint);
  white-space: normal;
  line-height: 1.2;
}
.hand-card .card-type {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.hand-card .card-text {
  font-size: 0.72rem;
  white-space: normal;
  line-height: 1.35;
  flex: 1;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* Reward/Shop/Rest/Event/Intermission/Result */
.phase-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 2rem;
  background: radial-gradient(ellipse at center, rgba(45,212,191,0.04) 0%, transparent 70%);
}
.reward-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: center;
}
.reward-card, .shop-card, .event-choice, .rest-option {
  background: var(--panel);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius);
  padding: 1rem;
  cursor: pointer;
  transition: var(--transition);
  width: 200px;
  text-align: center;
}
.reward-card:hover, .shop-card:hover, .event-choice:hover, .rest-option:hover {
  border-color: var(--mint-dark);
  transform: translateY(-4px);
  box-shadow: 0 6px 15px var(--mint-glow);
}
.card-title {
  font-weight: 800;
  color: var(--mint);
  font-size: 1.2rem;
}
.card-cost {
  color: var(--amber);
  font-weight: 600;
}
.card-desc {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 0.5rem;
}
.deck-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 300px;
  overflow-y: auto;
  width: 100%;
  max-width: 420px;
}
.deck-item {
  background: var(--panel-light);
  padding: 0.6rem;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--border);
}
.upgrade-services{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px;width:min(100%,560px);margin:0 auto 14px}
.upgrade-service{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:10px;border:1px solid #718f8c;border-radius:7px;background:#1a3035;color:#e6f3e8;font-size:13px}
.upgrade-service span{color:#b7d2cb;font-size:11px}.upgrade-service .btn{white-space:nowrap}
@media(max-width:650px){.upgrade-services{grid-template-columns:1fr}.upgrade-service{font-size:12px;padding:8px}}

/* Library modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--panel);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius);
  padding: 1.2rem;
  width: 90%;
  max-width: 850px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 30px rgba(0,0,0,0.7);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.8rem;
}
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 0.8rem;
}
.filter-select {
  background: var(--panel-dark);
  border: 1px solid var(--border-bright);
  color: var(--text);
  padding: 0.4rem;
  border-radius: 4px;
}
.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.6rem;
}
.library-card {
  background: var(--panel-light);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem;
  font-size: 0.75rem;
}
.library-card .name {
  font-weight: 700;
  color: var(--mint);
}
.library-card .meta {
  color: var(--text-dim);
  font-size: 0.7rem;
}

/* Tooltip (generic) */
/* Tooltip handled globally by JS to avoid overflow clipping */

/* Notifications */
.notice {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--danger);
  color: white;
  padding: 0.8rem 1.2rem;
  border-radius: 8px;
  z-index: 200;
  animation: slideIn 0.25s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}
@keyframes slideIn {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Damage flash animations */
.flash-damage {
  animation: flashRed 0.6s;
}
@keyframes flashRed {
  0% { background-color: rgba(239,68,68,0.4); }
  100% { background-color: transparent; }
}
.flash-block {
  animation: flashBlue 0.6s;
}
@keyframes flashBlue {
  0% { background-color: rgba(45,212,191,0.4); }
  100% { background-color: transparent; }
}
.hit-flash {
  animation: hitPulse 0.3s;
}
@keyframes hitPulse {
  0% { filter: brightness(1.8); }
  100% { filter: brightness(1); }
}
.block-pulse {
  animation: blockPulse 0.4s;
}
@keyframes blockPulse {
  0% { box-shadow: 0 0 12px var(--mint); }
  100% { box-shadow: 0 0 0 transparent; }
}

/* Squad arrays */
.squad-ally, .squad-enemy { display: flex; gap: 0.25rem; justify-content: center; margin-top: 0.4rem; opacity: 0.75; pointer-events: none; }
.squad-member { width: 14px; height: 22px; background: linear-gradient(135deg, #2dd4bf33, #0c0f1480); border: 1px solid #2dd4bf88; border-radius: 2px 2px 0 0; clip-path: polygon(0 0, 100% 0, 100% 80%, 50% 100%, 0 80%); }
.squad-enemy .squad-member { background: linear-gradient(135deg, #f59e0b33, #0c0f1480); border-color: #f59e0b88; }
.squad-ally { justify-content: flex-start; }
.squad-enemy { justify-content: flex-end; }
/* Responsive */
@media (max-width: 900px) {
  .battle {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto auto;
  }
  .enemy-area { grid-column: 1; grid-row: 1; }
  .player-area { grid-column: 1; grid-row: 2; }
  .battle-actions { grid-column: 1; grid-row: 3; }
  .hand-area { grid-column: 1; grid-row: 4; }
  .app-header { flex-direction: column; gap: 0.5rem; }
  .home h1 { font-size: 2rem; }
  .hand-card { width: 150px; height: 220px; }
}
@media (max-width: 390px) {
  .hand-area {
    justify-content: flex-start;
    padding-left: 0.2rem;
  }
  .hand-card { width: 140px; height: 210px; }
  body { overflow-x: auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* Library Tabs and extra styles for modal content */
.library-tabs {
  display: flex;
  gap: 0.3rem;
  margin-bottom: 0.8rem;
  flex-wrap: wrap;
}
.library-tab {
  background: var(--panel-light);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.4rem 0.8rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: var(--transition);
}
.library-tab.active {
  background: var(--mint-dark);
  color: #0c0f14;
  border-color: var(--mint);
  font-weight: 700;
  box-shadow: 0 0 8px var(--mint-glow);
}
.library-meta {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 0.5rem;
  text-align: right;
}
.library-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 2rem;
  color: var(--text-dim);
  font-size: 1rem;
}
.upgrade-details {
  margin-top: 0.3rem;
  font-size: 0.7rem;
}
.upgrade-details summary {
  cursor: pointer;
  color: var(--amber);
  font-weight: 600;
}
.upgrade-details .upgrade-text {
  padding: 0.3rem 0;
  color: var(--text-dim);
  white-space: pre-wrap;
}
.status-card .meta {
  color: var(--danger);
}
.relic-card .card-text {
  color: var(--text);
  font-style: italic;
}
/* Mobile adjustments for modal */
@media (max-width: 390px) {
  .modal {
    width: 95%;
    max-height: 95vh;
    padding: 0.8rem;
  }
  .library-tabs {
    flex-direction: column;
    align-items: stretch;
  }
  .library-tab {
    width: 100%;
    text-align: center;
  }
  .filter-row {
    flex-direction: column;
  }
  .filter-select {
    width: 100%;
  }
  .library-grid {
    grid-template-columns: 1fr;
  }
  .library-card {
    padding: 0.8rem;
  }
}
