:root {
  --fg: rgba(236, 244, 255, 0.94);
  --dim: rgba(236, 244, 255, 0.58);
  --faint: rgba(236, 244, 255, 0.3);
  --panel: rgba(10, 14, 24, 0.6);
  --panel-edge: rgba(255, 255, 255, 0.09);
  --line: rgba(255, 255, 255, 0.11);
  --hover: rgba(255, 255, 255, 0.07);
  --field: rgba(255, 255, 255, 0.05);
  --tip-bg: rgba(236, 244, 255, 0.94);
  --tip-fg: #0b1020;
  --accent: #a8f4ff;
  --danger: #ff9a85;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --font: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
}
body.light {
  --fg: rgba(34, 28, 22, 0.92);
  --dim: rgba(34, 28, 22, 0.58);
  --faint: rgba(34, 28, 22, 0.3);
  --panel: rgba(250, 246, 237, 0.74);
  --panel-edge: rgba(80, 60, 40, 0.14);
  --line: rgba(60, 45, 30, 0.13);
  --hover: rgba(60, 45, 30, 0.06);
  --field: rgba(60, 45, 30, 0.04);
  --tip-bg: rgba(34, 28, 22, 0.92);
  --tip-fg: #f6f1e6;
  --danger: #b0402a;
  --shadow: 0 12px 40px rgba(60, 45, 30, 0.18);
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #000;
  font: 12px/1.45 var(--font);
  color: var(--fg);
}
body.idle,
body.contemplate {
  cursor: none;
}
[hidden] {
  display: none !important;
}

#view,
#cursor {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
}
#view {
  transition: opacity 0.7s ease;
  touch-action: none;
}
#cursor {
  pointer-events: none;
  z-index: 1;
}
#view.fading,
#view.fading ~ #labels {
  opacity: 0;
}
body.contemplate #cursor {
  visibility: hidden;
}

/* ---------- controls ---------- */
button,
select,
input[type='number'] {
  font: inherit;
  color: inherit;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
button:hover,
select:hover {
  background: var(--hover);
}
button.on {
  border-color: var(--accent);
  color: var(--accent);
}
button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 2px;
}
select {
  border-radius: 9px;
  padding: 6px 10px;
}
select option,
select optgroup {
  color: #111;
  background: #fff;
}
input[type='number'] {
  border-radius: 8px;
  cursor: text;
}
input[type='text'] {
  min-width: 0;
  padding: 6px 10px;
  font: inherit;
  color: inherit;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 9px;
  transition: border-color 0.2s;
}
input[type='text']::placeholder {
  color: var(--faint);
}
input[type='text']:hover {
  border-color: var(--faint);
}
button:disabled {
  opacity: 0.5;
  cursor: default;
}
button.busy {
  cursor: progress;
}
#settings button.primary {
  border-color: var(--accent);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
#settings button.primary:hover {
  background: color-mix(in srgb, var(--accent) 20%, transparent);
}
button.quiet {
  background: transparent;
}
button.danger {
  border-color: var(--danger);
  color: var(--danger);
}
button.link {
  padding: 0;
  border: none;
  border-radius: 0;
  background: none;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

button.icon {
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 11px;
  background: transparent;
  color: var(--dim);
}
button.icon:hover {
  background: var(--hover);
  color: var(--fg);
}
button.icon.on {
  color: var(--accent);
  background: var(--hover);
}

input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  height: 18px;
  background: transparent;
  cursor: pointer;
  --p: 50%;
}
input[type='range']::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 3px;
  background: linear-gradient(to right, var(--accent) var(--p), var(--line) var(--p));
}
input[type='range']::-moz-range-track {
  height: 3px;
  border-radius: 3px;
  background: linear-gradient(to right, var(--accent) var(--p), var(--line) var(--p));
}
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  margin-top: -5px;
  border-radius: 50%;
  border: none;
  background: var(--fg);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}
input[type='range']::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: none;
  background: var(--fg);
}

input.switch {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  flex: none;
  width: 30px;
  height: 17px;
  margin: 0;
  border-radius: 999px;
  background: var(--line);
  cursor: pointer;
  transition: background 0.2s;
}
input.switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--fg);
  transition: transform 0.2s;
}
input.switch:checked {
  background: var(--accent);
}
input.switch:checked::after {
  transform: translateX(13px);
  background: #fff;
}

/* tooltips */
[data-tip] {
  position: relative;
}
[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  white-space: nowrap;
  padding: 4px 9px;
  border-radius: 7px;
  font-size: 11px;
  letter-spacing: 0.02em;
  background: var(--tip-bg);
  color: var(--tip-fg);
  pointer-events: none;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 18px;
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  box-shadow: var(--shadow);
  color: var(--fg);
}

/* ---------- intro ---------- */
#intro {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 16px;
  color: #eef6ff;
  text-align: center;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.72));
  backdrop-filter: blur(3px);
  transition: opacity 1.4s ease;
}
#intro.gone {
  opacity: 0;
  pointer-events: none;
}
#intro h1 {
  margin: 0 0 0.1em 0.45em;
  font-weight: 200;
  font-size: clamp(56px, 11vw, 132px);
  letter-spacing: 0.45em;
}
#intro .sub {
  margin: 0 0 2em;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  font-size: 11px;
  color: rgba(238, 246, 255, 0.6);
}
#intro p {
  font-size: 15px;
  line-height: 1.7;
  color: rgba(238, 246, 255, 0.78);
}
#intro .actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 2.2em 0 1.4em;
}
#intro button {
  font-size: 14px;
  padding: 10px 22px;
  background: transparent;
  border-color: rgba(255, 255, 255, 0.3);
}
#intro button.primary {
  background: rgba(168, 244, 255, 0.12);
  border-color: rgba(168, 244, 255, 0.6);
}
#intro .hint {
  font-size: 12px;
  color: rgba(238, 246, 255, 0.45);
}
#fatal {
  color: #ffb4a8;
}

/* ---------- dock ---------- */
#hud {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 5;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: max-content;
  max-width: calc(100vw - 32px);
  transition: opacity 0.8s ease, transform 0.8s ease;
}
/* with the drawer open, the dock centres itself in the remaining space */
body.settings-open #hud {
  left: calc((100vw - 416px) / 2);
  max-width: calc(100vw - 448px);
}
body.idle #hud,
body.hud-off #hud,
body.contemplate #hud,
body.intro #hud {
  opacity: 0;
  transform: translate(-50%, 10px);
  pointer-events: none;
}
#dock {
  padding: 6px 8px 8px;
  max-width: 100%;
  box-sizing: border-box;
}
#dock .caption {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 12px;
  padding: 3px 10px 5px;
  color: var(--dim);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mark {
  font-weight: 300;
  font-size: 12px;
  letter-spacing: 0.4em;
  color: var(--fg);
}
#dock .bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  row-gap: 4px;
}
#dock .group {
  display: flex;
  align-items: center;
  gap: 1px;
  padding: 0 6px;
}
#dock .group + .group {
  border-left: 1px solid var(--line);
}
.swatch {
  width: 22px;
  height: 22px;
  margin: 0 4px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: radial-gradient(circle at 32% 30%, var(--a) 0 16%, var(--b) 44%, var(--d) 72%, var(--c) 100%);
  transition: box-shadow 0.2s, transform 0.2s;
}
.swatch:hover {
  transform: scale(1.12);
  background: radial-gradient(circle at 32% 30%, var(--a) 0 16%, var(--b) 44%, var(--d) 72%, var(--c) 100%);
}
.swatch.on {
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.25), 0 0 0 3.5px var(--accent);
}

#toolopts {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 16px;
  padding: 7px 14px;
  border-radius: 14px;
  max-width: 100%;
  box-sizing: border-box;
}
#toolopts .field {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--dim);
}
#toolopts input[type='range'] {
  width: 120px;
}
#toolopts output {
  min-width: 18px;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}
#toolopts small {
  color: var(--dim);
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  position: relative;
  padding-left: 22px;
  background: transparent;
}
.chip::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 50%;
  width: 8px;
  height: 8px;
  margin-top: -4px;
  border-radius: 50%;
  background: var(--c);
}
.chip.faded {
  opacity: 0.45;
}
.chip.on {
  color: var(--fg);
  border-color: var(--c);
  background: var(--hover);
}

/* ---------- settings drawer ---------- */
#settings {
  position: fixed;
  top: 18px;
  right: 18px;
  bottom: 18px;
  z-index: 7;
  width: min(380px, calc(100vw - 36px));
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  transition: opacity 0.8s ease, transform 0.8s ease;
}
body.idle #settings:not(.pinned),
body.contemplate #settings {
  opacity: 0;
  transform: translateX(12px);
  pointer-events: none;
}
#settings > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 10px 2px 20px;
}
#settings h2 {
  margin: 0;
  font-weight: 300;
  font-size: 13px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
}
#settings header .actions {
  display: flex;
  gap: 2px;
  margin: 0;
}
#settings header [data-tip]:hover::after {
  top: calc(100% + 6px);
  bottom: auto;
  left: auto;
  right: 0;
  transform: none;
}
#tabs {
  display: flex;
  gap: 4px;
  padding: 4px 14px 0;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
#tabs button {
  flex: none;
  padding: 8px 6px 9px;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: none;
  color: var(--dim);
}
#tabs button:hover {
  color: var(--fg);
}
#tabs button.on {
  color: var(--fg);
  border-bottom-color: var(--accent);
}
#panes {
  flex: 1;
  overflow-y: auto;
  padding: 2px 20px 20px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
#panes h3 {
  margin: 20px 0 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--faint);
}
#settings .field {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 7px 0;
  color: var(--dim);
}
#settings .field > span:first-child {
  min-width: 84px;
}
#settings .field input[type='range'] {
  flex: 1;
  min-width: 0;
}
#settings output {
  min-width: 56px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
}
#settings .toggle {
  justify-content: space-between;
  cursor: pointer;
}
#settings .toggle > span:first-child {
  min-width: 0;
}
.seg {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.seg button {
  padding: 4px 11px;
  background: transparent;
}
.hint,
#settings small {
  display: block;
  color: var(--dim);
  line-height: 1.55;
}
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0;
}
.presets {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.preset {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 12px;
  border-radius: 12px;
  text-align: left;
}
.preset strong {
  font-weight: 500;
  overflow-wrap: anywhere;
}

/* account: names, saved things, space used */
.name-form {
  display: flex;
  gap: 6px;
  margin: 10px 0;
}
.name-form input {
  flex: 1;
}
.name-form button {
  flex: none;
}
.invite {
  margin-top: 12px;
}
.who {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.who > div {
  flex: 1;
  min-width: 0;
}
.who strong {
  display: block;
  font-weight: 500;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 500;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
}
.saved {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.saved .row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.saved .info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.saved .info strong {
  font-weight: 500;
  overflow-wrap: anywhere;
}
.saved .row input[type='text'] {
  width: 100%;
  box-sizing: border-box;
}
.saved .row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.saved .row-actions button {
  padding: 3px 10px;
}
.usage {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 0 10px;
}
.meter {
  height: 3px;
  border-radius: 3px;
  background: var(--line);
  overflow: hidden;
}
.meter i {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 0.4s ease;
}
.biomes {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.biome {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.biome .head {
  display: flex;
  align-items: center;
  gap: 8px;
}
.biome .head strong {
  flex: 1;
  font-weight: 500;
}
.biome .head code {
  font-size: 10px;
  color: var(--dim);
}
.biome .dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.biome select {
  width: 100%;
}
.editor {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.digits {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
}
.digits .k {
  width: 62px;
  color: var(--dim);
}
.digits button {
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 7px;
  background: transparent;
}
.digits button:disabled {
  opacity: 0.25;
  cursor: default;
}
.digits input {
  width: 56px;
  padding: 4px 8px;
}
.digits small {
  flex-basis: 100%;
  padding-left: 65px;
}
.journal {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--dim);
}
.journal time {
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}
dl.keys {
  display: grid;
  grid-template-columns: 124px 1fr;
  gap: 7px 14px;
  margin: 0;
  align-items: baseline;
}
dl.keys dd {
  margin: 0;
  color: var(--dim);
}
kbd {
  display: inline-block;
  padding: 1px 7px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  font: 11px var(--font);
  color: var(--fg);
  background: var(--field);
  white-space: nowrap;
}

/* ---------- region labels ---------- */
#labels {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  transition: opacity 0.7s ease;
}
.label {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  white-space: nowrap;
  text-align: center;
  transition: transform 0.35s ease-out;
}
.label span {
  font-size: 11px;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  color: rgba(236, 244, 255, 0.55);
  text-shadow: 0 0 12px rgba(0, 0, 0, 0.8);
}
.label small {
  font-size: 9px;
  letter-spacing: 0.15em;
  color: rgba(236, 244, 255, 0.35);
}
body[data-style='1'] .label span,
body[data-style='2'] .label span,
body[data-style='3'] .label span {
  font-family: var(--serif);
  font-style: italic;
  font-size: 15px;
  letter-spacing: 0.3em;
  text-shadow: 0 0 6px rgba(245, 238, 222, 0.9);
}
body[data-style='1'] .label span {
  color: rgba(150, 40, 25, 0.75);
}
body[data-style='2'] .label span,
body[data-style='3'] .label span {
  color: rgba(70, 45, 30, 0.8);
}
body[data-style='1'] .label small,
body[data-style='2'] .label small,
body[data-style='3'] .label small {
  font-family: var(--serif);
  color: rgba(70, 45, 30, 0.55);
  text-shadow: 0 0 6px rgba(245, 238, 222, 0.9);
}

/* ---------- toast ---------- */
#toast {
  position: fixed;
  top: 20px;
  left: 50%;
  z-index: 8;
  max-width: min(640px, calc(100vw - 32px));
  box-sizing: border-box;
  transform: translate(-50%, -12px);
  padding: 9px 18px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  color: var(--fg);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease, transform 0.5s ease;
}
#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 640px) {
  #hud,
  body.settings-open #hud {
    left: 50%;
    bottom: 12px;
    max-width: calc(100vw - 24px);
  }
  body.settings-open #hud {
    opacity: 0;
    pointer-events: none;
  }
  #settings {
    top: auto;
    left: 12px;
    right: 12px;
    bottom: 12px;
    width: auto;
    max-height: 72vh;
  }
  .presets {
    grid-template-columns: 1fr;
  }
}
