/* =====================================================================
   Dixit Companion
   A small magical-night booklet for storytellers.
   Midnight stage · cream serif · antique gold ornaments.
   ===================================================================== */

:root {
  /* Palette */
  --midnight:      #0F1B33;
  --midnight-deep: #070D1C;
  --midnight-soft: #1A2A4A;
  --cream:         #F1E5C7;
  --cream-soft:    #E5D5B0;
  --cream-deep:    #C9B98F;
  --gold:          #D4AF6F;
  --gold-deep:     #B89058;
  --gold-soft:     rgba(212, 175, 111, 0.55);
  --coral:         #D97862;
  --plum:          #7E5A85;
  --moss:          #4A6552;

  --paper:   var(--midnight);
  --ink:     var(--cream);
  --ink-soft: rgba(241, 229, 199, 0.62);
  --ink-faint: rgba(241, 229, 199, 0.30);
  --rule:     rgba(212, 175, 111, 0.55);
  --rule-soft: rgba(212, 175, 111, 0.20);

  --accent:   var(--gold);

  /* Type */
  --serif:   "Fraunces", "Cormorant Garamond", "Iowan Old Style", Georgia, serif;
  --serif-2: "Cormorant Garamond", "Garamond", Georgia, serif;

  --ease:     cubic-bezier(0.65, 0, 0.35, 1);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);

  --pad-x: 22px;
}

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

html, body {
  height: 100%;
  height: 100svh;
  overflow: hidden;
  overscroll-behavior: none;
}

html {
  background: var(--midnight-deep);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-size-adjust: 100%;
  font-variant-ligatures: common-ligatures discretionary-ligatures contextual;
}

body {
  font-family: var(--serif);
  font-variation-settings: "opsz" 14, "wght" 400, "SOFT" 100, "WONK" 0;
  background:
    radial-gradient(1200px 700px at 75% -10%, rgba(126, 90, 133, 0.20), transparent 60%),
    radial-gradient(900px 600px at 0% 80%, rgba(212, 175, 111, 0.10), transparent 65%),
    radial-gradient(1500px 1000px at 50% 50%, var(--midnight-soft) 0%, var(--midnight) 50%, var(--midnight-deep) 100%);
  position: relative;
}

/* ---------- Atmospheric layers (stars + grain) ---------------------- */

.night {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}
.night-glow {
  position: absolute;
  inset: -10%;
  background:
    radial-gradient(420px 320px at 18% 28%, rgba(212, 175, 111, 0.10), transparent 70%),
    radial-gradient(360px 240px at 82% 78%, rgba(217, 120, 98, 0.08), transparent 70%);
  filter: blur(2px);
}

/* Two scattered star layers, different sizes */
.night-stars {
  position: absolute;
  inset: 0;
  background-repeat: no-repeat;
  background-color: transparent;
}
.night-stars-a {
  background-image:
    radial-gradient(1px 1px at 12% 14%, rgba(241,229,199,0.85), transparent 60%),
    radial-gradient(1px 1px at 78% 8%, rgba(241,229,199,0.55), transparent 60%),
    radial-gradient(1px 1px at 46% 22%, rgba(241,229,199,0.70), transparent 60%),
    radial-gradient(1px 1px at 92% 36%, rgba(241,229,199,0.55), transparent 60%),
    radial-gradient(1px 1px at 8% 48%, rgba(241,229,199,0.50), transparent 60%),
    radial-gradient(1px 1px at 28% 64%, rgba(241,229,199,0.65), transparent 60%),
    radial-gradient(1px 1px at 62% 70%, rgba(241,229,199,0.45), transparent 60%),
    radial-gradient(1px 1px at 86% 82%, rgba(241,229,199,0.55), transparent 60%),
    radial-gradient(1px 1px at 38% 92%, rgba(241,229,199,0.40), transparent 60%);
}
.night-stars-b {
  background-image:
    radial-gradient(1.5px 1.5px at 22% 38%, rgba(212,175,111,0.55), transparent 65%),
    radial-gradient(2px 2px at 70% 18%, rgba(212,175,111,0.45), transparent 65%),
    radial-gradient(2px 2px at 52% 80%, rgba(217,120,98,0.40), transparent 65%),
    radial-gradient(1.5px 1.5px at 88% 58%, rgba(212,175,111,0.40), transparent 65%);
  animation: twinkle 8s ease-in-out infinite alternate;
}
@keyframes twinkle {
  0%   { opacity: 0.85; }
  50%  { opacity: 0.55; }
  100% { opacity: 0.95; }
}

/* SVG-noise grain overlay, very subtle */
.night-grain {
  position: absolute;
  inset: 0;
  opacity: 0.06;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.9 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  background-size: 160px 160px;
}

/* ---------- Sheet (full viewport) ----------------------------------- */

.sheet {
  position: relative;
  z-index: 1;
  max-width: 980px;
  margin: 0 auto;
  /* Honor iOS notch / home-indicator safe areas when installed as a PWA.
     env() returns 0 if unsupported, so this is harmless elsewhere. */
  padding-top:    calc(18px + env(safe-area-inset-top, 0px));
  padding-right:  calc(var(--pad-x) + env(safe-area-inset-right, 0px));
  padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  padding-left:   calc(var(--pad-x) + env(safe-area-inset-left, 0px));
  height: 100svh;
  display: grid;
  grid-template-rows:
    auto         /* masthead */
    auto         /* rule */
    auto         /* spec */
    auto         /* rule */
    minmax(0, 1fr)  /* stage */
    auto;        /* dock */
  gap: 12px;
}

@media (min-width: 720px) {
  :root { --pad-x: 56px; }
  .sheet {
    padding-top:    calc(30px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px));
    gap: 16px;
  }
}

/* ---------- Masthead ------------------------------------------------- */

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--gold);
  text-decoration: none;
}
.brand-mark {
  width: 30px;
  height: 30px;
  display: block;
  flex: 0 0 auto;
  filter: drop-shadow(0 1px 0 rgba(0,0,0,0.4));
}
.brand-word {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  font-family: var(--serif);
  font-style: italic;
  font-variation-settings: "opsz" 60, "wght" 500, "SOFT" 60;
  font-size: 18px;
  letter-spacing: 0.005em;
  color: var(--cream);
}
.brand-word em { font-style: italic; }
.brand-orn {
  font-style: normal;
  color: var(--gold);
  font-size: 0.7em;
  transform: translateY(-0.1em);
  display: inline-block;
}

@media (min-width: 720px) {
  .brand-word { font-size: 20px; }
  .brand-mark { width: 36px; height: 36px; }
}

.masthead-meta {
  font-family: var(--serif-2);
  font-style: italic;
  font-size: 14px;
  color: var(--ink-soft);
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.meta-pair { display: inline-flex; gap: 6px; align-items: baseline; }
.meta-pair em { font-style: italic; opacity: 0.7; }
.meta-pair span {
  font-family: var(--serif);
  font-style: normal;
  font-variation-settings: "opsz" 36, "wght" 600, "SOFT" 30;
  color: var(--gold);
  font-size: 18px;
  letter-spacing: 0.02em;
}

/* ---------- Ornamental rules (gold hairline + center diamond) ------- */

hr.rule {
  border: 0;
  margin: 0;
  width: 100%;
  height: 14px;
  background:
    /* the diamond */
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='28' height='14' viewBox='0 0 28 14'><g fill='%23D4AF6F'><path d='M14 2 L20 7 L14 12 L8 7 Z' opacity='0.95'/><circle cx='14' cy='7' r='1.2' fill='%230F1B33'/></g></svg>") center / auto 14px no-repeat,
    /* the line */
    linear-gradient(to right, transparent 0%, var(--rule) 18%, var(--rule) 82%, transparent 100%) center / 100% 1px no-repeat;
  transform-origin: left;
  position: relative;
}
hr.rule-cream {
  background:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='28' height='14' viewBox='0 0 28 14'><g fill='%23B89058'><path d='M14 2 L20 7 L14 12 L8 7 Z'/><circle cx='14' cy='7' r='1.2' fill='%23F1E5C7'/></g></svg>") center / auto 14px no-repeat,
    linear-gradient(to right, transparent 0%, rgba(184,144,88,0.55) 18%, rgba(184,144,88,0.55) 82%, transparent 100%) center / 100% 1px no-repeat;
}

/* ---------- Spec line ----------------------------------------------- */

.spec {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-family: var(--serif-2);
  font-style: italic;
  font-size: 14px;
  color: var(--ink-soft);
  gap: 16px;
}
.spec em { color: var(--cream); font-style: italic; }
.spec .spec-mid { color: var(--ink-faint); font-style: italic; }
.spec .status { display: inline-flex; align-items: center; gap: 8px; color: var(--cream); }
.spec .dot {
  width: 7px; height: 7px;
  background: var(--gold);
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 10px rgba(212,175,111,0.7);
  transition: background 240ms var(--ease), box-shadow 240ms var(--ease);
}
.spec .dot.offline { background: var(--coral); box-shadow: 0 0 8px rgba(217,120,98,0.5); }

/* ---------- Stage --------------------------------------------------- */

.stage {
  position: relative;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 6px;
}

.stage-top { position: relative; min-height: 0; }

.labels {
  font-family: var(--serif-2);
  font-style: italic;
  font-size: 13px;
  color: var(--ink-soft);
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}
.label-key i {
  font-style: normal;
  margin: 0 6px;
  color: var(--accent);
}

.phrase {
  display: block;
  position: relative;
  line-height: 0.95;
  font-family: var(--serif);
  font-size: clamp(54px, 16vw, 132px);
  letter-spacing: -0.02em;
  text-shadow: 0 1px 0 rgba(0,0,0,0.35), 0 0 60px rgba(212,175,111,0.18);
}
.phrase-line { display: block; word-break: break-word; hyphens: manual; }
.phrase-activity {
  font-style: italic;
  font-variation-settings: "opsz" 144, "wght" 700, "SOFT" 60, "WONK" 1;
  color: var(--cream);
  margin-bottom: 0.04em;
}
.phrase-region {
  font-style: normal;
  font-variation-settings: "opsz" 144, "wght" 350, "SOFT" 90, "WONK" 0;
  color: var(--gold);
  letter-spacing: -0.025em;
}
.phrase-region.is-general {
  font-variation-settings: "opsz" 96, "wght" 380, "SOFT" 100, "WONK" 1;
  font-style: italic;
  font-size: 0.6em;
  color: var(--cream-deep);
  letter-spacing: 0;
  margin-top: 0.08em;
}

/* idle (pre-game) state — quieter, smaller */
[data-session="idle"] .phrase {
  font-size: clamp(34px, 11vw, 78px);
}
[data-session="idle"] .phrase-activity {
  font-variation-settings: "opsz" 72, "wght" 500, "SOFT" 100, "WONK" 0;
  color: var(--ink-soft);
}
[data-session="idle"] .phrase-region {
  font-variation-settings: "opsz" 72, "wght" 350, "SOFT" 100, "WONK" 0;
  color: var(--ink-faint);
  font-style: italic;
}
[data-session="idle"] .accent { display: none; }
[data-session="idle"] .history-stack { display: none; }

/* ---------- Accent ornament (rotates per generation) ---------------- */

.accent {
  position: absolute;
  right: -8px;
  top: 14%;
  width: clamp(54px, 13vw, 104px);
  height: clamp(54px, 13vw, 104px);
  display: grid;
  place-items: center;
  color: var(--accent);
  pointer-events: none;
  filter: drop-shadow(0 0 16px rgba(212,175,111,0.25));
}
.accent svg { width: 100%; height: 100%; display: block; }
@media (min-width: 720px) {
  .accent { right: calc(var(--pad-x) * -0.4); top: 8%; }
}

/* ---------- History stack (3D recede, readable) --------------------- */

.history-stack {
  list-style: none;
  margin: 0;
  padding: 12px 0 0;
  min-height: 0;
  perspective: 1300px;
  perspective-origin: 50% 0%;
  transform-style: preserve-3d;
  pointer-events: none;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.history-item {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 16px;
  align-items: baseline;
  padding: 6px 0 8px;
  border-top: 1px solid var(--rule-soft);
  font-family: var(--serif);
  font-size: clamp(22px, 6vw, 30px);
  line-height: 1.05;
  letter-spacing: -0.015em;
  color: var(--cream);
  overflow-wrap: break-word;
  transform-origin: 50% 0%;
  transition:
    transform 540ms var(--ease-out),
    opacity   540ms var(--ease-out),
    filter    540ms var(--ease-out);
  will-change: transform, opacity;
}

/* Per-depth recede: each item flows naturally below the previous one
   (so wrapping/different heights don't overlap) and steps back on Z. */
.history-item[data-depth="0"] {
  transform: translateZ(0);
  opacity: 0.75;
}
.history-item[data-depth="1"] {
  transform: translateZ(-110px);
  opacity: 0.50;
}
.history-item[data-depth="2"] {
  transform: translateZ(-220px);
  opacity: 0.32;
  filter: blur(0.4px);
}
.history-item[data-depth="3"] {
  transform: translateZ(-330px);
  opacity: 0.18;
  filter: blur(0.7px);
}
.history-item[data-depth="4"] {
  transform: translateZ(-440px);
  opacity: 0.10;
  filter: blur(1px);
}
.history-item[data-depth="5"],
.history-item[data-depth="6"],
.history-item[data-depth="7"],
.history-item[data-depth="8"],
.history-item[data-depth="9"] { display: none; }

.history-item .h-num {
  font-family: var(--serif);
  font-style: italic;
  font-variation-settings: "opsz" 24, "wght" 500, "SOFT" 100;
  font-size: 14px;
  color: var(--gold);
  padding-top: 0.55em;
  letter-spacing: 0.02em;
  text-align: right;
  border-right: 1px solid var(--rule-soft);
  padding-right: 10px;
  height: 100%;
}
.history-item .h-phrase { font-family: var(--serif); }
.history-item .h-activity {
  font-style: italic;
  font-variation-settings: "opsz" 60, "wght" 700, "SOFT" 60;
  color: var(--cream);
}
.history-item .h-region {
  font-style: normal;
  font-variation-settings: "opsz" 60, "wght" 380, "SOFT" 90;
  color: var(--gold);
  margin-left: 0.3em;
}
.history-item .h-region.is-general {
  font-style: italic;
  font-variation-settings: "opsz" 36, "wght" 400, "SOFT" 100, "WONK" 1;
  color: var(--cream-deep);
}

/* Entrance: new top item flies forward then settles. */
@keyframes recedeIn {
  0%   { opacity: 0; transform: translateZ(260px) translateY(-40px); }
  60%  { opacity: 0.95; }
  100% { opacity: 0.75; transform: translateZ(0) translateY(0); }
}
.history-item.entering { animation: recedeIn 560ms var(--ease-out) both; }

/* ---------- Dock ---------------------------------------------------- */

.dock {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sub-actions {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  gap: 10px;
}
.sub-actions:empty { display: none; }
.sub-actions > li { flex: 1; display: flex; }
.sub-actions > li > * { flex: 1; }

/* ---------- Generate button (cream filled, gold border) ------------- */

.generate {
  appearance: none;
  border: 1px solid var(--gold);
  background: var(--cream);
  color: var(--midnight-deep);
  width: 100%;
  padding: 18px 22px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  font-family: var(--serif);
  font-style: italic;
  font-variation-settings: "opsz" 60, "wght" 600, "SOFT" 60;
  font-size: 19px;
  letter-spacing: 0.005em;
  text-align: left;
  transition: transform 120ms var(--ease), background 220ms var(--ease), color 220ms var(--ease);
  position: relative;
  overflow: hidden;
  box-shadow:
    0 1px 0 rgba(241,229,199,0.18) inset,
    0 18px 38px -18px rgba(0,0,0,0.6),
    0 0 0 4px rgba(15,27,51,0.6),
    0 0 0 5px rgba(212,175,111,0.30);
}
.generate::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, var(--gold) 0%, var(--gold-deep) 100%);
  transform: translateY(101%);
  transition: transform 420ms var(--ease);
  z-index: 0;
}
.generate > * { position: relative; z-index: 1; }
.generate:hover::before,
.generate:focus-visible::before { transform: translateY(0); }
.generate:hover { color: var(--midnight-deep); }
.generate:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 4px;
}
.generate:active { transform: translateY(1px); }

.gen-arrow {
  width: 22px; height: 22px;
  display: grid; place-items: center;
  color: var(--midnight-deep);
  transition: transform 360ms var(--ease);
}
.gen-arrow svg { width: 100%; height: 100%; }
.generate:hover .gen-arrow { transform: rotate(45deg); }

.gen-label {
  font-family: var(--serif);
  font-style: italic;
  font-variation-settings: "opsz" 60, "wght" 600, "SOFT" 60;
}
.gen-tag {
  font-family: var(--serif-2);
  font-style: italic;
  font-size: 13px;
  color: rgba(15,27,51,0.55);
  letter-spacing: 0.04em;
}

@media (min-width: 720px) {
  .generate { padding: 22px 28px; font-size: 22px; }
}

/* ---------- Ghost buttons (Restart / Log) --------------------------- */

.ghost-btn {
  appearance: none;
  background: transparent;
  border: 1px solid rgba(212,175,111,0.40);
  color: var(--cream);
  padding: 11px 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  font-family: var(--serif-2);
  font-style: italic;
  font-size: 14px;
  letter-spacing: 0.02em;
  font-weight: 500;
  transition: background 220ms var(--ease), color 220ms var(--ease), border-color 220ms var(--ease);
}
.ghost-btn em { font-style: italic; }
.ghost-btn[hidden] { display: none; }
.ghost-btn:hover { background: rgba(241,229,199,0.06); border-color: var(--gold); color: var(--cream); }
.ghost-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
.ghost-btn .g-icon { width: 14px; height: 14px; display: inline-grid; place-items: center; color: var(--gold); }
.ghost-btn .g-icon svg { width: 100%; height: 100%; }
.ghost-btn .g-count {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 18px;
  padding: 0 6px;
  background: var(--gold);
  color: var(--midnight-deep);
  font-style: normal;
  font-variation-settings: "wght" 700;
  font-family: var(--serif);
  margin-left: 4px;
  border-radius: 1px;
}

/* =====================================================================
   Session log dialog (native <dialog>) — the cream "page"
   ===================================================================== */

dialog.modal {
  border: 0;
  padding: 0;
  margin: 0;
  background: var(--cream);
  color: var(--midnight-deep);
  width: 100vw;
  max-width: 100vw;
  height: 100svh;
  max-height: 100svh;
  inset: 0;
  overflow: hidden;
}
dialog.modal::backdrop {
  background: rgba(7, 13, 28, 0.72);
  backdrop-filter: blur(3px);
  animation: fadeIn 220ms var(--ease) both;
}
dialog.modal[open] { animation: pageOpen 420ms var(--ease-out) both; }

@keyframes pageOpen {
  from { opacity: 0; transform: translateY(28px) scale(0.985); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-card {
  position: relative;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(800px 400px at 50% -10%, rgba(212,175,111,0.15), transparent 70%),
    var(--cream);
}

/* Decorative ornamental corners on the modal card */
.modal-corners { position: absolute; inset: 12px; pointer-events: none; }
.modal-corners span {
  position: absolute;
  width: 22px; height: 22px;
  border: 1px solid var(--gold);
}
.modal-corners span:nth-child(1) { top: 0;    left: 0;    border-right: 0; border-bottom: 0; }
.modal-corners span:nth-child(2) { top: 0;    right: 0;   border-left: 0;  border-bottom: 0; }
.modal-corners span:nth-child(3) { bottom: 0; left: 0;    border-right: 0; border-top: 0; }
.modal-corners span:nth-child(4) { bottom: 0; right: 0;   border-left: 0;  border-top: 0; }

@media (min-width: 720px) {
  dialog.modal {
    width: min(720px, calc(100vw - 48px));
    height: min(82svh, 720px);
    margin: auto;
    inset: 0;
    border: 1px solid var(--gold-deep);
    box-shadow:
      0 30px 60px -20px rgba(0,0,0,0.6),
      0 0 0 4px var(--midnight-deep),
      0 0 0 5px rgba(212,175,111,0.30);
  }
}

.modal-head {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: end;
  gap: 16px;
  padding:
    calc(28px + env(safe-area-inset-top, 0px))
    calc(var(--pad-x) + env(safe-area-inset-right, 0px))
    16px
    calc(var(--pad-x) + env(safe-area-inset-left, 0px));
}
.modal-head hgroup { margin: 0; }
.modal-eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--serif-2);
  font-style: italic;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: lowercase;
  color: var(--gold-deep);
  margin: 0 0 8px;
}
.modal-eyebrow i { font-style: normal; color: var(--gold); }
.modal-title {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-variation-settings: "opsz" 96, "wght" 600, "SOFT" 60, "WONK" 1;
  font-size: clamp(30px, 7.5vw, 48px);
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--midnight-deep);
}
.modal-meta {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  margin: 0;
  font-family: var(--serif-2);
  font-style: italic;
  font-size: 13px;
  color: var(--gold-deep);
}
.modal-meta #modalCount {
  font-family: var(--serif);
  font-style: normal;
  font-size: 28px;
  font-variation-settings: "opsz" 36, "wght" 700, "SOFT" 30;
  color: var(--coral);
  line-height: 1;
}
.modal-meta-sub em { color: var(--gold-deep); font-style: italic; }

.modal-close-form { margin: 0; }
.modal-close {
  appearance: none;
  background: var(--midnight-deep);
  color: var(--cream);
  border: 1px solid var(--midnight-deep);
  width: 40px; height: 40px;
  display: grid; place-items: center;
  cursor: pointer;
  transition: background 200ms var(--ease), transform 200ms var(--ease);
}
.modal-close:hover { background: var(--coral); transform: rotate(90deg); }
.modal-close svg { width: 16px; height: 16px; }
.modal-close:focus-visible {
  outline: 2px solid var(--coral);
  outline-offset: 3px;
}

.modal-list {
  list-style: none;
  margin: 0;
  padding: 4px var(--pad-x) 8px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--gold-deep) transparent;
}
.modal-item {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 16px;
  align-items: baseline;
  padding: 16px 0;
  border-bottom: 1px solid rgba(184,144,88,0.25);
  animation: riseIn 320ms var(--ease-out) both;
}
.modal-item:last-child { border-bottom: 0; }
.modal-item.is-current {
  background: linear-gradient(90deg, rgba(217,120,98,0.10), transparent 70%);
  padding-left: 12px;
  margin-left: -12px;
  padding-right: 12px;
  margin-right: -12px;
  border-bottom: 1px solid rgba(217,120,98,0.30);
}
.modal-item .m-num {
  font-family: var(--serif);
  font-style: italic;
  font-variation-settings: "opsz" 36, "wght" 600, "SOFT" 60, "WONK" 1;
  font-size: 22px;
  color: var(--gold-deep);
  padding-top: 0.2em;
  text-align: right;
  border-right: 1px solid rgba(184,144,88,0.30);
  padding-right: 12px;
  height: 100%;
}
.modal-item.is-current .m-num { color: var(--coral); }
.modal-item .m-phrase {
  font-family: var(--serif);
  font-size: clamp(22px, 5.4vw, 34px);
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: var(--midnight-deep);
}
.modal-item .m-activity {
  font-style: italic;
  font-variation-settings: "opsz" 72, "wght" 700, "SOFT" 60;
}
.modal-item .m-region {
  font-style: normal;
  font-variation-settings: "opsz" 72, "wght" 400, "SOFT" 90;
  color: var(--gold-deep);
  margin-left: 0.3em;
}
.modal-item .m-region.is-general {
  font-style: italic;
  font-variation-settings: "opsz" 48, "wght" 400, "SOFT" 100, "WONK" 1;
  color: var(--gold-deep);
}
.modal-item .m-tag {
  font-family: var(--serif-2);
  font-style: italic;
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--gold-deep);
  padding-top: 0.7em;
}
.modal-item.is-current .m-tag { color: var(--coral); }

.modal-foot {
  padding:
    12px
    calc(var(--pad-x) + env(safe-area-inset-right, 0px))
    calc(24px + env(safe-area-inset-bottom, 0px))
    calc(var(--pad-x) + env(safe-area-inset-left, 0px));
  text-align: center;
  font-family: var(--serif-2);
  font-style: italic;
  font-size: 12px;
  color: var(--gold-deep);
  border-top: 1px solid rgba(184,144,88,0.20);
}

/* ---------- Confirm dialog (smaller, centered) ---------------------- */

dialog.modal-confirm {
  width: min(440px, calc(100vw - 32px));
  height: auto;
  max-height: calc(100svh - 32px);
  margin: auto;
  inset: 0;
  border: 1px solid var(--gold-deep);
  box-shadow:
    0 30px 60px -20px rgba(0,0,0,0.7),
    0 0 0 4px var(--midnight-deep),
    0 0 0 5px rgba(212,175,111,0.30);
}
dialog.modal-confirm .modal-card {
  grid-template-rows: auto auto auto;
  height: auto;
  background:
    radial-gradient(600px 240px at 50% -10%, rgba(217,120,98,0.20), transparent 70%),
    var(--cream);
}
.modal-head-compact {
  grid-template-columns: 1fr;
  padding: 28px var(--pad-x) 12px;
}
.confirm-body {
  margin: 0;
  padding: 14px var(--pad-x) 20px;
  font-family: var(--serif-2);
  font-size: 16px;
  line-height: 1.4;
  color: var(--midnight-deep);
}
.confirm-body em { font-style: italic; }

.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 4px var(--pad-x) 24px;
  margin: 0;
}
.confirm-actions > button {
  font-family: var(--serif);
  font-style: italic;
  font-size: 16px;
  padding: 14px 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: background 220ms var(--ease), color 220ms var(--ease), border-color 220ms var(--ease), transform 120ms var(--ease);
}
.confirm-actions > button:active { transform: translateY(1px); }
.confirm-actions > button em { font-style: italic; }

/* Cancel: bordered, calm */
.confirm-cancel {
  background: transparent;
  border: 1px solid rgba(15,27,51,0.30);
  color: var(--midnight-deep);
  font-variation-settings: "opsz" 36, "wght" 500, "SOFT" 60;
}
.confirm-cancel:hover {
  background: rgba(15,27,51,0.06);
  border-color: var(--midnight-deep);
}
.confirm-cancel:focus-visible {
  outline: 2px solid var(--midnight-deep);
  outline-offset: 3px;
}

/* Confirm: coral fill — destructive accent */
.confirm-go {
  appearance: none;
  background: var(--coral);
  border: 1px solid var(--coral);
  color: var(--cream);
  font-variation-settings: "opsz" 36, "wght" 600, "SOFT" 60;
  position: relative;
  overflow: hidden;
}
.confirm-go::before {
  content: "";
  position: absolute;
  inset: 0;
  background: #b85e4d;
  transform: translateY(101%);
  transition: transform 320ms var(--ease);
}
.confirm-go > * { position: relative; z-index: 1; }
.confirm-go:hover::before,
.confirm-go:focus-visible::before { transform: translateY(0); }
.confirm-go:focus-visible {
  outline: 2px solid var(--coral);
  outline-offset: 3px;
}
.confirm-go .g-icon { width: 14px; height: 14px; color: var(--cream); display: inline-grid; place-items: center; }
.confirm-go .g-icon svg { width: 100%; height: 100%; }

/* =====================================================================
   Animations
   ===================================================================== */

@keyframes ruleDraw {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}
@keyframes riseIn {
  from { opacity: 0; transform: translateY(28px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes shapeIn {
  from { opacity: 0; transform: rotate(-18deg) scale(0.55); }
  to   { opacity: 1; transform: rotate(0deg) scale(1); }
}
@keyframes counterTick {
  0%   { transform: translateY(0); }
  40%  { transform: translateY(-100%); opacity: 0; }
  41%  { transform: translateY(100%); }
  100% { transform: translateY(0); opacity: 1; }
}

/* Page-load reveal */
.sheet > * {
  opacity: 0;
  animation: riseIn 700ms var(--ease-out) forwards;
}
.sheet > .masthead { animation-delay: 80ms; }
.sheet > .spec     { animation-delay: 220ms; }
.sheet > .stage    { animation-delay: 360ms; }
.sheet > .dock     { animation-delay: 520ms; }
.sheet > hr.rule   { animation-name: ruleDraw; transform-origin: left; }
.sheet > hr.rule:nth-of-type(1) { animation-delay: 150ms; }
.sheet > hr.rule:nth-of-type(2) { animation-delay: 290ms; }

/* Reveal cycle on each generate click */
.stage.cycle .labels         { animation: fadeIn 360ms var(--ease) both; animation-delay: 80ms; }
.stage.cycle .phrase-activity { animation: riseIn 540ms var(--ease-out) both; animation-delay: 160ms; }
.stage.cycle .phrase-region   { animation: riseIn 540ms var(--ease-out) both; animation-delay: 280ms; }
.stage.cycle .accent          { animation: shapeIn 600ms var(--ease-out) both; animation-delay: 420ms; }

#counter.tick { display: inline-block; animation: counterTick 420ms var(--ease) both; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.001ms !important;
  }
  .sheet > * { opacity: 1; }
  .history-item { transition: none; }
  .night-stars-b { animation: none; }
}

/* Selection */
::selection { background: var(--gold); color: var(--midnight-deep); }
