:root {
  --bg: #0c0a0e;
  --surface: #16121a;
  --surface-light: #221e26;
  --gold: #c9a84c;
  --gold-bright: #e4c76b;
  --gold-dim: #8b7355;
  --ivory: #e8e4d9;
  --jet: #1a1a1a;
  --blood: #7a1e1e;
  --dream: #7ecce5;
  --muted: #5a5048;
  --font-display: 'Cinzel Decorative', serif;
  --font-body: 'Cinzel', serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: var(--font-body);
  color: var(--ivory);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

canvas {
  display: block;
  width: 100%; height: 100%;
}

#ui-layer {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  pointer-events: none;
  z-index: 10;
}

.screen {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  background: rgba(12, 10, 14, 0.92);
  backdrop-filter: blur(4px);
}

.screen.active { display: flex; }

.screen.overlay {
  background: rgba(12, 10, 14, 0.88);
}

.game-title {
  font-family: var(--font-display);
  font-size: clamp(2.5rem, 8vw, 5rem);
  color: var(--gold);
  text-align: center;
  letter-spacing: 0.15em;
  text-shadow: 0 0 40px rgba(201, 168, 76, 0.3), 0 2px 0 var(--bg);
  margin-bottom: 0.2em;
}

.subtitle {
  font-family: var(--font-body);
  font-size: clamp(1rem, 3vw, 1.5rem);
  color: var(--gold-dim);
  letter-spacing: 0.4em;
  text-transform: uppercase;
  margin-bottom: 2em;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.8em;
  align-items: center;
}

.ornate-btn {
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--gold);
  background: transparent;
  border: 1px solid var(--gold-dim);
  padding: 0.7em 2em;
  cursor: pointer;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  transition: all 0.3s ease;
  position: relative;
  min-width: 220px;
  text-align: center;
  pointer-events: auto;
}

.ornate-btn:hover {
  background: rgba(201, 168, 76, 0.08);
  border-color: var(--gold);
  color: var(--gold-bright);
  box-shadow: 0 0 20px rgba(201, 168, 76, 0.15);
}

.ornate-btn.small {
  min-width: 120px;
  font-size: 0.85rem;
  padding: 0.5em 1.2em;
}

.version {
  position: absolute; bottom: 1.5em;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.2em;
}

#hud {
  background: transparent;
  pointer-events: none;
  justify-content: flex-end;
  align-items: flex-start;
  padding: 1em;
  backdrop-filter: none;
}

#hud > * { pointer-events: auto; }

#event-log {
  position: absolute;
  bottom: 80px; left: 1em;
  max-width: 320px;
  max-height: 180px;
  overflow: hidden;
  font-size: 0.85rem;
  color: var(--ivory);
  opacity: 0.85;
  line-height: 1.5;
}

#event-log .event-item {
  margin-bottom: 0.3em;
  padding-left: 1em;
  border-left: 1px solid var(--gold-dim);
  animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 0.85; transform: translateX(0); }
}

#controls-bar {
  position: absolute;
  bottom: 1em; left: 1em;
  display: flex; gap: 0.5em;
}

.icon-btn {
  width: 44px; height: 44px;
  background: rgba(22, 18, 26, 0.9);
  border: 1px solid var(--gold-dim);
  color: var(--gold);
  font-family: var(--font-body);
  font-size: 0.9rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
  pointer-events: auto;
}

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

#algorithm-stability {
  position: absolute;
  top: 1em; right: 1em;
  text-align: right;
}

#algorithm-stability .label {
  font-size: 0.75rem;
  color: var(--gold-dim);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  display: block;
  margin-bottom: 0.3em;
}

.meter {
  width: 160px; height: 6px;
  background: var(--surface);
  border: 1px solid var(--gold-dim);
  position: relative;
}

#stability-fill {
  height: 100%;
  width: 50%;
  background: linear-gradient(90deg, var(--blood), var(--gold));
  transition: width 0.5s ease;
}

#sg-fs-btn {
  position: fixed; top: 8px; right: 8px;
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  padding: 0; border: 0; border-radius: 6px;
  background: rgba(0,0,0,.45); color: #fff; cursor: pointer; z-index: 9999;
}

#sg-fs-btn:hover { background: rgba(0,0,0,.7); }

h2 {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 5vw, 2.5rem);
  color: var(--gold);
  margin-bottom: 1em;
  letter-spacing: 0.1em;
}

#tutorial-content {
  max-width: 500px;
  text-align: center;
  line-height: 1.7;
  margin-bottom: 1.5em;
  color: var(--ivory);
  font-size: 0.95rem;
  padding: 0 1em;
}

#tutorial-content strong {
  color: var(--gold);
  display: block;
  margin-bottom: 0.5em;
  font-size: 1.1rem;
}

.tutorial-buttons {
  display: flex;
  gap: 1em;
}

#ending-desc {
  max-width: 450px;
  text-align: center;
  line-height: 1.7;
  margin-bottom: 1em;
  color: var(--ivory);
  font-size: 0.95rem;
  padding: 0 1em;
}

#ending-stats {
  margin-bottom: 1.5em;
  text-align: center;
  color: var(--gold-dim);
  font-size: 0.9rem;
  line-height: 1.6;
}

#stats-list {
  max-width: 400px;
  width: 100%;
  margin-bottom: 1.5em;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 0.5em 0;
  border-bottom: 1px solid var(--surface-light);
  font-size: 0.9rem;
}

.stat-row .stat-label { color: var(--muted); }
.stat-row .stat-value { color: var(--gold); }

.settings-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1em;
  margin-bottom: 1.5em;
}

.setting-row {
  display: flex;
  align-items: center;
  gap: 1em;
}

.setting-row label {
  color: var(--gold-dim);
  font-size: 0.9rem;
  min-width: 80px;
}

input[type="range"] {
  -webkit-appearance: none;
  width: 200px;
  height: 4px;
  background: var(--surface-light);
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  background: var(--gold);
  cursor: pointer;
  border-radius: 0;
}

/* Mobile adjustments */
@media (max-width: 600px) {
  .game-title { font-size: clamp(1.8rem, 10vw, 3rem); }
  .subtitle { font-size: 0.85rem; letter-spacing: 0.3em; }
  #event-log { max-width: 200px; font-size: 0.75rem; bottom: 70px; }
  .ornate-btn { min-width: 180px; font-size: 0.9rem; }
  .meter { width: 120px; }
}
