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

:root {
  --ink: #f3e6cf;
  --ink-dim: #b9a888;
  --panel: rgba(22, 16, 12, 0.82);
  --panel-solid: #1a1410;
  --line: rgba(232, 196, 140, 0.18);
  --gold: #e0b15a;
  --gold-deep: #c48a32;
  --night: #7ea0d4;
  --quake: #e24a32;
  --shadow: 0 10px 32px rgba(0, 0, 0, 0.38);
  --sans: "Iowan Old Style", "Palatino Linotype", Palatino, "Times New Roman", serif;
  --ui: "Avenir Next", "Segoe UI", Helvetica, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --ink: #2a2118;
    --ink-dim: #6d5c45;
    --panel: rgba(248, 238, 220, 0.88);
    --panel-solid: #f6edd8;
    --line: rgba(80, 56, 24, 0.14);
    --gold: #9a6b18;
    --gold-deep: #7a5210;
    --night: #35568a;
    --shadow: 0 10px 28px rgba(60, 40, 16, 0.16);
  }
}

html,
body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: #1c140e;
  color: var(--ink);
  font-family: var(--ui);
}

#canvas-container {
  position: fixed;
  inset: 0;
  z-index: 1;
  touch-action: none;
  cursor: grab;
}

#canvas-container.is-dragging {
  cursor: grabbing;
}

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

#stats-panel,
#fps-counter,
#controls-legend,
#sidebar {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

#stats-panel {
  position: fixed;
  top: 18px;
  left: 18px;
  z-index: 20;
  min-width: 188px;
  padding: 14px 16px 12px;
  border-radius: 14px;
}

.stat-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 18px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
}

.stat-item:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.stat-label {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.stat-value {
  font-family: var(--sans);
  font-size: 17px;
  font-weight: 600;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

#fps-counter {
  position: fixed;
  top: 18px;
  right: 336px;
  z-index: 20;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 12px;
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
  color: var(--ink-dim);
}

#fps-value {
  color: var(--gold);
  font-weight: 700;
}

#controls-legend {
  position: fixed;
  right: 336px;
  bottom: 18px;
  z-index: 20;
  max-width: min(520px, calc(100vw - 360px));
  padding: 9px 12px;
  border-radius: 999px;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-dim);
  line-height: 1.4;
}

#earthquake-badge {
  position: fixed;
  top: 50%;
  left: calc(50% - 150px);
  transform: translate(-50%, -50%);
  z-index: 40;
  padding: 14px 36px;
  border-radius: 6px;
  background: var(--quake);
  color: #fff8ee;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.28em;
  pointer-events: none;
  box-shadow: 0 12px 40px rgba(180, 30, 10, 0.4);
}

#earthquake-badge.hidden {
  display: none;
}

#sidebar {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 30;
  width: 300px;
  height: 100%;
  padding: 28px 22px 24px;
  overflow-y: auto;
  background: var(--panel);
  border-left: 1px solid var(--line);
  border-radius: 0;
}

#sidebar h1 {
  font-family: var(--sans);
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--gold);
  line-height: 1;
}

.subtitle {
  margin: 8px 0 26px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.control-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 244, 220, 0.04);
  color: var(--ink);
  font: 600 14px/1.2 var(--ui);
  text-align: left;
  cursor: pointer;
}

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

.control-btn:focus-visible,
*:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.control-btn.primary {
  background: linear-gradient(160deg, var(--gold) 0%, var(--gold-deep) 100%);
  border-color: transparent;
  color: #2a1c0c;
}

.control-btn.active {
  background: #24344c;
  border-color: var(--night);
  color: #e8eef8;
}

.btn-icon {
  width: 22px;
  text-align: center;
  font-size: 16px;
}

.mode-line {
  margin: 16px 0 0;
  font-size: 12px;
  color: var(--ink-dim);
}

.info-section {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.info-section h2 {
  margin-bottom: 8px;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-dim);
  font-weight: 600;
}

.info-section p {
  font-size: 13px;
  line-height: 1.55;
  color: var(--ink-dim);
}

@media (prefers-reduced-motion: reduce) {
  #earthquake-badge {
    animation: none;
  }

  .control-btn {
    transition: none;
  }
}

@media (prefers-reduced-motion: no-preference) {
  #earthquake-badge {
    animation: quake-pulse 0.12s linear infinite alternate;
  }
}

@keyframes quake-pulse {
  from { transform: translate(-50%, -50%) scale(1); }
  to { transform: translate(-50%, -50%) scale(1.04) rotate(-0.6deg); }
}

@media (max-width: 820px) {
  #fps-counter,
  #controls-legend {
    right: 16px;
  }

  #controls-legend {
    bottom: 168px;
    max-width: calc(100vw - 32px);
  }

  #earthquake-badge {
    left: 50%;
  }

  #sidebar {
    top: auto;
    bottom: 0;
    width: 100%;
    height: auto;
    max-height: 42vh;
    padding: 16px 16px 18px;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  #sidebar h1 {
    font-size: 22px;
  }

  .subtitle {
    margin-bottom: 12px;
  }

  .controls {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .control-btn {
    flex: 1 1 44%;
    min-width: 140px;
  }

  .info-section {
    display: none;
  }
}
