:root {
  --bg-ink: #151311;
  --bg-paper: #e8d9c3;
  --wood-1: #7d4f2f;
  --wood-2: #9f6d43;
  --wood-3: #4a2d1a;
  --gold: #d6b166;
  --gold-soft: rgba(214, 177, 102, 0.28);
  --text: #f7f2e9;
  --muted: rgba(247, 242, 233, 0.68);
  --glass: rgba(15, 14, 12, 0.5);
  --glass-border: rgba(247, 242, 233, 0.14);
  --danger: #ffb08e;
  --ok: #f5d89a;
  --neutral: #d5d9de;
  --ring: 0;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  background: radial-gradient(circle at 18% 8%, #3a3127 0%, #191612 42%, #0f0d0b 100%);
  color: var(--text);
  font-family: "Avenir Next", "Segoe UI", ui-sans-serif, system-ui, sans-serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.35;
  background-image:
    radial-gradient(circle at 30% 22%, rgba(255, 255, 255, 0.12), transparent 36%),
    radial-gradient(circle at 75% 68%, rgba(0, 0, 0, 0.36), transparent 42%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 30%, rgba(0, 0, 0, 0.2));
}

#app {
  position: fixed;
  inset: 0;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.glass {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  backdrop-filter: blur(8px) saturate(110%);
  -webkit-backdrop-filter: blur(8px) saturate(110%);
}

.topBar {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: min(460px, 94vw);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  pointer-events: auto;
}

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

.scoreBlock .label {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}

.scoreBlock .score {
  font-size: 28px;
  line-height: 1;
  font-weight: 800;
}

.centerBlock {
  text-align: center;
  min-width: 130px;
}

.centerBlock .title {
  font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
  letter-spacing: 0.22em;
  font-size: 11px;
  color: rgba(247, 242, 233, 0.62);
}

.centerBlock .subtitle {
  font-size: 12px;
  margin-top: 3px;
  color: var(--ok);
}

.chainWrap {
  margin: 7px auto 0;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  position: relative;
  display: grid;
  place-items: center;
}

.chainRing {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background:
    conic-gradient(from -90deg, rgba(214, 177, 102, 0.86) calc(var(--ring) * 1%), rgba(214, 177, 102, 0.08) 0);
  mask: radial-gradient(circle, transparent 58%, black 61%);
  -webkit-mask: radial-gradient(circle, transparent 58%, black 61%);
  filter: drop-shadow(0 0 8px rgba(214, 177, 102, 0.25));
}

.chainValue {
  font-weight: 800;
  font-size: 12px;
}

.leftDock,
.rightDock {
  position: absolute;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: auto;
}

.leftDock {
  left: 12px;
  top: 14px;
}

.rightDock {
  right: 12px;
  bottom: 12px;
  align-items: flex-end;
}

button,
select {
  font: inherit;
  color: var(--text);
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 8px 12px;
}

button {
  cursor: pointer;
}

button:hover,
select:hover {
  border-color: rgba(247, 242, 233, 0.28);
}

button.toggle.active {
  border-color: var(--gold);
  color: #ffefc9;
}

.seedLabel {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--muted);
}

.toast {
  position: absolute;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  top: 86px;
  min-width: 220px;
  max-width: 70vw;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--glass-border);
  background: rgba(12, 11, 9, 0.72);
  text-align: center;
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.good {
  color: var(--ok);
  border-color: rgba(245, 216, 154, 0.4);
}

.toast.bad {
  color: var(--danger);
  border-color: rgba(255, 176, 142, 0.4);
}

.toast.neutral {
  color: var(--neutral);
}

.debugInfo {
  position: absolute;
  bottom: 12px;
  left: 12px;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(10, 10, 10, 0.6);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 11px;
  color: #eaeaea;
  white-space: pre;
  pointer-events: none;
}

.hidden {
  display: none !important;
}

.screen,
.panel {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 30;
  pointer-events: auto;
  background: rgba(7, 6, 5, 0.58);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.screenCard,
.panelCard {
  width: min(560px, 92vw);
  border-radius: 18px;
  border: 1px solid rgba(247, 242, 233, 0.2);
  background: linear-gradient(180deg, rgba(38, 31, 24, 0.92), rgba(25, 20, 15, 0.92));
  box-shadow: 0 20px 44px rgba(0, 0, 0, 0.46);
  padding: 22px 20px;
}

.screenCard h1 {
  margin: 0;
  font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
  font-weight: 700;
  letter-spacing: 0.08em;
  font-size: clamp(34px, 5vw, 48px);
}

.screenCard h2,
.panelCard h2 {
  margin: 0;
  font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
  letter-spacing: 0.05em;
}

.screenCard .sub {
  margin: 8px 0 18px;
  color: var(--muted);
}

.menuActions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.menuRow {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 10px;
  margin-top: 10px;
  align-items: center;
}

.panelCard p {
  color: var(--muted);
  margin-top: 10px;
}

.panelCard ul {
  margin: 10px 0 16px;
  padding-left: 18px;
  color: #f0e8d8;
}

.panelCard li {
  margin: 6px 0;
}

#rulesDiagram {
  width: 100%;
  max-width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(247, 242, 233, 0.2);
  background: rgba(0, 0, 0, 0.18);
  margin-top: 8px;
}

.settingsGrid {
  margin: 14px 0 16px;
  display: grid;
  gap: 10px;
}

.settingsGrid label {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  color: var(--muted);
}

.endCard {
  text-align: center;
}

body.zen-clarity .toast {
  background: rgba(8, 8, 8, 0.85);
  border-color: rgba(247, 242, 233, 0.3);
}

body.zen-clarity .screenCard,
body.zen-clarity .panelCard {
  background: rgba(19, 15, 11, 0.96);
}

@media (max-width: 760px) {
  .leftDock {
    top: unset;
    bottom: 12px;
  }

  .rightDock {
    right: 8px;
    bottom: 124px;
  }

  .topBar {
    top: 8px;
  }

  .menuRow {
    grid-template-columns: 1fr;
    gap: 6px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
