:root {
  --ivory: #f4eee3;
  --ivory-dim: rgba(244, 238, 227, 0.66);
  --ink: #172024;
  --gold: #c7a565;
  --gold-bright: #ead19a;
  --glass: rgba(18, 23, 25, 0.58);
  --glass-deep: rgba(13, 17, 19, 0.82);
  --hairline: rgba(244, 238, 227, 0.18);
  --serif: "Bodoni 72", Didot, "Iowan Old Style", "Palatino Linotype", Palatino, "Times New Roman", serif;
  --sans: "Avenir Next", Avenir, "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: #b9d1df;
  color: var(--ivory);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body { font-family: var(--sans); }

button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible {
  outline: 1px solid var(--gold-bright);
  outline-offset: 3px;
}
svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.25; stroke-linecap: round; stroke-linejoin: round; }

#world {
  position: fixed;
  inset: 0;
  isolation: isolate;
  background: #b9d1df;
}
#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#scene:active { cursor: grabbing; }

.grade {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(ellipse 80% 68% at 53% 43%, transparent 45%, rgba(20, 31, 35, 0.12) 100%),
    linear-gradient(to bottom, rgba(18, 28, 31, 0.07), transparent 21%, transparent 72%, rgba(18, 24, 25, 0.2));
  mix-blend-mode: multiply;
}

.brand {
  position: absolute;
  z-index: 3;
  top: max(28px, env(safe-area-inset-top));
  left: max(34px, env(safe-area-inset-left));
  display: flex;
  align-items: stretch;
  gap: 13px;
  pointer-events: none;
  text-shadow: 0 1px 12px rgba(18, 29, 31, 0.34);
}
.brand-rule {
  width: 1px;
  background: linear-gradient(to bottom, transparent, rgba(244, 238, 227, 0.92) 20%, rgba(244, 238, 227, 0.34) 70%, transparent);
}
.brand-text { display: flex; flex-direction: column; gap: 4px; padding: 3px 0; }
.brand-city {
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 400;
  line-height: 0.9;
  letter-spacing: 0.055em;
  color: #f8f2e8;
}
.brand-mood {
  font-size: 8px;
  line-height: 1;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: rgba(251, 246, 236, 0.72);
}

.coords {
  position: absolute;
  z-index: 3;
  left: max(34px, env(safe-area-inset-left));
  bottom: max(29px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 8.5px;
  letter-spacing: 0.19em;
  color: rgba(248, 243, 233, 0.55);
  text-shadow: 0 1px 8px rgba(12, 21, 23, 0.55);
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.coords i {
  width: 16px;
  height: 1px;
  background: rgba(248, 243, 233, 0.3);
  display: block;
}
.coords sup { font-size: 6px; vertical-align: super; }

.preset-rail {
  position: absolute;
  z-index: 4;
  right: max(28px, env(safe-area-inset-right));
  top: 50%;
  transform: translateY(-53%);
  width: 43px;
  padding: 9px 5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border-radius: 24px;
  background: linear-gradient(120deg, rgba(19, 24, 25, 0.32), rgba(22, 28, 29, 0.16));
  border: 1px solid rgba(246, 240, 229, 0.14);
  box-shadow: 0 12px 38px rgba(14, 24, 26, 0.1), inset 0 1px rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(10px) saturate(0.9);
  -webkit-backdrop-filter: blur(10px) saturate(0.9);
  transition: opacity 0.6s ease, transform 0.8s cubic-bezier(0.16, 1, 0.3, 1), background 0.4s;
}
.preset-rail:hover { background: rgba(17, 23, 24, 0.54); }
.rail-btn {
  position: relative;
  width: 31px;
  height: 31px;
  padding: 8px;
  border-radius: 50%;
  color: rgba(249, 244, 234, 0.68);
  transition: color 0.35s ease, background 0.35s ease, transform 0.35s ease;
}
.rail-btn svg { stroke-width: 1.1; filter: drop-shadow(0 1px 3px rgba(8, 16, 19, 0.3)); }
.rail-btn::after {
  content: attr(data-label);
  position: absolute;
  right: calc(100% + 12px);
  top: 50%;
  transform: translate(4px, -50%);
  white-space: nowrap;
  padding: 6px 10px 5px;
  border-radius: 2px;
  background: rgba(15, 21, 22, 0.72);
  border: 1px solid rgba(244, 238, 227, 0.13);
  color: rgba(248, 243, 233, 0.9);
  font-family: var(--serif);
  font-size: 12px;
  letter-spacing: 0.035em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  backdrop-filter: blur(8px);
}
.rail-btn:hover { color: #fbf2df; background: rgba(245, 239, 227, 0.08); }
.rail-btn:hover::after { opacity: 1; transform: translate(0, -50%); }
.rail-btn.is-active { color: var(--gold-bright); background: rgba(220, 187, 125, 0.09); }
.rail-btn.is-active::before {
  content: "";
  position: absolute;
  inset: 2px;
  border: 1px solid rgba(230, 201, 142, 0.34);
  border-radius: 50%;
}
.rail-btn:active { transform: scale(0.92); }
.rail-sep {
  width: 17px;
  height: 1px;
  margin: 5px 0;
  background: rgba(244, 238, 227, 0.19);
}
.rail-reset { opacity: 0.72; }

.atelier-toggle {
  position: absolute;
  z-index: 5;
  right: max(28px, env(safe-area-inset-right));
  bottom: max(25px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 9px;
  height: 38px;
  padding: 0 14px 0 11px;
  border-radius: 20px;
  color: rgba(247, 241, 231, 0.72);
  background: rgba(17, 22, 23, 0.34);
  border: 1px solid rgba(246, 240, 229, 0.14);
  box-shadow: 0 10px 28px rgba(12, 20, 22, 0.12);
  backdrop-filter: blur(11px) saturate(0.9);
  -webkit-backdrop-filter: blur(11px) saturate(0.9);
  transition: color 0.3s, background 0.3s, border-color 0.3s;
}
.atelier-toggle:hover, .atelier-toggle[aria-expanded="true"] {
  color: #f7eddb;
  background: rgba(16, 22, 23, 0.6);
  border-color: rgba(231, 203, 146, 0.3);
}
.atelier-glyph { width: 17px; height: 17px; display: block; color: var(--gold-bright); opacity: 0.9; }
.atelier-text { font-family: var(--serif); font-size: 12.5px; letter-spacing: 0.09em; padding-top: 1px; }

.settings {
  position: absolute;
  z-index: 7;
  right: max(24px, env(safe-area-inset-right));
  bottom: max(74px, calc(env(safe-area-inset-bottom) + 74px));
  width: 356px;
  max-height: min(78vh, 760px);
  border-radius: 2px;
  background:
    linear-gradient(155deg, rgba(30, 37, 37, 0.92), rgba(15, 20, 21, 0.95));
  border: 1px solid rgba(246, 240, 229, 0.15);
  box-shadow: 0 30px 100px rgba(5, 12, 15, 0.38), inset 0 1px rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(24px) saturate(0.9);
  -webkit-backdrop-filter: blur(24px) saturate(0.9);
  overflow: hidden auto;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.985);
  transform-origin: bottom right;
  transition: opacity 0.35s ease, transform 0.5s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.35s;
  scrollbar-width: thin;
  scrollbar-color: rgba(244, 238, 227, 0.2) transparent;
}
.settings.is-open { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }
.settings::before {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px solid rgba(240, 230, 210, 0.07);
  pointer-events: none;
}
.settings-inner { position: relative; padding: 25px 25px 17px; }

.settings-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 26px;
}
.eyebrow {
  display: block;
  margin-bottom: 7px;
  font-size: 7.5px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: rgba(210, 181, 124, 0.8);
}
.settings h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 27px;
  line-height: 1;
  letter-spacing: 0.015em;
  color: #f4ecdd;
}
.settings-close {
  width: 27px;
  height: 27px;
  padding: 7px;
  margin-top: 1px;
  border-radius: 50%;
  color: rgba(245, 238, 226, 0.5);
  border: 1px solid rgba(244, 238, 227, 0.12);
  transition: color 0.25s, border-color 0.25s, transform 0.25s;
}
.settings-close:hover { color: var(--ivory); border-color: rgba(244, 238, 227, 0.35); transform: rotate(90deg); }

.setting-block { padding: 15px 0; border-top: 1px solid rgba(244, 238, 227, 0.1); }
.setting-block:first-of-type { border-top: 0; padding-top: 0; }
.setting-label {
  display: block;
  margin-bottom: 10px;
  font-size: 8px;
  font-weight: 500;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: rgba(244, 238, 227, 0.46);
}
.setting-label-row { display: flex; align-items: baseline; justify-content: space-between; }
.setting-label-row .setting-label { margin-bottom: 12px; }
.setting-value { color: rgba(210, 181, 124, 0.9); font-family: var(--serif); font-style: italic; font-size: 12px; }

.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: rgba(244, 238, 227, 0.12);
  border: 1px solid rgba(244, 238, 227, 0.12);
}
.preset-grid button {
  position: relative;
  padding: 10px 11px 9px;
  background: rgba(21, 27, 28, 0.94);
  color: rgba(244, 238, 227, 0.76);
  text-align: left;
  font-family: var(--serif);
  font-size: 12.5px;
  letter-spacing: 0.025em;
  transition: background 0.25s, color 0.25s;
}
.preset-grid button em {
  position: absolute;
  right: 10px;
  top: 11px;
  font-family: var(--sans);
  font-style: normal;
  font-size: 7px;
  letter-spacing: 0.08em;
  color: rgba(244, 238, 227, 0.28);
}
.preset-grid button:hover { background: rgba(45, 51, 50, 0.94); color: #fff8e9; }
.preset-grid button.is-active { color: var(--gold-bright); background: rgba(55, 53, 43, 0.7); }

.segmented {
  display: flex;
  gap: 3px;
  padding: 3px;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid rgba(244, 238, 227, 0.09);
}
.segmented button {
  flex: 1;
  padding: 8px 3px 7px;
  font-size: 9px;
  letter-spacing: 0.045em;
  color: rgba(244, 238, 227, 0.48);
  transition: color 0.25s, background 0.25s;
  border-radius: 1px;
}
.segmented button:hover { color: rgba(244, 238, 227, 0.85); }
.segmented button.is-active { color: #f8efdc; background: rgba(244, 238, 227, 0.1); }

.water-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 17px;
  background: transparent;
  cursor: pointer;
  margin: 0;
}
.water-range::-webkit-slider-runnable-track {
  height: 1px;
  background: linear-gradient(to right, rgba(230, 202, 145, 0.8) var(--fill, 50%), rgba(244, 238, 227, 0.2) var(--fill, 50%));
}
.water-range::-moz-range-track { height: 1px; background: rgba(244, 238, 227, 0.2); }
.water-range::-moz-range-progress { height: 1px; background: rgba(230, 202, 145, 0.8); }
.water-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 9px;
  height: 9px;
  margin-top: -4px;
  border-radius: 50%;
  background: var(--gold-bright);
  box-shadow: 0 0 0 3px rgba(230, 202, 145, 0.11), 0 2px 7px rgba(0, 0, 0, 0.36);
}
.water-range::-moz-range-thumb { width: 9px; height: 9px; border: 0; border-radius: 50%; background: var(--gold-bright); }
.range-legend {
  display: flex;
  justify-content: space-between;
  margin-top: 3px;
  font-size: 7.5px;
  letter-spacing: 0.08em;
  color: rgba(244, 238, 227, 0.3);
}

.detail-block { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.detail-block p {
  margin: 5px 0 0;
  font-family: var(--serif);
  font-size: 11.5px;
  font-style: italic;
  color: rgba(244, 238, 227, 0.36);
}
.switch {
  position: relative;
  flex: 0 0 auto;
  width: 36px;
  height: 20px;
  border-radius: 10px;
  border: 1px solid rgba(244, 238, 227, 0.23);
  background: rgba(0, 0, 0, 0.2);
  transition: background 0.25s, border-color 0.25s;
}
.switch span {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: rgba(244, 238, 227, 0.6);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), background 0.25s;
}
.switch[aria-checked="true"] { background: rgba(177, 137, 69, 0.24); border-color: rgba(224, 191, 127, 0.7); }
.switch[aria-checked="true"] span { transform: translateX(16px); background: var(--gold-bright); }

.settings-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  padding-top: 15px;
  border-top: 1px solid rgba(244, 238, 227, 0.1);
  font-size: 7.5px;
  letter-spacing: 0.08em;
  color: rgba(244, 238, 227, 0.29);
}
.settings-foot button {
  margin-left: auto;
  padding: 0;
  color: rgba(210, 181, 124, 0.7);
  font-size: 8px;
  letter-spacing: 0.08em;
}
.settings-foot button:hover { color: var(--gold-bright); }
kbd {
  padding: 1px 4px;
  border: 1px solid rgba(244, 238, 227, 0.22);
  border-radius: 2px;
  font-family: var(--sans);
  font-size: 7px;
}

.hint {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: max(29px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: none;
  color: rgba(249, 244, 235, 0.72);
  text-shadow: 0 1px 9px rgba(11, 20, 22, 0.58);
  opacity: 1;
  transition: opacity 1.2s ease, transform 1.2s ease;
}
.hint.is-gone { opacity: 0; transform: translate(-50%, 5px); }
.hint p {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 12px;
  letter-spacing: 0.035em;
  white-space: nowrap;
}
.hint-rule { width: 28px; height: 1px; background: rgba(248, 241, 231, 0.33); }

.fallback {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 7px;
  text-align: center;
  background: #182323;
}
.fallback[hidden] { display: none; }
.fallback p { margin: 0; font-family: var(--serif); font-size: 24px; }
.fallback span { font-size: 11px; color: var(--ivory-dim); letter-spacing: 0.06em; }

body.ui-hidden .brand,
body.ui-hidden .coords,
body.ui-hidden .preset-rail,
body.ui-hidden .atelier-toggle,
body.ui-hidden .settings,
body.ui-hidden .hint { opacity: 0 !important; pointer-events: none !important; }
body.ui-hidden .settings { visibility: hidden !important; }

body.panel-open .preset-rail { opacity: 0.25; pointer-events: none; }
body.panel-open .atelier-toggle { opacity: 0.4; pointer-events: none; }

@media (max-width: 720px) {
  .brand { top: 22px; left: 21px; gap: 10px; }
  .brand-city { font-size: 21px; }
  .brand-mood { font-size: 7px; }
  .coords { display: none; }
  .preset-rail {
    right: auto;
    left: 50%;
    top: auto;
    bottom: max(17px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    width: auto;
    flex-direction: row;
    padding: 5px 8px;
    border-radius: 23px;
  }
  .rail-sep { width: 1px; height: 17px; margin: 0 4px; }
  .rail-btn::after { display: none; }
  .atelier-toggle {
    right: 18px;
    top: 20px;
    bottom: auto;
    height: 35px;
    padding: 0 11px;
  }
  .atelier-text { display: none; }
  .settings {
    right: 12px;
    left: 12px;
    bottom: auto;
    top: 67px;
    width: auto;
    max-height: calc(100vh - 152px);
  }
  .hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
