:root {
  --bg: #08060a;
  --gold: #d4af37;
  --gold-bright: #f7d774;
  --crimson: #ef4444;
  --text: #f4f4f5;
  --muted: #b4b0ba;
  --serif: "Cinzel", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  background: radial-gradient(circle at 50% 0%, #2a0d16 0%, #100a12 45%, var(--bg) 100%);
  background-color: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, sans-serif;
  overflow: hidden;
}

button { font: inherit; color: inherit; }
button:focus-visible { outline: 2px solid var(--gold-bright); outline-offset: 3px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- 3D scene ---------- */
.scene { position: fixed; inset: 0; z-index: 0; }
.scene canvas { display: block; width: 100%; height: 100%; touch-action: manipulation; }

.vignette {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(6, 4, 8, 0.72) 0%, rgba(6, 4, 8, 0) 30%, rgba(6, 4, 8, 0) 72%, rgba(6, 4, 8, 0.85) 100%),
    radial-gradient(ellipse at 50% 50%, transparent 55%, rgba(0, 0, 0, 0.7) 100%);
}

.flash {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 65%, rgba(255, 190, 110, 0.75), rgba(180, 20, 20, 0.35) 45%, transparent 75%);
  opacity: 0;
}
.flash.go { animation: flash 1.1s ease-out; }
@keyframes flash { 0% { opacity: 0; } 12% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- Layout ---------- */
/* The app layer lets clicks fall through to the canvas except on real controls. */
.app {
  position: relative;
  z-index: 3;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  pointer-events: none;
  text-align: center;
}
.top-controls, .knock-btn, .dock { pointer-events: auto; }

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: max(14px, env(safe-area-inset-top)) 20px 0;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(100, 14, 18, 0.35);
  border: 1px solid rgba(239, 68, 68, 0.35);
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  color: #fecaca;
  text-align: left;
}

.pulse-dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--crimson);
  box-shadow: 0 0 10px var(--crimson);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.3; transform: scale(0.7); } }

.top-controls { display: flex; gap: 8px; flex: none; }

.ghost-btn {
  min-height: 38px;
  padding: 8px 13px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(12, 9, 14, 0.6);
  backdrop-filter: blur(8px);
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.ghost-btn:hover { background: rgba(212, 175, 55, 0.14); border-color: rgba(212, 175, 55, 0.55); }
.ghost-btn.active { border-color: var(--gold); color: var(--gold-bright); }

.hud { padding: 10px 16px 0; }
.stage-window { flex: 1; min-height: 0; }

/* ---------- Hero + countdown ---------- */
.eyebrow {
  font-family: var(--mono);
  font-size: clamp(0.6rem, 1.6vw, 0.74rem);
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--gold);
}

.title {
  font-family: var(--serif);
  font-weight: 900;
  font-size: clamp(2rem, min(7vw, 9vh), 4.6rem);
  line-height: 1.05;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  text-wrap: balance;
  margin: 4px 0 6px;
  background: linear-gradient(180deg, #fff9e3 8%, var(--gold-bright) 45%, var(--gold) 68%, #7d5c0e 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 18px rgba(0, 0, 0, 0.9)) drop-shadow(0 0 28px rgba(212, 175, 55, 0.22));
}

.subtitle { color: #d6d3db; font-size: clamp(0.86rem, 2.2vw, 1rem); text-shadow: 0 2px 8px #000; }
.highlight { color: #ff5a5a; font-weight: 700; }

.countdown {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: clamp(7px, 1.4vw, 14px);
  width: min(100%, 540px);
  margin: clamp(10px, 2vh, 18px) auto 0;
}

.time-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: clamp(10px, 1.8vh, 18px) 4px;
  border-radius: 14px;
  border: 1px solid rgba(212, 175, 55, 0.32);
  background: linear-gradient(180deg, rgba(34, 24, 34, 0.82), rgba(10, 8, 13, 0.88));
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.09);
  backdrop-filter: blur(6px);
}

.time-value {
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(1.9rem, min(8vw, 8vh), 3.5rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 22px rgba(247, 215, 116, 0.28);
}
.time-value.tick { animation: tick 0.35s ease-out; }
@keyframes tick { from { transform: translateY(-5px); opacity: 0.35; } }

.time-label {
  margin-top: 7px;
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
}

.target-date {
  margin-top: 10px;
  font-family: var(--mono);
  font-size: 0.74rem;
  color: #e4e4e7;
  text-shadow: 0 2px 8px #000;
}
.local-time { display: block; margin-top: 2px; color: var(--muted); font-size: 0.68rem; }

body.imminent .time-card { border-color: rgba(239, 68, 68, 0.6); }
body.imminent .time-value { color: #ffd9d9; text-shadow: 0 0 24px rgba(239, 68, 68, 0.65); }

.final-count {
  position: fixed;
  inset: 0;
  z-index: 6;
  display: none;
  align-items: center;
  justify-content: center;
  padding-top: 12vh;
  pointer-events: none;
  font-family: var(--serif);
  font-weight: 900;
  font-size: min(48vw, 48vh);
  color: rgba(255, 235, 200, 0.92);
  text-shadow: 0 0 60px rgba(239, 68, 68, 0.85), 0 10px 40px #000;
}
.final-count.show { display: flex; animation: countPop 0.95s ease-out forwards; }
@keyframes countPop {
  0% { transform: scale(1.35); opacity: 0; }
  18% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.82); opacity: 0; }
}

/* ---------- Declaration ---------- */
.stamp {
  display: inline-block;
  padding: 6px 18px;
  border: 3px double var(--crimson);
  border-radius: 6px;
  color: #ff6b6b;
  background: rgba(60, 4, 6, 0.55);
  box-shadow: 0 0 28px rgba(239, 68, 68, 0.3);
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(0.8rem, 2.4vw, 1.05rem);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  transform: rotate(-4deg);
  /* Delays line up with the lid opening in the 3D sequence. */
  animation: stampSlam 0.55s 4.6s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
@keyframes stampSlam { from { transform: scale(3.4) rotate(-16deg); opacity: 0; } }

.declaration h2 {
  margin-top: 10px;
  font-family: var(--serif);
  font-weight: 900;
  font-size: clamp(1.45rem, min(5.5vw, 6.5vh), 3rem);
  line-height: 1.1;
  text-transform: uppercase;
  text-wrap: balance;
  color: var(--gold-bright);
  text-shadow: 0 4px 18px #000;
  animation: riseIn 0.8s 4.95s ease-out both;
}
.declaration p {
  margin-top: 4px;
  color: #d6d3db;
  font-size: 0.9rem;
  text-shadow: 0 2px 8px #000;
  animation: riseIn 0.8s 5.2s ease-out both;
}
@keyframes riseIn { from { opacity: 0; transform: translateY(14px); } }

/* ---------- Bottom area ---------- */
.bottom { padding: 0 12px max(8px, env(safe-area-inset-bottom)); }

.idle-panel { padding-bottom: 8px; }
.knock-btn {
  min-height: 44px;
  padding: 10px 22px;
  border-radius: 999px;
  border: 1px solid rgba(212, 175, 55, 0.5);
  background: rgba(18, 12, 16, 0.75);
  backdrop-filter: blur(8px);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.knock-btn:hover { background: rgba(212, 175, 55, 0.18); }
.knock-btn:active { transform: scale(0.96); }
.knock-reply {
  min-height: 1.4em;
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--muted);
}

.dock {
  width: min(100%, 640px);
  margin: 0 auto;
  padding: 12px 14px 10px;
  border-radius: 20px;
  border: 1px solid rgba(212, 175, 55, 0.3);
  background: linear-gradient(180deg, rgba(24, 18, 28, 0.88), rgba(9, 7, 12, 0.95));
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(10px);
  animation: riseIn 0.6s ease-out;
}

.rehearsal-flag {
  margin-bottom: 8px;
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px dashed rgba(96, 165, 250, 0.6);
  background: rgba(37, 99, 235, 0.14);
  color: #bfdbfe;
  font-size: 0.74rem;
}

.dock-head { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: stretch; }
.stat {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 6px 8px;
  border-radius: 11px;
  background: rgba(0, 0, 0, 0.42);
  border: 1px solid rgba(255, 255, 255, 0.07);
}
.stat-label {
  font-size: 0.56rem;
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--muted);
}
.stat-value { font-family: var(--mono); font-weight: 700; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.stat-value.gold { color: var(--gold-bright); }

.remove-btn {
  padding: 6px 12px;
  border-radius: 11px;
  border: 1px solid rgba(239, 68, 68, 0.4);
  background: rgba(127, 29, 29, 0.22);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
}
.remove-btn:hover:not(:disabled) { background: rgba(220, 38, 38, 0.35); }
.remove-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.dock-status { margin: 9px 0 11px; font-size: 0.8rem; line-height: 1.4; color: #e4e4e7; }
.dock-status.locked { color: #bbf7d0; }
.dock-status.error { color: #fecaca; }

.chip-rack { display: grid; grid-template-columns: repeat(6, 1fr); gap: clamp(4px, 1.6vw, 14px); justify-items: center; }

.poker-chip {
  width: 100%;
  max-width: 62px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  background:
    radial-gradient(circle, var(--chip) 0 56%, rgba(255, 255, 255, 0.55) 57% 60%, transparent 61%),
    repeating-conic-gradient(from -11deg, var(--edge) 0 22deg, var(--chip) 22deg 60deg);
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.6), 0 10px 18px rgba(0, 0, 0, 0.6), inset 0 0 0 2px rgba(255, 255, 255, 0.2);
  transition: transform 0.16s, box-shadow 0.16s, opacity 0.2s;
}
.poker-chip span { font-family: var(--mono); font-weight: 700; font-size: clamp(0.66rem, 2.6vw, 0.86rem); color: #fff; text-shadow: 0 1px 3px #000; }
.poker-chip:hover:not(:disabled) { transform: translateY(-6px) rotate(24deg); box-shadow: 0 8px 0 rgba(0, 0, 0, 0.5), 0 16px 26px rgba(212, 175, 55, 0.35); }
.poker-chip:active:not(:disabled) { transform: translateY(2px) scale(0.95); }
.poker-chip:disabled { opacity: 0.38; cursor: not-allowed; }
.poker-chip.armed { outline: 3px solid var(--gold-bright); outline-offset: 3px; animation: armed 0.8s ease-in-out infinite; }
.remove-btn.armed { background: #b91c1c; border-color: #fecaca; }
@keyframes armed { 50% { transform: translateY(-5px); } }

.poster .top-bar, .poster .bottom, .poster .countdown, .poster .local-time, .poster .subtitle { display: none; }
.poster .title { font-size: 4.4rem; }
.poster .target-date { font-size: 1.05rem; }
.poster .eyebrow { display: block; }
.poster .hud { padding-top: 34px; }

.quote { min-height: 1.3em; margin-top: 10px; font-family: var(--mono); font-size: 0.72rem; color: var(--gold-bright); }

.footer { margin-top: 6px; font-size: 0.66rem; color: #8b8791; }

.chip-tooltip {
  position: fixed;
  z-index: 7;
  pointer-events: none;
  transform: translate(-50%, -140%);
  padding: 5px 10px;
  border-radius: 7px;
  border: 1px solid var(--gold);
  background: rgba(10, 8, 12, 0.95);
  font-family: var(--mono);
  font-size: 0.72rem;
  white-space: nowrap;
}

/* ---------- Flat fallback (no WebGL, or the 3D library failed to load) ---------- */
.flat-stage { position: absolute; inset: 0; }
.flat-coffin {
  position: absolute;
  background: radial-gradient(ellipse at 40% 50%, #8f1620, #2c0407 80%);
  clip-path: polygon(0 24%, 26% 0, 100% 22%, 100% 78%, 26% 100%, 0 76%);
  pointer-events: auto;
}
.flat-coffin.closed { background: linear-gradient(160deg, #6b3a24, #1f0e08); }
.flat-coffin.closed .flat-chip { display: none; }
.flat-chip {
  position: absolute;
  width: 32px;
  height: 32px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 3px dashed var(--edge);
  background: var(--chip);
  color: #fff;
  font: 700 0.55rem var(--mono);
  cursor: pointer;
}

/* ---------- Small screens ---------- */
@media (max-width: 640px) {
  .top-bar { flex-direction: column-reverse; gap: 8px; padding-left: 10px; padding-right: 10px; }
  .status-pill { font-size: 0.6rem; padding: 5px 10px; }
  .btn-text { font-size: 0.74rem; }
  .eyebrow { letter-spacing: 0.16em; }
  .dock-head { grid-template-columns: 1fr 1fr; }
  .remove-btn { grid-column: 1 / -1; min-height: 36px; }
  .footer { display: none; }
}

/* Short windows: landscape phones, small laptops */
@media (max-height: 760px) {
  .eyebrow, .footer, .declaration p { display: none; }
  .dock-status { margin: 6px 0 8px; }
  .quote { margin-top: 7px; }
  .poker-chip { max-width: 52px; }
}

@media (max-height: 520px) {
  .status-pill, .subtitle, .local-time, .knock-reply, .quote, .rehearsal-flag { display: none; }
  .top-bar { justify-content: flex-end; padding-top: 6px; }
  .hud { padding-top: 0; }
  .title { font-size: 1.4rem; }
  .time-card { padding: 5px 4px; }
  .time-value { font-size: 1.4rem; }
  .time-label { margin-top: 2px; }
  .stamp { font-size: 0.6rem; padding: 2px 10px; }
  .declaration h2 { font-size: 1.15rem; margin-top: 4px; }
  .dock { width: min(100%, 560px); padding: 6px 10px 8px; }
  .dock-head { grid-template-columns: 1fr 1fr auto; }
  .remove-btn { grid-column: auto; }
  .stat-value { font-size: 0.95rem; }
  .poker-chip { max-width: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-delay: 0ms !important; transition-duration: 0.01ms !important; }
}
