:root {
  --bg: #0b0a09;
  --bg-deep: #060505;
  --bg-lift: #1a1511;
  --gold: #d9b46a;
  --gold-bright: #ecd29a;
  --gold-soft: rgba(217, 180, 106, 0.55);
  --gold-faint: rgba(217, 180, 106, 0.16);
  --ink: #ece2cf;
  --ink-soft: rgba(236, 226, 207, 0.72);
  --dim: #8f836e;
  --line: rgba(217, 180, 106, 0.2);
  --panel: rgba(17, 14, 11, 0.84);
  --serif-latin: "Cormorant Garamond", "Gowun Batang", Georgia, serif;
  --serif-ko: "Gowun Batang", "Cormorant Garamond", serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --ease: cubic-bezier(.22, .7, .2, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* No fades while the page first takes its state. */
body.preload, body.preload * { transition: none !important; animation: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background:
    radial-gradient(ellipse 70% 60% at 50% 46%, var(--bg-lift) 0%, var(--bg) 58%, var(--bg-deep) 100%);
  color: var(--ink);
  font-family: var(--serif-ko);
  -webkit-font-smoothing: antialiased;
}

canvas#vessel {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}
button:focus-visible, textarea:focus-visible {
  outline: 1px solid var(--gold);
  outline-offset: 3px;
}

/* ---------- top ---------- */

.top {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 22px 28px;
  z-index: 3;
}
.brand { display: flex; align-items: baseline; gap: 14px; }
.brand-name {
  font-family: var(--serif-latin);
  font-weight: 500;
  font-size: 15px;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: var(--gold);
}
html[lang="en"] .top-actions { display: flex; gap: 22px; }

.link {
  font-family: var(--serif-latin);
  font-size: 15px;
  color: var(--dim);
  letter-spacing: 0.06em;
  padding: 4px 0;
  border-bottom: 1px solid transparent;
  transition: color .3s, border-color .3s;
}
html[lang="ko"] .link { font-family: var(--serif-ko); font-size: 14px; }
.link:hover { color: var(--gold); border-color: var(--gold-faint); }

/* ---------- buttons ---------- */

.btn {
  font-family: var(--serif-ko);
  font-size: 14px;
  letter-spacing: 0.04em;
  padding: 10px 22px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-soft);
  transition: border-color .3s, color .3s, background .3s;
}
html[lang="en"] .btn { font-family: var(--serif-latin); font-size: 16px; }
.btn:hover:not(:disabled) { border-color: var(--gold-soft); color: var(--gold-bright); }
.btn.primary {
  border-color: var(--gold-soft);
  color: var(--gold-bright);
  background: rgba(217, 180, 106, 0.07);
}
.btn.primary:hover:not(:disabled) { background: rgba(217, 180, 106, 0.14); }
.btn.quiet { border-color: transparent; color: var(--dim); }
.btn:disabled { opacity: .35; cursor: default; }

/* ---------- empty note (centred on the vessel) ---------- */

.center-note {
  position: fixed;
  left: var(--cx, 50%);
  top: var(--cy, 50%);
  transform: translate(-50%, -50%);
  width: min(calc(var(--r, 240px) * 1.15), 86vw);
  text-align: center;
  z-index: 2;
  transition: opacity .8s var(--ease);
}
.note-title {
  margin: 0 0 10px;
  font-size: clamp(19px, 2.2vw, 24px);
  letter-spacing: 0.06em;
  color: var(--ink);
}
html[lang="en"] .note-title { font-family: var(--serif-latin); font-size: clamp(24px, 2.6vw, 30px); font-weight: 400; }
.note-hint {
  margin: 0 auto 26px;
  max-width: 22em;
  font-size: 14px;
  line-height: 1.7;
  color: var(--dim);
}
html[lang="en"] .note-hint { font-family: var(--serif-latin); font-size: 17px; font-style: italic; }

body:not([data-mode="empty"]) .center-note,
body.sheet-open .center-note { opacity: 0; pointer-events: none; }

/* ---------- dashboard ---------- */

.dash {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  padding: 0 28px 26px;
  display: grid;
  justify-items: center;
  gap: 14px;
  z-index: 2;
  transition: opacity .8s var(--ease), transform .8s var(--ease);
}
body:not([data-mode="sealed"]) .dash { opacity: 0; pointer-events: none; transform: translateY(12px); }
body.sheet-open .dash { opacity: 0; pointer-events: none; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(92px, auto));
  gap: 0;
}
.stat {
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 0 26px;
  border-left: 1px solid var(--line);
}
.stat:first-child { border-left: 0; }
.stat-label {
  font-size: 12px;
  color: var(--dim);
  letter-spacing: 0.14em;
}
html[lang="en"] .stat-label { font-family: var(--serif-latin); text-transform: uppercase; font-size: 11px; letter-spacing: 0.24em; }
.stat-value {
  font-family: var(--serif-latin);
  font-size: 30px;
  font-weight: 500;
  line-height: 1.1;
  color: var(--ink);
  font-variant-numeric: lining-nums tabular-nums;
  letter-spacing: 0.02em;
}
#stat-days { font-family: var(--serif-ko); font-size: 22px; padding-top: 4px; font-weight: 400; white-space: nowrap; }
html[lang="en"] #stat-days { font-family: var(--serif-latin); font-size: 30px; padding-top: 0; font-weight: 500; }

.status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--dim);
  letter-spacing: 0.04em;
}
html[lang="en"] .status { font-family: var(--serif-latin); font-style: italic; font-size: 16px; }
.pulse {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--dim);
  transition: background .4s, box-shadow .4s;
}
body[data-turning="yes"] .pulse {
  background: var(--gold);
  box-shadow: 0 0 10px rgba(217, 180, 106, .6);
  animation: breathe 3.2s ease-in-out infinite;
}
.pulse.beat { box-shadow: 0 0 18px 3px rgba(236, 210, 154, .85) !important; }
@keyframes breathe { 50% { opacity: .45; } }

.dash-actions { display: flex; align-items: center; gap: 12px; }
.dash-actions .link { margin-left: 8px; }

/* ---------- workings ---------- */

.works {
  position: fixed;
  left: 28px;
  bottom: 28px;
  width: min(380px, calc(100vw - 56px));
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 3;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.7;
  color: var(--ink-soft);
}
.works-band {
  white-space: nowrap;
  overflow: hidden;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--line);
  font-family: var(--serif-ko);
  font-size: 14px;
  color: var(--dim);
}
.works-band .head { color: var(--gold-bright); }
.works-band .mouth { display: block; font-family: var(--mono); font-size: 11px; color: var(--gold); margin-top: 2px; }
.works-lines { list-style: none; margin: 0; padding: 0; }

/* ---------- sheet ---------- */

.sheet {
  position: fixed;
  top: 84px;
  right: 32px;
  max-height: calc(100vh - 116px);
  width: 400px;
  overflow-y: auto;
  padding: 30px 30px 26px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .45);
  z-index: 4;
  animation: sheet-in .6s var(--ease);
}
@keyframes sheet-in { from { opacity: 0; transform: translateY(10px); } }

.step h2 {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 400;
  letter-spacing: 0.08em;
  color: var(--gold-bright);
}
html[lang="en"] .step h2 { font-family: var(--serif-latin); font-size: 26px; font-weight: 500; letter-spacing: 0.02em; }
.hint {
  margin: 0 0 18px;
  font-size: 13.5px;
  line-height: 1.75;
  color: var(--dim);
}
html[lang="en"] .hint { font-family: var(--serif-latin); font-size: 16.5px; }

textarea {
  width: 100%;
  resize: none;
  padding: 10px 2px 12px;
  margin-bottom: 10px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font-family: var(--serif-ko);
  font-size: 18px;
  line-height: 1.7;
  transition: border-color .3s;
}
textarea::placeholder { color: rgba(143, 131, 110, .6); }
textarea:focus { outline: none; border-color: var(--gold-soft); }

.trace-info {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  min-height: 1.6em;
  font-size: 12.5px;
  color: var(--dim);
}
#trace-count { color: var(--gold); }

.row { display: flex; gap: 10px; margin-top: 18px; align-items: center; }
.row.end { justify-content: flex-end; margin-top: 28px; }
.choice { display: grid; gap: 12px; margin-top: 10px; }
.choice .btn { padding: 14px 22px; font-size: 15px; }

.say-label {
  margin: 22px 0 8px;
  font-size: 11.5px;
  letter-spacing: 0.18em;
  color: var(--dim);
}
html[lang="en"] .say-label { font-family: var(--serif-latin); text-transform: uppercase; font-size: 11px; letter-spacing: 0.26em; }
.step > .say-label:first-child { margin-top: 0; }
.say {
  margin: 0 0 18px;
  padding: 4px 0 4px 18px;
  border-left: 1px solid var(--gold-soft);
  font-size: 18px;
  line-height: 1.95;
  color: var(--ink);
  white-space: pre-line;
}
html[lang="en"] .say { font-family: var(--serif-latin); font-size: 21px; line-height: 1.6; }
.revealed {
  margin: 0 0 26px;
  font-size: 18px;
  line-height: 1.75;
  color: var(--gold-bright);
}

.hold {
  position: relative;
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 16px 20px;
  overflow: hidden;
  border: 1px solid var(--gold-soft);
  border-radius: 999px;
  color: var(--gold-bright);
  font-size: 15px;
  letter-spacing: 0.1em;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
html[lang="en"] .hold { font-family: var(--serif-latin); font-size: 17px; letter-spacing: 0.06em; }
.hold-fill {
  position: absolute;
  inset: 0;
  transform-origin: left center;
  transform: scaleX(var(--p, 0));
  background: linear-gradient(90deg, rgba(217, 180, 106, .10), rgba(217, 180, 106, .30));
}
.hold-text { position: relative; }

/* ---------- archive ---------- */

.archive { list-style: none; margin: 18px 0 0; padding: 0; }
.archive li {
  padding: 18px 0;
  border-top: 1px solid var(--line);
}
.archive .meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-family: var(--serif-latin);
  font-size: 14px;
  color: var(--dim);
  font-variant-numeric: lining-nums;
}
.archive .tag { color: var(--gold); }
.archive .petition { margin: 8px 0 4px; font-size: 16px; line-height: 1.7; color: var(--ink); }
.archive .thanks { margin: 4px 0; font-size: 14px; line-height: 1.7; color: var(--ink-soft); }
.archive .thanks::before { content: "— "; color: var(--gold-soft); }
.archive .counts { font-family: var(--serif-latin); font-size: 14px; color: var(--dim); font-variant-numeric: lining-nums; }
.archive .none { color: var(--dim); border: 0; }

/* ---------- narrow screens ---------- */

@media (max-width: 899px) {
  .top { padding: 16px 18px; }
  .brand { flex-direction: column; gap: 2px; }
  .sheet {
    top: auto;
    left: 0; right: 0; bottom: 0;
    width: auto;
    max-height: 64vh;
    border-radius: 20px 20px 0 0;
    border-bottom: 0;
    padding: 24px 20px calc(22px + env(safe-area-inset-bottom));
  }
  .dash { padding: 0 16px calc(18px + env(safe-area-inset-bottom)); gap: 12px; }
  .stats { grid-template-columns: repeat(4, auto); }
  .stat { padding: 0 12px; }
  .stat-value { font-size: 23px; }
  #stat-days { font-size: 16px; padding-top: 3px; }
  html[lang="en"] #stat-days { font-size: 23px; }
  .works { left: 16px; bottom: 16px; }
}

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