*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #0e0f14;
  --panel: #161822;
  --panel-alt: #1e2230;
  --border: #2e3447;
  --text: #ece6d8;
  --muted: #9e9a92;
  --gold: #d8b25a;
  --red: #c93b3b;
  --jade: #4ca87a;
  --font-ui: "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "Cascadia Code", "Consolas", ui-monospace, monospace;
}

html {
  scrollbar-gutter: stable;
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

body {
  background: radial-gradient(circle at 50% 10%, #1a1d2a 0%, var(--bg) 72%);
}

.app-shell {
  height: 100dvh;
  max-width: 1400px;
  margin: 0 auto;
  padding: 6px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.top-bar {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 5px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-seal {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: linear-gradient(135deg, #272b3b 0%, #141720 65%, #5c2020 100%);
  border: 1px solid var(--gold);
  color: var(--gold);
  font-weight: 800;
  font-size: 0.74rem;
  letter-spacing: 0.04em;
}

.brand-title {
  margin: 0;
  font-size: 0.94rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.version-badge {
  flex: 0 0 auto;
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(216, 178, 90, 0.14);
  border: 1px solid rgba(216, 178, 90, 0.45);
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  text-decoration: none;
}

a.version-badge:hover {
  background: rgba(216, 178, 90, 0.24);
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.top-btn,
.top-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 9px;
  border-radius: 6px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}

.top-btn:hover,
.top-link:hover {
  border-color: var(--gold);
  color: var(--gold);
}

.top-btn.is-active {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(216, 178, 90, 0.16);
}

.top-btn:focus-visible,
.top-link:focus-visible,
.version-badge:focus-visible,
.btn-primary:focus-visible,
.btn-secondary:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.top-btn.is-muted {
  color: var(--muted);
  border-color: rgba(201, 59, 59, 0.55);
}

.stage-wrap {
  flex: 1 1 auto;
  min-height: 0;
  container-type: size;
  display: flex;
  align-items: center;
  justify-content: center;
}

.canvas-frame {
  position: relative;
  width: min(100cqw, calc(100cqh * 16 / 9));
  height: min(100cqh, calc(100cqw * 9 / 16));
  background: #08090d;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.58);
}

.canvas-frame:fullscreen {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  border: none;
  border-radius: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #050608;
}

.canvas-frame:fullscreen #game-canvas {
  width: min(100vw, calc(100vh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(9, 10, 15, 0.8);
  backdrop-filter: blur(2px);
  z-index: 5;
}

.overlay-title-full {
  background: radial-gradient(ellipse at 50% 20%, #1e2538 0%, #111521 58%, #090b12 100%);
  backdrop-filter: none;
  padding: clamp(12px, 2.4vh, 28px) clamp(18px, 3.2vw, 40px);
}

.title-menu-wrap {
  width: min(860px, 100%);
  max-height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  gap: clamp(10px, 1.9vh, 18px);
  text-align: center;
}

.title-header {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.title-eyebrow-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-bottom: 6px;
}

.title-eyebrow-row .eyebrow {
  margin-bottom: 0;
}

.title-hero {
  margin: 0 0 8px;
  font-size: clamp(1.6rem, 3.1vw, 2.4rem);
  font-weight: 900;
  letter-spacing: 0.1em;
  color: var(--text);
}

.title-sub {
  margin: 0 auto;
  max-width: 66ch;
  color: #b2ada4;
  font-size: 0.9rem;
  line-height: 1.45;
}

.title-panel {
  width: 100%;
  padding: clamp(12px, 2vh, 20px);
  background: rgba(18, 21, 31, 0.90);
  border: 1px solid rgba(216, 178, 90, 0.36);
  border-radius: 12px;
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.title-panel .tenets-grid {
  margin-bottom: 0;
}

.title-meta-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 22px;
  padding-top: 10px;
  border-top: 1px solid rgba(216, 178, 90, 0.18);
  font-size: 0.76rem;
  color: #b2ada4;
}

.title-meta-item strong {
  color: var(--gold);
  font-weight: 700;
}

.title-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.btn-start-hero {
  padding: 11px 24px;
  font-size: 0.92rem;
}

.title-footer-hint {
  margin: 0;
  color: #a9a49c;
  font-size: 0.74rem;
}

.overlay-card {
  width: min(590px, 94%);
  max-height: 92%;
  overflow-y: auto;
  padding: 18px 22px;
  background: rgba(18, 20, 29, 0.96);
  border: 1px solid rgba(216, 178, 90, 0.45);
  border-radius: 10px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.65);
  text-align: center;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--gold);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.overlay-title {
  margin: 0 0 8px;
  font-size: clamp(1.35rem, 2.5vw, 1.9rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  color: var(--text);
}

.overlay-sub {
  margin: 0 auto 14px;
  max-width: 50ch;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.tenets-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
  text-align: left;
}

.tenet-box {
  padding: 9px 10px;
  border-radius: 7px;
  background: var(--panel);
  border: 1px solid var(--border);
}

.tenet-title {
  display: block;
  margin-bottom: 3px;
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.tenet-box p {
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.38;
}

.best-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(76, 168, 122, 0.12);
  border: 1px solid rgba(76, 168, 122, 0.42);
  color: #8ad3ac;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 700;
}

.save-pill {
  display: inline-block;
  padding: 3px 11px;
  border-radius: 999px;
  background: rgba(216, 178, 90, 0.13);
  border: 1px solid rgba(216, 178, 90, 0.45);
  color: #f0d38b;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
}

.summary-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0 14px;
  text-align: left;
}

.stat-cell {
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
}

.stat-label {
  display: block;
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-val {
  display: block;
  margin-top: 2px;
  font-family: var(--font-mono);
  font-size: 0.92rem;
  font-weight: 800;
  color: var(--text);
}

.end-cause {
  margin: 0 0 4px;
  color: #e67676;
  font-weight: 700;
  font-size: 0.88rem;
}

.victory-card {
  border-color: rgba(216, 178, 90, 0.78);
}

.victory-epitaph {
  margin: 0 0 4px;
  color: #9de0bb;
  font-weight: 700;
  font-size: 0.86rem;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.btn-primary,
.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: 7px;
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.btn-primary {
  background: var(--gold);
  border: 1px solid #f0d080;
  color: #12131a;
}

.btn-primary:hover {
  background: #e5c36d;
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-secondary:hover {
  border-color: var(--gold);
  color: var(--gold);
}

.controls-legend {
  flex: 0 0 auto;
  padding: 5px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 7px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.72rem;
  color: var(--muted);
}

.controls-legend.is-hidden {
  display: none;
}

.legend-items {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
}

.legend-sep {
  opacity: 0.4;
}

kbd {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 4px;
  background: #101219;
  border: 1px solid #394058;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1.3;
}

.btn-primary kbd {
  background: rgba(14, 15, 20, 0.16);
  border-color: rgba(14, 15, 20, 0.35);
  color: #12131a;
}

.btn-keys {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  letter-spacing: 0.01em;
}

.btn-keys kbd {
  padding: 1px 4px;
  font-size: 0.62rem;
}

.btn-keys .kbd-sep {
  opacity: 0.65;
  font-size: 0.66rem;
  font-weight: 700;
}

.btn-primary:has(.btn-keys) {
  gap: 5px;
  padding-inline: 11px;
}

.hidden {
  display: none !important;
}

body.hide-cursor,
body.hide-cursor *,
.canvas-frame.hide-cursor,
.canvas-frame.hide-cursor * {
  cursor: none !important;
}

@media (max-height: 690px) {
  .app-shell {
    padding: 4px 10px 6px;
    gap: 4px;
  }

  .top-bar {
    min-height: 34px;
    padding: 4px 10px;
  }

  .overlay-title-full {
    padding: 10px 18px;
  }

  .title-menu-wrap {
    gap: 9px;
  }

  .title-hero {
    margin-bottom: 4px;
    font-size: clamp(1.38rem, 2.5vw, 1.85rem);
  }

  .title-sub {
    font-size: 0.82rem;
    line-height: 1.38;
  }

  .title-panel {
    padding: 10px 12px;
    gap: 8px;
  }

  .title-meta-strip {
    padding-top: 7px;
    font-size: 0.72rem;
  }

  .btn-start-hero {
    padding: 8px 20px;
    font-size: 0.86rem;
  }

  .overlay-card {
    padding: 13px 16px;
  }

  .tenets-grid {
    gap: 6px;
    margin-bottom: 10px;
  }

  .tenet-box {
    padding: 7px 8px;
  }

  .controls-legend {
    padding: 3px 10px;
    font-size: 0.68rem;
  }
}

@media (max-width: 720px) {
  .tenets-grid {
    grid-template-columns: 1fr;
  }
}
