:root {
  --ink: #f7f0e3;
  --ink-dim: rgba(247, 240, 227, 0.62);
  --panel: rgba(20, 18, 38, 0.5);
  --panel-edge: rgba(255, 231, 180, 0.16);
  --gold: #ffd98f;
  --tide: #8ff3e6;
  --glow: 0 0 0 1px rgba(255, 217, 143, 0.55), 0 0 18px rgba(255, 200, 120, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #14102a;
  color: var(--ink);
  font-family: 'Nunito', system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
  opacity: 0;
  transition: opacity 1.2s ease;
}
body.ready #scene { opacity: 1; }

.panel {
  position: fixed;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 18px;
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}

button {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 0;
  cursor: pointer;
}
button:disabled { opacity: 0.35; cursor: default; }

kbd {
  font-family: 'Nunito', sans-serif;
  font-size: 0.72em;
  font-weight: 800;
  padding: 0.05em 0.45em;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
}

/* ---------- brand ---------- */
.brand {
  position: fixed;
  top: 18px;
  left: 22px;
  pointer-events: none;
  text-shadow: 0 2px 18px rgba(20, 10, 40, 0.55);
}
.brand h1 {
  margin: 0;
  font-family: 'Cormorant Garamond', serif;
  font-weight: 600;
  font-size: 40px;
  letter-spacing: 0.04em;
  line-height: 1;
  background: linear-gradient(120deg, #fff3d6 10%, var(--gold) 45%, var(--tide) 95%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand p {
  margin: 4px 0 0 2px;
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 17px;
  color: var(--ink-dim);
}

/* ---------- tools ---------- */
#tools {
  top: 50%;
  left: 18px;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
}
#tools button {
  position: relative;
  width: 74px;
  padding: 5px 4px 4px;
  border-radius: 13px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: background 0.2s, box-shadow 0.2s, transform 0.15s;
}
#tools button:hover { background: rgba(255, 255, 255, 0.08); }
#tools button:active { transform: scale(0.95); }
#tools button.on { background: rgba(255, 217, 143, 0.14); box-shadow: var(--glow); }
#tools .ico { font-size: 22px; line-height: 1.1; filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3)); }
#tools .lbl { font-size: 11px; font-weight: 700; letter-spacing: 0.02em; }
#tools kbd {
  position: absolute;
  top: 4px;
  right: 5px;
  font-size: 9px;
  padding: 0 4px;
  opacity: 0.45;
}

/* dwelling kinds fly out beside the Dwellings button */
#dwellMenu {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px;
  z-index: 2;
  animation: fly-in 0.18s ease-out;
}
#dwellMenu[hidden] { display: none; }
#dwellMenu button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 8px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  text-align: left;
  transition: background 0.2s, box-shadow 0.2s;
}
#dwellMenu button:hover { background: rgba(255, 255, 255, 0.08); }
#dwellMenu button.on { background: rgba(255, 217, 143, 0.14); box-shadow: var(--glow); }
#dwellMenu .ico { font-size: 18px; width: 22px; text-align: center; }
@keyframes fly-in {
  from { opacity: 0; translate: -6px 0; }
  to { opacity: 1; translate: 0 0; }
}

/* ---------- top bar ---------- */
#top {
  top: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px;
}
#top button {
  min-width: 38px;
  height: 36px;
  padding: 0 10px;
  border-radius: 11px;
  font-size: 15px;
  font-weight: 700;
  transition: background 0.2s, box-shadow 0.2s;
}
#top button:hover:not(:disabled) { background: rgba(255, 255, 255, 0.09); }
#top .sep { width: 1px; height: 22px; margin: 0 5px; background: var(--panel-edge); }
.chips { display: flex; gap: 2px; align-items: center; }
.chips button.on { background: rgba(255, 217, 143, 0.16) !important; box-shadow: var(--glow); }

/* ---------- dock ---------- */
#dock {
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 10px 20px;
  white-space: nowrap;
}
.field {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 700;
  transition: opacity 0.3s;
}
.field > span { color: var(--ink-dim); text-transform: uppercase; letter-spacing: 0.08em; font-size: 11px; }
.field.dim { opacity: 0.35; }
.field[hidden] { display: none; }
.field output { min-width: 24px; font-variant-numeric: tabular-nums; color: var(--gold); }
.field.chips button {
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 700;
}
.field.chips button:hover { background: rgba(255, 255, 255, 0.08); }
.field.chips > span + button { margin-left: -4px; }
.field.chips button.swatch {
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  background: var(--c) !important;
  border: 2px solid rgba(255, 255, 255, 0.25);
}
.field.chips button.swatch.on { border-color: #fff; }

input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  width: 120px;
  height: 4px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--tide), var(--gold));
  outline: none;
}
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff8ea;
  box-shadow: 0 0 10px rgba(255, 217, 143, 0.8);
  cursor: pointer;
}
input[type='range']::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 0;
  border-radius: 50%;
  background: #fff8ea;
  box-shadow: 0 0 10px rgba(255, 217, 143, 0.8);
  cursor: pointer;
}

/* ---------- hint & toast ---------- */
#hint {
  position: fixed;
  bottom: 82px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  max-width: min(640px, calc(100vw - 220px));
  text-align: center;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--ink);
  text-shadow: 0 1px 12px rgba(10, 5, 30, 0.9), 0 0 2px rgba(10, 5, 30, 0.7);
  pointer-events: none;
}
#hint em { color: var(--gold); font-style: normal; }

#toast {
  position: fixed;
  top: 76px;
  left: 50%;
  transform: translate(-50%, -8px);
  padding: 9px 16px;
  border-radius: 12px;
  background: rgba(20, 18, 38, 0.75);
  border: 1px solid var(--panel-edge);
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#sizeTag {
  position: fixed;
  padding: 3px 9px;
  border-radius: 9px;
  background: rgba(20, 18, 38, 0.72);
  border: 1px solid var(--panel-edge);
  color: var(--gold);
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  transform: translate(14px, -130%);
}
#sizeTag[hidden] { display: none; }
#top button.off { opacity: 0.4; }

/* ---------- help ---------- */
#help {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(12, 8, 28, 0.45);
  backdrop-filter: blur(3px);
}
#help[hidden] { display: none; }
#help .card {
  max-width: 640px;
  padding: 28px 32px 26px;
  border-radius: 22px;
  background: linear-gradient(160deg, rgba(42, 34, 74, 0.92), rgba(22, 20, 44, 0.94));
  border: 1px solid var(--panel-edge);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
#help h2 {
  margin: 0 0 8px;
  font-family: 'Cormorant Garamond', serif;
  font-size: 34px;
  font-weight: 600;
  color: var(--gold);
}
#help .lede { margin: 0 0 18px; line-height: 1.55; color: var(--ink); }
#help .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 24px; }
#help ul { margin: 0; padding: 0; list-style: none; }
#help li { padding: 5px 0; font-size: 13.5px; color: var(--ink-dim); }
#help li b { color: var(--ink); }
#help .tip { margin: 16px 0 20px; font-size: 13.5px; color: var(--ink-dim); font-style: italic; }
#help .tip em { color: var(--tide); }
#help .go {
  display: block;
  margin-left: auto;
  padding: 10px 22px;
  border-radius: 12px;
  font-weight: 800;
  color: #2a1d10;
  background: linear-gradient(120deg, #ffe7b0, var(--gold));
  box-shadow: 0 0 24px rgba(255, 210, 130, 0.4);
}
#help .fine { margin: 14px 0 0; font-size: 12px; text-align: right; color: var(--ink-dim); }
#help .fine a { color: var(--ink-dim); }

/* ---------- small screens ---------- */
@media (max-width: 720px) {
  .brand p { display: none; }
  #tools {
    top: auto;
    bottom: 76px;
    left: 50%;
    transform: translateX(-50%);
    flex-direction: row;
    max-width: calc(100vw - 16px);
    overflow-x: auto;
    scrollbar-width: none;
  }
  #tools button { width: 58px; flex: none; }
  #dwellMenu { flex-direction: row; flex-wrap: wrap; max-width: calc(100vw - 16px); }
  #dwellMenu button { padding: 5px 8px; font-size: 12px; }
  #tools kbd { display: none; }
  .brand { top: 12px; left: 16px; }
  .brand h1 { font-size: 26px; }
  /* Full width under the title, so it wraps to two rows instead of covering it. */
  #top { top: 48px; left: 8px; right: 8px; flex-wrap: wrap; justify-content: center; padding: 4px; }
  #top button { min-width: 32px; height: 32px; padding: 0 7px; font-size: 14px; }
  #top .sep { margin: 0 2px; }
  #dock { bottom: 10px; gap: 12px; padding: 8px 12px; max-width: calc(100vw - 16px); overflow-x: auto; scrollbar-width: none; }
  input[type='range'] { width: 80px; }
  #hint { display: none; }
  #help .cols { grid-template-columns: 1fr; }
}
