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

:root {
  --desk: #c8b49a;
  --desk-dark: #a89078;
  --paper: #faf6f0;
  --ink: #2c241c;
  --muted: #6b5e52;
  --panel: rgba(250, 246, 240, 0.92);
  --glass: rgba(255, 255, 255, 0.55);
  --border: rgba(44, 36, 28, 0.12);
  --accent: #b8734a;
  --accent-soft: rgba(184, 115, 74, 0.2);
  --shadow: 0 8px 32px rgba(44, 36, 28, 0.12);
  --radius: 14px;
  --font-display: "Source Serif 4", Georgia, serif;
  --font-body: "Source Sans 3", system-ui, sans-serif;
}

html {
  height: 100%;
}

body {
  font-family: var(--font-body);
  background: var(--desk);
  background-image:
    linear-gradient(175deg, rgba(255, 255, 255, 0.08) 0%, transparent 40%),
    repeating-linear-gradient(
      92deg,
      transparent,
      transparent 80px,
      rgba(44, 36, 28, 0.025) 80px,
      rgba(44, 36, 28, 0.025) 81px
    ),
    linear-gradient(180deg, #d4c0a8 0%, #b8a088 100%);
  color: var(--ink);
  min-height: 100vh;
  overflow: hidden;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

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

.hidden {
  display: none !important;
}

/* ── Picker ── */
.picker {
  flex: 1;
  overflow-y: auto;
  padding: clamp(1.5rem, 4vw, 3rem) clamp(1rem, 4vw, 2.5rem) 2rem;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
  animation: fadeUp 0.5s ease both;
}

.picker-header {
  text-align: center;
  margin-bottom: clamp(1.5rem, 4vw, 2.5rem);
}

.eyebrow {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.5rem;
}

.title {
  font-family: var(--font-display);
  font-size: clamp(2.2rem, 6vw, 3.4rem);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.08;
  margin-bottom: 0.5rem;
  color: var(--ink);
}

.subtitle {
  font-size: 1.02rem;
  color: var(--muted);
  max-width: 40ch;
  margin: 0 auto;
  line-height: 1.5;
}

.sim-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1.1rem;
}

.sim-card {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: calc(var(--radius) + 2px);
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  color: inherit;
  font: inherit;
  box-shadow: var(--shadow);
  transition: transform 0.22s ease, box-shadow 0.22s ease;
}

.sim-card:hover,
.sim-card:focus-visible {
  transform: translateY(-3px);
  box-shadow: 0 16px 40px rgba(44, 36, 28, 0.16);
  outline: 2px solid var(--accent-soft);
  outline-offset: 0;
}

.sim-card:active {
  transform: translateY(-1px);
}

.sim-preview {
  height: 148px;
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
}

.sim-preview--sand {
  background: linear-gradient(180deg, #14141c 0%, #0a0a10 100%);
}

.sim-preview--domino {
  background: linear-gradient(180deg, #c8b8a0 0%, #a89880 100%);
}

.sim-preview--chem {
  background: linear-gradient(180deg, #e8e4dc 0%, #d0ccc4 100%);
}

.sim-preview--maze {
  background: linear-gradient(180deg, #2a3c50 0%, #1a2838 100%);
}

.sim-preview--spark {
  background: #000;
}

.sim-preview--hex {
  background: linear-gradient(180deg, #12091f 0%, #08040e 100%);
}

.sim-preview--cube {
  background: linear-gradient(180deg, #e0dcd6 0%, #c8c4be 100%);
}

.preview-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.sim-info {
  padding: 1rem 1.15rem 1.25rem;
}

.sim-icon {
  font-size: 1.25rem;
  display: block;
  margin-bottom: 0.3rem;
  opacity: 0.85;
}

.sim-info h2 {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
}

.sim-info p {
  font-size: 0.84rem;
  color: var(--muted);
  line-height: 1.5;
}

/* ── Stage ── */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  animation: fadeIn 0.3s ease both;
}

.hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-shrink: 0;
}

.hud-center {
  text-align: center;
  min-width: 0;
}

.sim-title {
  display: block;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 600;
}

.sim-hint {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.hud-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--glass);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.85);
  border-color: rgba(44, 36, 28, 0.2);
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.tool-palette {
  display: flex;
  gap: 0.5rem;
  padding: 0.55rem 1rem;
  border-bottom: 1px solid var(--border);
  background: rgba(250, 246, 240, 0.75);
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.tool-palette::-webkit-scrollbar {
  display: none;
}

.tool-swatch {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid rgba(44, 36, 28, 0.15);
  cursor: pointer;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.12);
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.tool-swatch:hover {
  transform: scale(1.1);
}

.tool-swatch.is-active {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--accent);
  transform: scale(1.06);
}

.tool-swatch:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.canvas-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  background: #b8a890;
  padding: clamp(8px, 2vw, 16px);
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
  border-radius: 8px;
  box-shadow:
    inset 0 0 0 1px rgba(44, 36, 28, 0.08),
    0 4px 24px rgba(44, 36, 28, 0.15);
}

#canvas[data-cursor="pointer"] {
  cursor: pointer;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (max-width: 600px) {
  .hud {
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
  }

  .hud-center {
    grid-column: 1 / -1;
    order: -1;
  }

  .hud-actions {
    grid-column: 2;
  }
}

@media (prefers-reduced-motion: reduce) {
  .picker,
  .stage,
  .sim-card {
    animation: none;
    transition: none;
  }
}
