:root {
  color-scheme: dark;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #070b14;
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  color: #f4ead8;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}

canvas:active {
  cursor: grabbing;
}

.hud {
  position: fixed;
  inset: 0 auto auto 0;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: max(8px, var(--safe-top)) calc(16px + var(--safe-right)) 8px calc(16px + var(--safe-left));
  pointer-events: none;
  text-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
}

.scenes {
  position: relative;
  width: max-content;
  pointer-events: auto;
}

.scene-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  min-width: 100%;
  padding: 8px;
  border-radius: 22px;
  border: 1px solid rgba(244, 234, 216, 0.16);
  background: rgba(10, 16, 28, 0.72);
  backdrop-filter: blur(12px);
  z-index: 5;
}

.scene-menu[hidden] {
  display: none;
}

.scene-btn {
  appearance: none;
  border: 1px solid rgba(244, 234, 216, 0.18);
  background: rgba(10, 16, 28, 0.55);
  color: inherit;
  font: inherit;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 7px 10px 7px 8px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  backdrop-filter: blur(10px);
  white-space: nowrap;
}

.scene-menu .scene-btn {
  width: 100%;
  justify-content: flex-start;
}

.scene-caret {
  margin-left: 4px;
  font-size: 9px;
  opacity: 0.7;
}

.scenes[data-open="true"] .scene-caret {
  transform: rotate(180deg);
}

.scene-btn:hover,
.scene-btn:focus-visible {
  border-color: rgba(244, 234, 216, 0.45);
  outline: none;
}

.scene-btn[aria-pressed="true"] {
  border-color: rgba(244, 234, 216, 0.8);
  background: rgba(20, 28, 44, 0.78);
}

.scene-swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  flex: none;
}

.scene-upload input {
  display: none;
}

body.theme-light {
  color: #1c1814;
}

body.theme-light .label {
  color: rgba(28, 24, 20, 0.62);
}

body.theme-light .hud {
  text-shadow: 0 6px 18px rgba(255, 255, 255, 0.45);
}

body.theme-light .scene-btn {
  color: #1c1814;
  background: rgba(255, 252, 248, 0.62);
  border-color: rgba(28, 24, 20, 0.14);
}

body.theme-light .scene-btn[aria-pressed="true"] {
  background: rgba(255, 252, 248, 0.9);
  border-color: rgba(28, 24, 20, 0.45);
}

body.theme-light .scene-menu {
  background: rgba(255, 252, 248, 0.78);
  border-color: rgba(28, 24, 20, 0.12);
}

.stats {
  display: flex;
  gap: 28px;
}

.stat {
  text-align: right;
}

.label {
  display: block;
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(244, 234, 216, 0.55);
}

.stat span:last-child {
  font-size: 28px;
  font-variant-numeric: tabular-nums;
}

.toast {
  position: fixed;
  left: 50%;
  top: calc(52px + var(--safe-top));
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 48px);
  padding: 6px 14px;
  border: 1px solid rgba(244, 234, 216, 0.08);
  background: rgba(10, 16, 28, 0.28);
  backdrop-filter: blur(8px);
  border-radius: 999px;
  color: rgba(244, 234, 216, 0.55);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-align: center;
  pointer-events: none;
  z-index: 6;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.55s ease, visibility 0.55s ease;
  text-shadow: none;
}

.toast.show {
  opacity: 1;
  visibility: visible;
}

body.theme-light .toast {
  color: rgba(28, 24, 20, 0.48);
  background: rgba(255, 252, 248, 0.32);
  border-color: rgba(28, 24, 20, 0.06);
}

@media (max-width: 720px) {
  .hud {
    padding: max(6px, var(--safe-top)) calc(12px + var(--safe-right)) 6px calc(12px + var(--safe-left));
  }

  .scene-btn {
    font-size: 10px;
    padding: 6px 8px 6px 6px;
  }

  .stat span:last-child {
    font-size: 22px;
  }

  .toast {
    top: calc(44px + var(--safe-top));
  }
}
