:root {
  --bg: #08080b;
  --text: #e8e8ee;
  --muted: #9a9aa6;
  --line: rgba(255, 255, 255, 0.09);
  --fill: rgba(255, 255, 255, 0.045);
  --radius: 24px;
  --hue: 250; /* set per time-of-day from js */
}

* { box-sizing: border-box; }
html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, sans-serif;
}

/* the stage centers the card and hosts the glow behind it */
.stage {
  position: relative;
  width: min(400px, 100%);
  display: grid;
  place-items: center;
}

/* glow: a blurred rounded-rect behind the card, hue from the clock.
   the colour wheel turns via an animated @property angle, not a rotating
   element, so the halo keeps its shape while the colours drift. crisp,
   no canvas, no aliasing. */
@property --spin {
  syntax: "<angle>";
  initial-value: 0deg;
  inherits: false;
}

.glow {
  position: absolute;
  inset: -2px;
  border-radius: var(--radius);
  background: conic-gradient(
    from var(--spin),
    hsl(var(--hue) 85% 62%),
    hsl(calc(var(--hue) + 55) 85% 62%),
    hsl(calc(var(--hue) - 55) 85% 62%),
    hsl(var(--hue) 85% 62%)
  );
  filter: blur(34px) saturate(1.15);
  opacity: 0.55;
  animation: drift 22s linear infinite;
  z-index: -1;
}

@keyframes drift {
  to { --spin: 360deg; }
}

/* card + flip. tilt and flip write separate vars and compose here, so the
   two modules never stomp each other's transform. */
.card {
  position: relative;
  width: 100%;
  transform-style: preserve-3d;
  transform: perspective(1000px)
    rotateX(var(--rx, 0deg))
    rotateY(calc(var(--flip, 0deg) + var(--ry, 0deg)));
}

.face {
  border-radius: var(--radius);
  backface-visibility: hidden;
}

/* perspective here gives the lifting sheet its depth */
.front { position: relative; perspective: 1300px; }

.back {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 28px;
  transform: rotateY(180deg);
}

/* glass panel — faked with gradients + an inner highlight instead of
   backdrop-filter, which fringed badly mid-flip. shared by the sheet + back. */
.sheet, .back {
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.012) 42%),
    rgba(13, 13, 19, 0.96);
  border: 1px solid var(--line);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

/* the sheet is in-flow so it sizes the card; it lifts on a top hinge. the board
   fills the same box behind it and is uncovered as the sheet swings up. */
.sheet {
  position: relative;
  z-index: 1;
  border-radius: var(--radius);
  transform-origin: 50% 0;
  transform: rotateX(var(--peel, 0deg));
  transform-style: preserve-3d;
  backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 36px 32px;
  text-align: center;
}

/* paper underside, revealed as the sheet passes edge-on */
.sheet::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  transform: rotateX(180deg);
  backface-visibility: hidden;
  background: linear-gradient(200deg, #15151d, #0c0c12);
  box-shadow: inset 0 0 0 1px var(--line);
}

/* the board sits under the sheet — darker so the lift reads as depth */
.board {
  position: absolute;
  inset: 0;
  z-index: 0;
  list-style: none;
  margin: 0;
  padding: 26px;
  border-radius: var(--radius);
  background: linear-gradient(160deg, #111119, #0b0b11);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 12px;
  overflow: hidden;
}

/* shadow the sheet casts on the board as it lifts away */
.card[data-peel] .board {
  box-shadow: inset 0 22px 34px -14px rgba(0, 0, 0, 0.65);
}

.board:empty::after {
  content: "no messages yet";
  margin: auto;
  color: var(--muted);
  font-size: 13px;
}

.board li {
  align-self: var(--side, center);
  max-width: 86%;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
  transform: rotate(var(--r, 0deg));
}

.board .who {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

/* the corner grip that starts a peel */
.grip {
  position: absolute;
  right: -4px;
  bottom: -4px;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 0;
  background: none;
  cursor: grab;
  touch-action: none;
  z-index: 5;
}

/* shared icon button — nav links and the close button look/behave the same */
.icon-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.2s, background 0.2s, transform 0.2s;
}

.icon-btn svg {
  width: 21px;
  height: 21px;
  fill: currentColor;
}

/* cursor-following sheen, same as the nav icons; --mx/--my fed from js */
.icon-btn::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(60px at var(--mx, 50%) var(--my, 50%), hsl(var(--hue) 90% 70% / 0.4), transparent 70%);
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
}

.icon-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  transform: translateY(-2px);
}

.icon-btn:hover::after { opacity: 1; }
.icon-btn:active { transform: translateY(-2px) scale(0.86); transition-duration: 0.06s; }

nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
}

.close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 30px;
  height: 30px;
  font-size: 17px;
  line-height: 1;
  background: rgba(255, 255, 255, 0.08);
}

/* avatar with status ring + drag-to-spin */
.avatar {
  --ring: #80848e;
  display: inline-block;
  padding: 3px;
  border-radius: 50%;
  border: 3px solid var(--ring);
  cursor: grab;
  touch-action: none;
  transition: border-color 0.4s, transform 0.2s;
}

.avatar:hover { transform: translateZ(8px) scale(1.06); }
.avatar[data-status="online"] { --ring: #23a55a; }
.avatar[data-status="idle"] { --ring: #f0b232; }
.avatar[data-status="dnd"] { --ring: #f23f43; }
.avatar img { display: block; border-radius: 50%; }
.avatar.rip { animation: rip 0.7s ease-out; }

@keyframes rip {
  30% { border-color: #f0c54a; box-shadow: 0 0 24px rgba(240, 197, 74, 0.5); }
}

h1 { margin: 0; font-size: 22px; font-weight: 600; }

.status {
  margin: 0;
  min-height: 1.5em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
}

.game { position: relative; display: inline-flex; }
.game[hidden] { display: none; }
.game svg { width: 17px; height: 17px; }

.game::after {
  content: attr(data-game);
  position: absolute;
  bottom: calc(100% + 7px);
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  padding: 4px 9px;
  border-radius: 7px;
  background: rgba(18, 18, 26, 0.96);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.game:hover::after { opacity: 1; }

/* now playing / last.fm row */
.track {
  position: relative;
  display: grid;
  grid-template-columns: 48px 1fr;
  grid-template-rows: 24px 24px;
  column-gap: 12px;
  align-items: center;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--fill);
  color: inherit;
  text-decoration: none;
  text-align: left;
  transition: background 0.2s, filter 0.2s;
}

.track[href]:hover { background: rgba(255, 255, 255, 0.07); filter: brightness(1.2); }
.track:not([href]) { pointer-events: none; }
.track img { grid-row: 1 / 3; border-radius: 8px; background: var(--line); }

.track .name, .track .sub {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 14px;
}

.track .sub { color: var(--muted); font-size: 13px; }
.track .when:not(:empty)::before { content: " · "; }

.track .progress {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  overflow: hidden;
  border-radius: 0 0 14px 14px;
  background: var(--line);
}

.track[data-spotify] .progress { display: block; }

.track .progress::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, hsl(var(--hue) 80% 60%), hsl(calc(var(--hue) + 40) 80% 65%));
  transform: scaleX(var(--p, 0));
  transform-origin: left;
  transition: transform 1s linear;
}

.track[data-live] .when { color: hsl(var(--hue) 80% 70%); }

.bars { display: none; }
.track[data-live] .bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 10px; margin-left: 6px; }
.bars i { width: 2px; height: 4px; border-radius: 1px; background: hsl(var(--hue) 80% 70%); animation: bounce 1.1s ease-in-out infinite; }
.bars i:nth-child(2) { animation-delay: -0.37s; }
.bars i:nth-child(3) { animation-delay: -0.74s; }

@keyframes bounce { 0%, 100% { height: 4px; } 50% { height: 10px; } }

.track:not([href]) .name::before, .track:not([href]) .sub::before {
  content: "";
  display: inline-block;
  width: 8em;
  height: 0.7em;
  border-radius: 4px;
  background: var(--line);
}

.track:not([href]) .sub::before { width: 5em; }

/* note form */
.note { display: flex; flex-direction: column; gap: 8px; width: 100%; }

textarea {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--fill);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  resize: vertical;
  min-height: 64px;
}

textarea::placeholder { color: var(--muted); }
input[name="website"] { position: absolute; left: -9999px; }

.send {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, hsl(var(--hue) 80% 62%), hsl(calc(var(--hue) + 40) 75% 58%));
  border: 0;
  border-radius: 10px;
  padding: 9px;
  cursor: pointer;
  transition: filter 0.2s;
}

.send:hover { filter: brightness(1.15); }
.send:disabled { filter: saturate(0.3) brightness(0.7); cursor: default; }

.feedback { min-height: 1.5em; margin: 0; color: var(--muted); font-size: 13px; }

/* turnstile mounts here; keep it out of the centering grid */
#ts { position: fixed; bottom: 0; left: 0; }

:focus-visible { outline: 2px solid hsl(var(--hue) 80% 65%); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
