:root {
  --bg: #0e141c;
  --panel: #1a2433;
  --panel-2: #243247;
  --ink: #e8eef6;
  --muted: #9aabbe;
  --accent: #d4af58;
  --vesper: #3cb8a9;
  --vesper-deep: #1f6f68;
  --ashen: #e07040;
  --ashen-deep: #8a3a22;
  --danger: #e04545;
  --ok: #5dcf7a;
  --btn: #2c3d55;
  --btn-hover: #3a516f;
  --radius: 12px;
  --touch: 52px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

#app { height: 100%; width: 100%; position: relative; }

.screen {
  display: none;
  height: 100%;
  width: 100%;
}
.screen.active { display: flex; }

/* ---- Title (iPad / desktop) ---- */
#screen-title {
  align-items: center;
  justify-content: center;
  padding: 32px;
  background:
    radial-gradient(ellipse at 20% 20%, rgba(60, 184, 169, 0.18), transparent 50%),
    radial-gradient(ellipse at 80% 70%, rgba(224, 112, 64, 0.16), transparent 45%),
    linear-gradient(160deg, #0e141c, #162033 60%, #1a2433);
}

.title-card {
  width: min(920px, 100%);
  background: rgba(26, 36, 51, 0.92);
  border: 1px solid rgba(212, 175, 88, 0.35);
  border-radius: 20px;
  padding: 40px 48px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 13px;
  font-weight: 600;
}

h1 {
  margin: 0 0 12px;
  font-size: clamp(40px, 5vw, 56px);
  letter-spacing: 0.02em;
}

.tagline {
  margin: 0 0 28px;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.45;
  max-width: 36em;
}

.faction-pick {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.faction-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  min-height: 110px;
  padding: 18px 20px;
  border-radius: var(--radius);
  border: 2px solid transparent;
  background: var(--btn);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  font-size: 15px;
}
.faction-btn span:last-child { color: var(--muted); font-size: 14px; }
.faction-btn:hover { background: var(--btn-hover); }
.faction-btn.selected {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(212, 175, 88, 0.4);
}
.faction-btn.selected[data-faction="vesper"] { border-color: var(--vesper); }
.faction-btn.selected[data-faction="ashen"] { border-color: var(--ashen); }

.faction-swatch {
  width: 36px;
  height: 14px;
  border-radius: 999px;
}
.faction-swatch.vesper { background: linear-gradient(90deg, var(--vesper-deep), var(--vesper)); }
.faction-swatch.ashen { background: linear-gradient(90deg, var(--ashen-deep), var(--ashen)); }

.btn-primary {
  min-height: var(--touch);
  min-width: 220px;
  padding: 0 28px;
  border: none;
  border-radius: var(--radius);
  background: linear-gradient(180deg, #e0c06a, #b8902e);
  color: #1a1408;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}
.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn-primary:not(:disabled):hover { filter: brightness(1.06); }

.btn-ghost {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid rgba(154, 171, 190, 0.35);
  background: transparent;
  color: var(--ink);
  font-size: 15px;
  cursor: pointer;
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.06); }

.hint-line {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 14px;
}

/* ---- Game HUD ---- */
#screen-game {
  flex-direction: column;
  background: #0a0f16;
}

.top-hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  min-height: 64px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.hud-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.hud-faction {
  font-weight: 600;
  font-size: 16px;
}
.hud-faction.vesper { color: var(--vesper); }
.hud-faction.ashen { color: var(--ashen); }

.hud-resources {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 18px;
  border-radius: 999px;
  background: var(--panel-2);
  font-variant-numeric: tabular-nums;
}
.ore-icon { color: var(--accent); font-size: 14px; }
#hud-ore { font-size: 26px; font-weight: 700; }
.ore-label { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; }

.hud-status {
  justify-self: end;
  color: var(--muted);
  font-size: 14px;
  max-width: 42ch;
  text-align: right;
}

.stage-wrap {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 260px;
  min-height: 0;
  min-width: 0;
}

#game {
  width: 100%;
  height: 100%;
  display: block;
  background: #1c2a1c;
  cursor: crosshair;
  touch-action: none;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  background: var(--panel);
  border-left: 1px solid rgba(255, 255, 255, 0.06);
  overflow: auto;
}

#minimap {
  width: 100%;
  height: auto;
  border-radius: 8px;
  background: #101820;
  border: 1px solid rgba(255, 255, 255, 0.08);
  cursor: pointer;
}

.cmd-group { display: flex; flex-direction: column; gap: 8px; }
.cmd-label {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.cmd-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.cmd-row:has(.cmd-btn:nth-child(3):last-child) {
  grid-template-columns: 1fr 1fr;
}
.cmd-row .cmd-btn:nth-child(3):last-child {
  grid-column: 1 / -1;
}

.cmd-btn {
  min-height: var(--touch);
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--btn);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
}
.cmd-btn small {
  display: block;
  margin-top: 2px;
  font-weight: 500;
  color: var(--accent);
  font-size: 12px;
}
.cmd-btn:hover:not(:disabled) { background: var(--btn-hover); }
.cmd-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.cmd-btn.active {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.cmd-btn.build { border-color: rgba(60, 184, 169, 0.35); }
.cmd-btn.train { border-color: rgba(224, 112, 64, 0.35); }

.selection-info {
  margin-top: auto;
  padding: 12px;
  border-radius: 10px;
  background: var(--panel-2);
  font-size: 14px;
  line-height: 1.4;
  min-height: 72px;
}

.controls-cheat {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

/* Overlay */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 12, 18, 0.72);
  z-index: 20;
}
.overlay.hidden { display: none; }
.overlay-card {
  width: min(420px, 90%);
  padding: 32px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid rgba(212, 175, 88, 0.4);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}
.overlay-card h2 { margin: 0; font-size: 32px; }
.overlay-card p { margin: 0 0 8px; color: var(--muted); }

/* Phone-size is not a design target; show a clear notice instead of a broken UI */
@media (max-width: 900px) {
  #screen-title .title-card::after {
    content: "Chrono Clash is built for iPad / desktop (~1024px+). Rotate or use a larger screen.";
    display: block;
    margin-top: 16px;
    padding: 12px;
    border-radius: 8px;
    background: rgba(224, 69, 69, 0.15);
    color: #ffb4b4;
    font-size: 13px;
  }
  .faction-pick { grid-template-columns: 1fr; }
  .stage-wrap { grid-template-columns: 1fr; }
  .side-panel {
    max-height: 38vh;
    border-left: none;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
  }
  .top-hud {
    grid-template-columns: 1fr;
    justify-items: start;
  }
  .hud-status { justify-self: start; text-align: left; }
}
