:root {
  --ink: #101510;
  --ink-soft: #1b211b;
  --ivory: #f1ead9;
  --ivory-dim: #c8c1b1;
  --brass: #c8a46a;
  --brass-bright: #e7c98f;
  --moss: #405444;
  --line: rgba(241, 234, 217, .17);
  --panel: rgba(15, 20, 16, .72);
  --panel-deep: rgba(11, 15, 12, .9);
  --shadow: 0 18px 55px rgba(0, 0, 0, .38);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", Georgia, serif;
  --sans: "Avenir Next", Avenir, "Helvetica Neue", "PingFang SC", "Noto Sans CJK SC", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: #0b0e0b; color: var(--ivory); }
body {
  overflow: hidden;
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  touch-action: none;
}
button { font: inherit; color: inherit; }

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; width: 100%; height: 100%; outline: none; cursor: grab; }
#stage canvas:active { cursor: grabbing; }
body.is-touring #stage canvas { cursor: crosshair; }

#vignette {
  pointer-events: none; position: fixed; inset: 0; z-index: 2;
  background:
    radial-gradient(ellipse at 50% 44%, transparent 42%, rgba(4, 7, 4, .16) 78%, rgba(3, 5, 3, .48) 112%),
    linear-gradient(180deg, rgba(3, 5, 3, .22), transparent 19%, transparent 76%, rgba(3, 5, 3, .36));
}
#grain {
  pointer-events: none; position: fixed; inset: -40%; z-index: 3; opacity: .055;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.92' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.7'/%3E%3C/svg%3E");
  animation: grain 1.4s steps(4) infinite;
}
@keyframes grain {
  0% { transform: translate3d(0, 0, 0); }
  25% { transform: translate3d(-2%, 3%, 0); }
  50% { transform: translate3d(3%, -2%, 0); }
  75% { transform: translate3d(-3%, -3%, 0); }
  100% { transform: translate3d(2%, 2%, 0); }
}

.topbar {
  position: fixed; z-index: 20; top: 0; left: 0; right: 0;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 24px;
  padding: 25px 30px 18px;
  pointer-events: none;
}
.brand { display: flex; align-items: center; gap: 14px; min-width: 300px; pointer-events: auto; }
.brand-mark {
  width: 46px; height: 46px; border: 1px solid var(--line); border-radius: 50%;
  display: grid; place-items: center; color: var(--brass-bright);
  background: rgba(10, 14, 10, .43); backdrop-filter: blur(9px);
  box-shadow: inset 0 0 0 1px rgba(200, 164, 106, .12);
}
.brand-mark svg { width: 28px; height: 28px; }
.brand-copy .eyebrow { margin: 0 0 3px; }
.brand h1 {
  margin: 0; font-family: var(--serif); font-weight: 500;
  font-size: clamp(19px, 1.7vw, 27px); letter-spacing: .03em; line-height: 1.1;
  text-shadow: 0 2px 22px rgba(0,0,0,.45);
}
.brand h1 span { color: rgba(241, 234, 217, .52); font-size: .61em; letter-spacing: .09em; font-style: italic; white-space: nowrap; }
.eyebrow {
  font-family: var(--sans); font-size: 9px; line-height: 1.4;
  letter-spacing: .27em; text-transform: uppercase; color: var(--brass);
}

.mode-tabs {
  pointer-events: auto; display: flex; align-items: center; gap: 4px;
  padding: 5px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel); backdrop-filter: blur(18px) saturate(1.18); box-shadow: var(--shadow);
}
.mode-btn {
  border: 0; border-radius: 999px; background: transparent; color: rgba(241, 234, 217, .6);
  padding: 10px 17px; font-size: 11px; letter-spacing: .11em; white-space: nowrap;
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  transition: color .25s, background .25s, box-shadow .25s;
}
.mode-btn span { font-family: var(--serif); font-size: 9px; opacity: .6; letter-spacing: .02em; }
.mode-btn:hover { color: var(--ivory); }
.mode-btn.is-active { background: var(--ivory); color: var(--ink); box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.mode-btn.is-active span { opacity: .48; }

.toolbar {
  pointer-events: auto; display: flex; align-items: center; gap: 2px;
  padding: 5px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel); backdrop-filter: blur(18px) saturate(1.18); box-shadow: var(--shadow);
}
.icon-btn {
  width: 34px; height: 34px; border: 0; border-radius: 50%; background: transparent;
  color: rgba(241,234,217,.7); display: grid; place-items: center; cursor: pointer;
  transition: background .2s, color .2s, transform .2s;
}
.icon-btn:hover { background: rgba(241, 234, 217, .1); color: var(--ivory); }
.icon-btn:active { transform: scale(.92); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn .play-icon, .icon-btn.is-paused .pause-icon { display: none; }
.icon-btn.is-paused .play-icon { display: block; }
.icon-btn[aria-pressed="false"] { color: rgba(241,234,217,.32); }
.icon-btn[aria-pressed="false"]::after { content: ""; position: absolute; }

.level-dock {
  position: fixed; z-index: 18; left: 30px; top: 50%; transform: translateY(-50%);
  width: 110px; padding: 15px 10px 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  backdrop-filter: blur(18px) saturate(1.15); box-shadow: var(--shadow);
  transition: opacity .35s, transform .35s;
}
.dock-title { margin: 0 6px 11px; font-family: var(--serif); font-size: 12px; letter-spacing: .12em; color: var(--ivory); display: flex; justify-content: space-between; align-items: baseline; }
.dock-title span { font-family: var(--sans); font-size: 7px; color: rgba(241,234,217,.4); letter-spacing: .18em; text-transform: uppercase; }
.level-list { display: grid; gap: 4px; }
.level-chip {
  position: relative; display: grid; grid-template-columns: 25px 1fr 8px; align-items: center; gap: 7px;
  border: 1px solid transparent; background: transparent; border-radius: 9px; padding: 8px 7px;
  text-align: left; cursor: pointer; color: rgba(241,234,217,.38); transition: background .2s, color .2s, border-color .2s;
}
.level-chip b { font-family: var(--serif); font-size: 15px; font-weight: 500; letter-spacing: .02em; }
.level-chip span { font-size: 9px; letter-spacing: .08em; }
.level-chip i { width: 5px; height: 5px; border-radius: 50%; background: rgba(241,234,217,.18); transition: background .2s, box-shadow .2s; }
.level-chip:hover { background: rgba(241,234,217,.055); color: rgba(241,234,217,.75); }
.level-chip.is-on { color: var(--ivory); border-color: rgba(241,234,217,.08); background: rgba(241,234,217,.05); }
.level-chip.is-on i { background: var(--brass-bright); box-shadow: 0 0 8px rgba(231,201,143,.6); }
.roof-chip { margin-top: 4px; border-top: 1px solid rgba(241,234,217,.09); border-radius: 0 0 9px 9px; padding-top: 10px; }
.dock-action {
  margin-top: 10px; width: 100%; border: 1px solid rgba(200,164,106,.22); background: transparent;
  color: rgba(231,201,143,.75); border-radius: 8px; padding: 8px 4px; font-size: 8px;
  letter-spacing: .1em; cursor: pointer; transition: background .2s, color .2s;
  display: flex; align-items: center; justify-content: center; gap: 5px;
}
.dock-action span { width: 3px; height: 3px; border-radius: 50%; background: currentColor; }
.dock-action:hover { background: rgba(200,164,106,.1); color: var(--brass-bright); }

.status-pill {
  position: fixed; z-index: 17; left: 30px; bottom: 28px; display: flex; align-items: center; gap: 9px;
  color: rgba(241,234,217,.65); font-size: 9px; letter-spacing: .15em; text-transform: uppercase;
  padding: 9px 13px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel); backdrop-filter: blur(14px); box-shadow: var(--shadow);
}
.status-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--brass-bright); box-shadow: 0 0 9px rgba(231,201,143,.7); }

.hint {
  position: fixed; z-index: 17; left: 50%; bottom: 28px; transform: translateX(-50%);
  font-size: 9px; letter-spacing: .1em; color: rgba(241,234,217,.55); white-space: nowrap;
  padding: 9px 15px; border: 1px solid rgba(241,234,217,.11); border-radius: 999px;
  background: rgba(10, 14, 10, .46); backdrop-filter: blur(10px);
  transition: opacity .3s;
}
.hint-key { color: rgba(231,201,143,.85); margin-right: 3px; }
.hint-sep { margin: 0 8px; opacity: .35; }

.scale-badge {
  position: fixed; z-index: 17; right: 30px; bottom: 28px; display: flex; align-items: center; gap: 12px;
  padding: 10px 14px 10px 11px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); backdrop-filter: blur(14px); box-shadow: var(--shadow);
  transition: opacity .3s, transform .3s;
}
.scale-badge.is-hidden { opacity: 0; transform: translateY(8px); pointer-events: none; }
.scale-line { height: 29px; display: flex; flex-direction: column; justify-content: space-between; align-items: center; width: 22px; border-left: 1px solid rgba(231,201,143,.55); }
.scale-line i { width: 9px; height: 1px; background: rgba(231,201,143,.55); display: block; }
.scale-line i:first-child { width: 15px; }
.scale-badge p { margin: 0; display: grid; gap: 3px; }
.scale-badge b { font-family: var(--serif); font-size: 13px; font-weight: 500; color: var(--brass-bright); letter-spacing: .04em; }
.scale-badge span { font-size: 8px; letter-spacing: .08em; color: rgba(241,234,217,.45); }

.tour-ui { position: fixed; inset: 0; z-index: 15; pointer-events: none; opacity: 0; visibility: hidden; transition: opacity .4s, visibility .4s; }
body.is-touring .tour-ui { opacity: 1; visibility: visible; }
body.is-touring .level-dock, body.is-touring .hint, body.is-touring .scale-badge, body.is-touring .status-pill { opacity: 0; pointer-events: none; }
body.is-touring .topbar { background: linear-gradient(180deg, rgba(8,11,8,.62), transparent); }
.crosshair {
  position: absolute; left: 50%; top: 50%; width: 4px; height: 4px; margin: -2px;
  border-radius: 50%; background: rgba(241,234,217,.72); box-shadow: 0 0 0 1px rgba(0,0,0,.28), 0 0 11px rgba(231,201,143,.5);
}
.tour-copy {
  position: absolute; left: 30px; bottom: 95px; padding: 16px 20px 15px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel-deep);
  backdrop-filter: blur(15px); box-shadow: var(--shadow); max-width: 430px;
}
.tour-copy .eyebrow { margin: 0 0 5px; }
.tour-copy h2 { margin: 0 0 11px; font-family: var(--serif); font-weight: 500; font-size: 25px; letter-spacing: .08em; }
.tour-copy .tour-help { margin: 0; font-size: 9px; letter-spacing: .08em; color: rgba(241,234,217,.5); }
.tour-copy .tour-help span { color: var(--brass-bright); margin: 0 3px 0 9px; }
.tour-copy .tour-help span:first-child { margin-left: 0; }
.tour-exit { position: absolute; right: 30px; bottom: 30px; display: flex; gap: 7px; pointer-events: auto; }
.tour-exit button {
  border: 1px solid var(--line); background: var(--panel); color: rgba(241,234,217,.78);
  border-radius: 999px; padding: 10px 16px; font-size: 9px; letter-spacing: .13em; cursor: pointer;
  backdrop-filter: blur(14px); transition: background .2s;
}
.tour-exit button:hover { background: rgba(241,234,217,.13); }
.tour-exit #btn-exit-tour { background: var(--ivory); color: var(--ink); border-color: var(--ivory); }
.tour-exit #btn-exit-tour:hover { background: var(--brass-bright); }
.touch-controls { display: none; position: absolute; inset: 0; pointer-events: none; }
.joystick {
  position: absolute; left: 28px; bottom: 30px; width: 104px; height: 104px; border-radius: 50%;
  border: 1px solid rgba(241,234,217,.25); background: rgba(12,18,12,.35);
  backdrop-filter: blur(6px); pointer-events: auto; touch-action: none;
}
.joystick::before { content: ""; position: absolute; inset: 21px; border: 1px solid rgba(241,234,217,.13); border-radius: 50%; }
.joystick span {
  position: absolute; width: 40px; height: 40px; left: 32px; top: 32px; border-radius: 50%;
  background: rgba(231,201,143,.3); border: 1px solid rgba(231,201,143,.55);
  box-shadow: 0 0 24px rgba(231,201,143,.16);
}
.touch-controls p { position: absolute; left: 28px; bottom: 9px; font-size: 8px; color: rgba(241,234,217,.36); letter-spacing: .08em; margin: 0; }

.loader {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  background: #0b0e0b; transition: opacity .8s ease, visibility .8s;
}
.loader.is-done { opacity: 0; visibility: hidden; }
.loader::after {
  content: ""; position: absolute; inset: 0; opacity: .05; pointer-events: none;
  background-image: radial-gradient(circle at 25% 30%, var(--brass) 0 1px, transparent 1px), radial-gradient(circle at 70% 70%, var(--brass) 0 1px, transparent 1px);
  background-size: 90px 90px, 110px 110px;
}
.loader-inner { display: grid; justify-items: center; text-align: center; width: min(340px, 80vw); }
.loader-plan { width: 150px; height: 112px; color: rgba(200,164,106,.72); margin-bottom: 25px; }
.loader-plan path { stroke-dasharray: 2 4; animation: draw 2.4s linear infinite; }
@keyframes draw { to { stroke-dashoffset: -60; } }
.loader .eyebrow { margin: 0 0 7px; }
.loader h2 { font-family: var(--serif); font-weight: 500; font-size: 24px; letter-spacing: .08em; margin: 0 0 24px; }
.loader-track { width: 100%; height: 1px; background: rgba(241,234,217,.13); overflow: hidden; }
.loader-track i { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, rgba(200,164,106,.4), var(--brass-bright)); transition: width .4s ease; box-shadow: 0 0 12px rgba(231,201,143,.6); }
.loader-note { margin: 13px 0 0; font-size: 8px; color: rgba(241,234,217,.35); letter-spacing: .14em; }

.help-modal {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  padding: 24px; background: rgba(5,8,5,.66); backdrop-filter: blur(9px);
  opacity: 0; visibility: hidden; transition: opacity .3s, visibility .3s;
}
.help-modal.is-open { opacity: 1; visibility: visible; }
.help-panel {
  position: relative; width: min(660px, 100%); max-height: 88vh; overflow: auto;
  padding: 38px 40px 31px; border: 1px solid rgba(241,234,217,.19); border-radius: 18px;
  background: linear-gradient(145deg, rgba(25,31,25,.98), rgba(13,18,14,.98));
  box-shadow: 0 34px 90px rgba(0,0,0,.55);
}
.help-panel .eyebrow { margin: 0 0 6px; }
.help-panel h2 { margin: 0 0 27px; font-family: var(--serif); font-weight: 500; font-size: 31px; letter-spacing: .06em; }
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px 34px; }
.help-grid h3 { font-family: var(--serif); font-size: 15px; font-weight: 500; letter-spacing: .08em; color: var(--brass-bright); margin: 0 0 8px; }
.help-grid p { font-size: 11px; line-height: 1.75; letter-spacing: .025em; color: rgba(241,234,217,.62); margin: 0; }
.help-foot { margin: 30px 0 0; padding-top: 18px; border-top: 1px solid var(--line); font-size: 9px; line-height: 1.7; letter-spacing: .06em; color: rgba(241,234,217,.35); }
.help-close {
  position: absolute; top: 16px; right: 19px; width: 32px; height: 32px; border: 1px solid var(--line);
  border-radius: 50%; background: transparent; color: var(--ivory-dim); font-size: 21px; line-height: 1; cursor: pointer;
}
.help-close:hover { background: rgba(241,234,217,.08); }

.toast {
  position: fixed; z-index: 70; left: 50%; top: 96px; transform: translate(-50%, -10px);
  padding: 10px 17px; border: 1px solid rgba(231,201,143,.26); border-radius: 999px;
  background: var(--panel-deep); color: rgba(241,234,217,.82); font-size: 10px; letter-spacing: .08em;
  opacity: 0; visibility: hidden; transition: opacity .25s, transform .25s, visibility .25s;
  backdrop-filter: blur(12px); box-shadow: var(--shadow); white-space: nowrap;
}
.toast.is-visible { opacity: 1; visibility: visible; transform: translate(-50%, 0); }

@media (max-width: 1120px) {
  .topbar { padding: 20px 20px 14px; gap: 12px; }
  .brand { min-width: 0; }
  .brand h1 span { display: none; }
  .mode-btn { padding: 10px 12px; font-size: 10px; }
  .level-dock { left: 20px; }
  .status-pill { left: 20px; bottom: 20px; }
  .hint { bottom: 20px; }
  .scale-badge { right: 20px; bottom: 20px; }
  .tour-copy { left: 20px; bottom: 86px; }
  .tour-exit { right: 20px; bottom: 20px; }
}

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; padding: 14px 14px 10px; gap: 10px; }
  .brand { width: calc(100% - 150px); gap: 10px; }
  .brand-mark { width: 38px; height: 38px; flex: 0 0 auto; }
  .brand-mark svg { width: 23px; height: 23px; }
  .brand .eyebrow { font-size: 7px; letter-spacing: .18em; }
  .brand h1 { font-size: 16px; white-space: nowrap; }
  .toolbar { position: absolute; top: 10px; right: 12px; }
  .toolbar .icon-btn { width: 31px; height: 31px; }
  .toolbar .icon-btn:nth-child(4) { display: none; }
  .mode-tabs { position: absolute; top: 57px; left: 14px; right: 14px; justify-content: center; }
  .mode-btn { flex: 1; justify-content: center; padding: 9px 6px; font-size: 9px; }
  .mode-btn span { display: none; }
  .level-dock {
    left: 12px; top: auto; bottom: 74px; transform: none; width: auto; padding: 7px;
    display: flex; align-items: center; gap: 5px; border-radius: 12px;
  }
  .dock-title, .dock-action { display: none; }
  .level-list { display: flex; gap: 3px; }
  .level-chip { grid-template-columns: 17px 1fr; gap: 3px; padding: 6px 8px; border-radius: 7px; }
  .level-chip b { font-size: 12px; }
  .level-chip span { font-size: 8px; }
  .level-chip i { display: none; }
  .roof-chip { margin-top: 0; border-top: 0; padding-top: 6px; }
  .status-pill { display: none; }
  .hint { display: none; }
  .scale-badge { right: 12px; bottom: 16px; padding: 7px 10px; }
  .scale-line { height: 23px; }
  .scale-badge span { display: none; }
  .scale-badge b { font-size: 11px; }
  .tour-copy { left: 12px; bottom: 154px; right: 12px; max-width: none; padding: 12px 14px; }
  .tour-copy h2 { font-size: 20px; margin-bottom: 8px; }
  .tour-copy .tour-help { font-size: 8px; line-height: 1.8; }
  .tour-exit { right: 12px; bottom: 14px; }
  .tour-exit button { padding: 9px 12px; font-size: 8px; }
  body.is-touring .touch-controls { display: block; }
  body.is-touring .tour-exit { bottom: 72px; }
  .help-panel { padding: 30px 22px 24px; }
  .help-grid { grid-template-columns: 1fr; gap: 20px; }
  .help-panel h2 { font-size: 25px; margin-bottom: 20px; }
  .toast { top: 110px; max-width: calc(100vw - 30px); white-space: normal; text-align: center; font-size: 9px; }
}

@media (prefers-reduced-motion: reduce) {
  #grain { animation: none; }
  * { scroll-behavior: auto !important; }
}
