:root {
  /* Global theme tokens define the app's paper-like daytime palette. */
  --bg: #F4F3EE;
  --ink: #17140F;
  --accent: #5AC8FA;
  --panel-bg: #F4F3EEF2;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    /* The default dark palette mirrors the light theme rather than inventing a separate look. */
    --bg: #15130F;
    --ink: #EFEAE0;
    --panel-bg: #15130FF2;
  }
}

:root[data-theme="dark"] {
  /* Explicit dark-theme override for browsers or scripts that set it directly. */
  --bg: #15130F;
  --ink: #EFEAE0;
  --panel-bg: #15130FF2;
}

html,
body {
  /* The app is a single-screen composition, so the document itself never scrolls. */
  height: 100%;
  margin: 0;
  background: var(--bg);
  overflow: hidden;
  font-family: 'Cormorant', Georgia, 'Times New Roman', serif;
}

body.hide-cursor,
body.hide-cursor * {
  cursor: none;
}

#canvas-holder {
  /* The canvas is anchored full-viewport so the generated scene owns the page. */
  position: fixed;
  inset: 0;
}

#canvas-holder canvas {
  display: block;
}

#footer-text-controls {
  /* Footer controls are intentionally subtle and detached from the main panel. */
  position: fixed;
  left: 16px;
  bottom: 16px;
  display: inline-flex;
  align-items: center;
  flex-direction: row;
  gap: 0;
  z-index: 2;
  font-family: 'Inter', -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 11px;
  letter-spacing: 0.02em;
  text-transform: lowercase;
  color: var(--ink);
  white-space: nowrap;
}

#settings-toggle-btn,
#credits-toggle-btn {
  border: none;
  background: transparent;
  color: var(--ink);
  opacity: 0.45;
  cursor: pointer;
  padding: 0;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
}

.footer-divider {
  display: inline-block;
  margin: 0 8px;
  color: var(--ink);
  opacity: 0.6;
  line-height: 1;
}

#settings-toggle-btn:hover,
#credits-toggle-btn:hover {
  opacity: 0.75;
}

#settings-toggle-btn:focus-visible,
#credits-toggle-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

#credits-overlay {
  /* The overlay is a simple modal layer that dims the scene without disturbing layout. */
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, #000000 50%, transparent);
  padding: 24px;
  box-sizing: border-box;
}

#credits-overlay[hidden] {
  display: none;
}

#credits-dialog {
  width: min(520px, 100%);
  padding: 20px 22px;
  border: 1px solid color-mix(in srgb, var(--ink) 28%, transparent);
  background: color-mix(in srgb, var(--bg) 95%, #000000 5%);
  color: var(--ink);
  font-family: 'Inter', -apple-system, "Helvetica Neue", Arial, sans-serif;
  box-sizing: border-box;
}

#credits-dialog h2 {
  margin: 0 0 12px 0;
  font-size: 12px;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  font-weight: 600;
}

#credits-dialog p {
  margin: 0 0 8px 0;
  font-size: 14px;
  letter-spacing: 0.01em;
  line-height: 1.45;
}

#credits-dialog p:last-child {
  margin-bottom: 0;
}

#credits-dialog a {
  color: inherit;
}

#credits-dialog a:hover {
  opacity: 0.75;
}

#fullscreen-toggle-btn {
  /* Fullscreen stays visually secondary to avoid competing with the generated content. */
  position: fixed;
  bottom: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  color: var(--ink);
  opacity: 0.72;
  z-index: 11;
  cursor: pointer;
  padding: 0;
}

#fullscreen-toggle-btn:hover {
  opacity: 0.95;
}

body.is-fullscreen #fullscreen-toggle-btn {
  opacity: 0.15;
}

body.is-fullscreen #settings-toggle-btn,
body.is-fullscreen #credits-toggle-btn {
  opacity: 0.15;
}

#fullscreen-toggle-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#fullscreen-toggle-btn .material-symbols-rounded {
  font-size: 21px;
  line-height: 1;
  font-family: 'Material Symbols Rounded';
}

@supports (padding: max(0px)) {
  /* Safe-area adjustments keep controls usable on notched and gesture-based devices. */
  #footer-text-controls {
    left: max(16px, env(safe-area-inset-left, 0px));
    bottom: max(16px, env(safe-area-inset-bottom, 0px));
  }

  #fullscreen-toggle-btn {
    right: max(16px, env(safe-area-inset-right, 0px));
    bottom: max(16px, env(safe-area-inset-bottom, 0px));
  }
}

@media (max-width: 768px) {
  #footer-text-controls {
    font-size: 13px;
    letter-spacing: 0.03em;
  }

  .footer-divider {
    margin: 0 10px;
  }

  #fullscreen-toggle-btn {
    width: 46px;
    height: 46px;
  }

  #fullscreen-toggle-btn .material-symbols-rounded {
    font-size: 24px;
  }

  #credits-dialog {
    padding: 18px;
  }

  #credits-dialog h2 {
    font-size: 13px;
  }

  #credits-dialog p {
    font-size: 16px;
    line-height: 1.55;
  }
}
