/* buildle — presentation layer. Frosted glass floating over a golden-hour sky. */

/* ── Design tokens ─────────────────────────────────────────────────────── */
:root {
  --dusk-plum: #3D2C5A;
  --warm-rose: #C96F8E;
  --peach-gold: #F2B077;
  --cloud-white: #F7F1E8;
  --honey: #EBB44E;
  --terracotta: #D98E73;
  --brick-red: #B5483E;
  --ink: #2B2D3A;
  --glow: #FFE8A8;

  --glass-fill: rgba(255, 255, 255, 0.12);
  --glass-fill-strong: rgba(255, 255, 255, 0.2);
  --glass-border: rgba(255, 255, 255, 0.2);
  --card-fill: rgba(43, 29, 58, 0.62);
  --overlay-scrim: rgba(24, 14, 38, 0.45);
  --shadow-deep: 0 24px 64px rgba(18, 8, 30, 0.45);

  --radius-s: 8px;
  --radius-pill: 999px;
  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 32px;

  --font-display: 'Fredoka', system-ui, sans-serif;
  --font-ui: 'Nunito', system-ui, sans-serif;
}

/* ── Base ──────────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--dusk-plum);
  color: var(--cloud-white);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}

input,
textarea {
  user-select: text;
  -webkit-user-select: text;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--cloud-white);
  outline-offset: 2px;
}

/* ── Stage ─────────────────────────────────────────────────────────────── */
#app {
  position: fixed;
  inset: 0;
  z-index: 0;
}

#app canvas {
  display: block;
  touch-action: none;
}

#vignette {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: radial-gradient(
    ellipse 130% 100% at 50% 45%,
    transparent 55%,
    rgba(26, 13, 40, 0.18) 78%,
    rgba(20, 9, 34, 0.45) 100%
  );
}

/* Sky-colored cover; main.js fades it out over 600ms once the first frame renders. */
#fade {
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
  background: linear-gradient(to bottom, var(--dusk-plum) 0%, var(--warm-rose) 55%, var(--peach-gold) 100%);
  transition: opacity 600ms ease;
}

#fade.hidden,
#fade.out,
#fade.done {
  opacity: 0;
}

/* ── HUD scaffolding ───────────────────────────────────────────────────── */
#hud {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

/* ── Logo: the two "l"s are stacked voxel squares ──────────────────────── */
.logo {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 24px;
  line-height: 1;
  color: var(--cloud-white);
  letter-spacing: 0.01em;
  text-shadow: 0 2px 12px rgba(40, 20, 60, 0.35);
}

#logo {
  position: fixed;
  top: calc(var(--space-2) + env(safe-area-inset-top, 0px));
  left: calc(var(--space-2) + env(safe-area-inset-left, 0px));
}

.voxel-l {
  display: inline-block;
  position: relative;
  width: 0.36em;
  height: 0.76em;
  margin: 0 0.1em;
}

.voxel-l i {
  position: absolute;
  left: 0;
  width: 0.36em;
  height: 0.36em;
  border-radius: 0.09em;
  box-shadow: inset -0.06em -0.07em 0 rgba(43, 29, 58, 0.25);
}

.voxel-l i:first-child {
  top: 0;
}

.voxel-l i:last-child {
  bottom: 0;
}

.vx-honey {
  background: var(--honey);
}

.vx-terra {
  background: var(--terracotta);
}

.logo-card {
  display: inline-block;
  font-size: 20px;
  margin-bottom: var(--space-2);
  text-shadow: none;
}

/* ── Prompt pill ───────────────────────────────────────────────────────── */
#prompt-pill {
  position: fixed;
  top: calc(var(--space-2) + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  max-width: min(620px, 92vw);
  padding: var(--space-1) var(--space-3);
  text-align: center;
  pointer-events: none;
  background: var(--glass-fill);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-pill);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

#prompt-text {
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.02em;
}

#day-line {
  margin-top: 0;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 12px;
  letter-spacing: 0.08em;
  color: rgba(247, 241, 232, 0.85);
}

/* ── Palette ───────────────────────────────────────────────────────────── */
#palette {
  position: fixed;
  bottom: calc(var(--space-2) + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 176px);
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1);
  overflow-x: auto;
  scrollbar-width: none;
  pointer-events: auto;
  background: var(--glass-fill);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-pill);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

#palette::-webkit-scrollbar {
  display: none;
}

.swatch {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-s);
  box-shadow: inset 0 0 0 1px rgba(43, 45, 58, 0.18), 0 2px 6px rgba(24, 14, 38, 0.25);
  transition: transform 150ms ease, box-shadow 150ms ease;
}

.swatch:hover {
  transform: translateY(-2px);
}

.swatch.selected {
  transform: translateY(-4px);
  box-shadow: 0 0 0 2px var(--cloud-white), 0 6px 14px rgba(24, 14, 38, 0.35);
}

.message-slot {
  margin-left: var(--space-1);
  display: grid;
  place-items: center;
  color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(43, 45, 58, 0.18), 0 0 12px rgba(255, 232, 168, 0.55);
}

.message-slot svg {
  width: 18px;
  height: 18px;
}

.message-slot.selected {
  box-shadow: 0 0 0 2px var(--cloud-white), 0 0 16px rgba(255, 232, 168, 0.7);
}

.message-slot:disabled {
  filter: grayscale(0.7) brightness(0.75);
  opacity: 0.6;
  cursor: default;
  transform: none;
  box-shadow: inset 0 0 0 1px rgba(43, 45, 58, 0.18);
}

/* ── Action buttons ────────────────────────────────────────────────────── */
#actions {
  position: fixed;
  right: calc(var(--space-2) + env(safe-area-inset-right, 0px));
  bottom: calc(var(--space-2) + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  pointer-events: auto;
}

.round-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-pill);
  background: var(--glass-fill);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transition: transform 150ms ease, background 150ms ease;
}

.round-btn:hover {
  background: var(--glass-fill-strong);
  transform: translateY(-2px);
}

.round-btn:active {
  transform: translateY(0) scale(0.96);
}

.round-btn svg {
  width: 20px;
  height: 20px;
}

.qmark {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
}

#btn-sound .icon-sound-off {
  display: none;
}

#btn-sound.muted .icon-sound-on {
  display: none;
}

#btn-sound.muted .icon-sound-off {
  display: block;
}

/* ── Joystick (visuals only; input math lives in main.js) ──────────────── */
#joystick {
  position: fixed;
  z-index: 5;
  width: 112px;
  height: 112px;
  margin: -56px 0 0 -56px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 160ms ease, visibility 160ms;
}

#joystick.active {
  opacity: 1;
  visibility: visible;
}

#joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 4px 12px rgba(24, 14, 38, 0.3);
  transform: translate(-50%, -50%);
}

/* ── Toast ─────────────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  z-index: 60;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 8px);
  max-width: 86vw;
  padding: var(--space-1) var(--space-2);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.04em;
  text-align: center;
  pointer-events: none;
  background: rgba(43, 29, 58, 0.7);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-pill);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 300ms ease, transform 300ms ease, visibility 300ms;
}

#toast.show {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
}

/* ── Streak celebration ────────────────────────────────────────────────── */
#celebrate {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  pointer-events: none;
  opacity: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(44px, 9vw, 96px);
  letter-spacing: 0.01em;
  color: var(--cloud-white);
  text-shadow: 0 6px 32px rgba(235, 180, 78, 0.6), 0 2px 8px rgba(40, 20, 60, 0.4);
}

#celebrate.go {
  opacity: 1;
  animation: celebrate-pop 1.9s cubic-bezier(0.22, 1.2, 0.36, 1) forwards;
}

@keyframes celebrate-pop {
  0% {
    opacity: 0;
    transform: scale(0.6);
  }
  14% {
    opacity: 1;
    transform: scale(1.06);
  }
  26% {
    transform: scale(1);
  }
  72% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: scale(1.04);
  }
}

/* ── Overlays & cards ──────────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-3);
  background: var(--overlay-scrim);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.overlay.hidden {
  display: none;
}

.card {
  width: min(400px, 100%);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: var(--space-4);
  text-align: center;
  background: var(--card-fill);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-s);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow-deep);
  animation: card-in 240ms cubic-bezier(0.34, 1.3, 0.64, 1);
}

@supports (height: 100dvh) {
  .card {
    max-height: calc(100dvh - 48px);
  }
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.card-title {
  display: block;
  margin: 0 0 var(--space-2);
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 22px;
  letter-spacing: 0.01em;
}

.card-body {
  margin: 0 0 var(--space-3);
  font-size: 15px;
  line-height: 1.6;
  color: rgba(247, 241, 232, 0.85);
}

.card-row {
  display: flex;
  justify-content: center;
  gap: var(--space-1);
  margin-top: var(--space-2);
}

#help-name,
#composer-text {
  width: 100%;
  padding: var(--space-1) var(--space-2);
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 16px;
  letter-spacing: 0.03em;
  color: var(--cloud-white);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-s);
  transition: border-color 150ms ease, background 150ms ease;
}

#help-name {
  text-align: center;
}

#help-name:focus,
#composer-text:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.45);
  background: rgba(255, 255, 255, 0.14);
}

#help-name::placeholder,
#composer-text::placeholder {
  color: rgba(247, 241, 232, 0.45);
}

#composer-text {
  min-height: 96px;
  resize: none;
  text-align: left;
  line-height: 1.5;
}

#composer-count {
  margin-top: var(--space-1);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-align: right;
  color: rgba(247, 241, 232, 0.6);
}

.controls {
  list-style: none;
  margin: var(--space-3) 0;
  padding: 0;
  display: grid;
  gap: var(--space-1);
  text-align: left;
}

.controls li {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.02em;
  color: rgba(247, 241, 232, 0.88);
}

.controls svg {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  color: var(--honey);
}

.button-primary {
  padding: var(--space-1) var(--space-3);
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 16px;
  letter-spacing: 0.02em;
  color: var(--ink);
  background: var(--honey);
  border-radius: var(--radius-pill);
  box-shadow: 0 4px 14px rgba(235, 180, 78, 0.35);
  transition: transform 150ms ease, filter 150ms ease;
}

.button-primary:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
}

.button-primary:active {
  transform: translateY(0) scale(0.97);
}

.button-primary:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
  filter: none;
}

.button-ghost {
  padding: var(--space-1) var(--space-3);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.02em;
  color: rgba(247, 241, 232, 0.85);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-pill);
  transition: background 150ms ease;
}

.button-ghost:hover {
  background: rgba(255, 255, 255, 0.12);
}

/* Envelope seals atop the note cards */
.seal {
  width: 40px;
  height: 40px;
  margin: 0 auto var(--space-2);
  display: grid;
  place-items: center;
  border-radius: var(--radius-pill);
}

.seal svg {
  width: 18px;
  height: 18px;
}

.seal-glow {
  background: var(--glow);
  color: var(--ink);
  box-shadow: 0 0 18px rgba(255, 232, 168, 0.45);
}

.seal-wax {
  background: var(--brick-red);
  color: var(--cloud-white);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.18);
}

/* Parchment note card — warm paper, handwritten warmth */
.card.parchment {
  background: linear-gradient(160deg, #F7ECCB 0%, #EFDFB4 60%, #E7D2A0 100%);
  border: 1px solid rgba(110, 75, 58, 0.28);
  color: #4A3A2E;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

#note-text {
  margin: 0;
  font-weight: 600;
  font-size: 17px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

#note-author {
  margin: var(--space-2) 0 0;
  font-style: italic;
  font-weight: 600; /* the loaded Nunito italic face — no faux bold */
  font-size: 14px;
  text-align: right;
  color: #8A6B52;
}

/* ── Mobile (≤500px, verified at 390px) ────────────────────────────────── */
@media (max-width: 500px) {
  .logo {
    font-size: 20px;
  }

  #prompt-pill {
    top: calc(48px + env(safe-area-inset-top, 0px));
    max-width: calc(100vw - 24px);
    padding: var(--space-1) var(--space-2);
  }

  #prompt-text {
    font-size: 13px;
  }

  #palette {
    left: var(--space-1);
    right: var(--space-1);
    transform: none;
    max-width: none;
    justify-content: flex-start;
    bottom: calc(var(--space-1) + env(safe-area-inset-bottom, 0px));
    /* right-edge fade hints that the row scrolls; ui.js lifts it at the end */
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 32px), rgba(0, 0, 0, 0.08));
    mask-image: linear-gradient(to right, #000 calc(100% - 32px), rgba(0, 0, 0, 0.08));
  }

  #palette.at-end {
    -webkit-mask-image: none;
    mask-image: none;
  }

  .swatch {
    width: 44px;
    height: 44px;
  }

  #actions {
    flex-direction: row;
    right: var(--space-1);
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  }

  #toast {
    bottom: calc(152px + env(safe-area-inset-bottom, 0px));
  }

  .mini-menu {
    right: var(--space-1);
    bottom: calc(128px + env(safe-area-inset-bottom, 0px));
  }

  .mini-menu button {
    min-height: 44px;
  }
}

/* ── Mini-menus (share / views) ────────────────────────────────────────── */
.mini-menu {
  position: fixed;
  right: var(--space-2);
  bottom: 72px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-1);
  background: var(--card-fill);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-s);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow-deep);
}

.mini-menu.hidden {
  display: none;
}

.mini-menu button {
  min-width: 152px;
  padding: var(--space-1) var(--space-2);
  border: 0;
  border-radius: var(--radius-s);
  background: var(--glass-fill);
  color: var(--cloud-white);
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.04em;
  text-align: left;
  cursor: pointer;
}

.mini-menu button:hover {
  background: var(--glass-fill-strong);
}

/* ── Photo mode: tilt-shift bands + exit pill ──────────────────────────── */
.tilt-band {
  position: fixed;
  left: 0;
  right: 0;
  height: 18vh;
  z-index: 5;
  display: none;
  pointer-events: none;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

#tilt-top {
  top: 0;
  -webkit-mask-image: linear-gradient(to bottom, #000 30%, transparent);
  mask-image: linear-gradient(to bottom, #000 30%, transparent);
}

#tilt-bottom {
  bottom: 0;
  -webkit-mask-image: linear-gradient(to top, #000 30%, transparent);
  mask-image: linear-gradient(to top, #000 30%, transparent);
}

body.photo-mode .tilt-band {
  display: block;
}

#photo-exit {
  position: fixed;
  left: 50%;
  bottom: calc(var(--space-3) + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 31;
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-pill);
  background: var(--card-fill);
  color: var(--cloud-white);
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.06em;
  cursor: pointer;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

#photo-exit.hidden {
  display: none;
}

/* ── HUD hidden (photo mode / filming) ─────────────────────────────────── */
body.hud-hidden #hud {
  display: none;
}

/* ── Filming: vertical letterbox + chrome ──────────────────────────────── */
body.filming {
  background: #241636;
}

body.filming #app {
  display: flex;
  align-items: center;
  justify-content: center;
}

body.filming #app canvas {
  width: auto !important;
  height: 100% !important;
}

#filming {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
}

#filming.hidden {
  display: none;
}

#filming-frame {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  height: calc(100% - var(--space-2));
  aspect-ratio: 9 / 16;
  border: 1px solid rgba(247, 241, 232, 0.5);
  border-radius: var(--radius-s);
}

#filming-caption {
  position: absolute;
  left: 50%;
  top: calc(50% + 50vh - 48px);
  transform: translateX(-50%);
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 14px;
  letter-spacing: 0.08em;
  color: rgba(247, 241, 232, 0.85);
  text-shadow: 0 2px 12px rgba(24, 14, 38, 0.8);
}

/* On touch devices the composer top-aligns so its buttons clear the
   on-screen keyboard (centered, they'd sit right under it on a 390×844). */
@media (pointer: coarse) {
  #overlay-composer {
    align-items: flex-start;
    padding-top: calc(env(safe-area-inset-top, 0px) + 48px);
  }
}

/* ── Reduced motion: no CSS transitions or animations ──────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}
