/* ── lateroom character studio — nocturnal single-theme design ─────────────────
   A warm, candlelit dark room. Editorial serif for names and headlines; a clean
   system sans for the working UI. One accent that runs amber → blush.            */

:root {
  --room: #0f0b0e;
  --ground: #151013;
  --card: #1c1519;
  --card-2: #221a1f;
  --line: rgba(255, 255, 255, 0.09);
  --line-2: rgba(255, 255, 255, 0.14);
  --ink: #f4ece8;
  --soft: #d8c9c0;
  --muted: #a7968c;
  --faint: #7d6f68;
  --amber: #eaa36b;
  --blush: #e0648b;
  --ready: #8fca9e;
  --warn: #e6b455;
  --danger: #e07a7a;
  --accent: linear-gradient(105deg, #f0ad74, #e0648b);
  --serif: "Hoefler Text", "Palatino Linotype", Palatino, Georgia, Cambria, "Noto Serif", "DejaVu Serif", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --radius: 16px;
  --shadow: 0 18px 50px -24px rgba(0, 0, 0, 0.75);
}

* { box-sizing: border-box; }

html { height: 100%; }

body {
  /* min-height (not height:100%) so the body box grows with the content — otherwise the themed
     background is clipped to a single viewport and a seam appears partway down a long, scrolled page. */
  min-height: 100vh;
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(120% 80% at 82% -8%, rgba(224, 100, 139, 0.10), transparent 60%),
    radial-gradient(90% 70% at 8% 0%, rgba(234, 163, 107, 0.10), transparent 55%),
    var(--room);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

a { color: inherit; }

button { font-family: inherit; }

.app { min-height: 100vh; }

.boot { color: var(--faint); text-align: center; padding: 28vh 1rem; letter-spacing: 0.02em; }

/* ── masthead ─────────────────────────────────────────────────────────────── */
.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem clamp(1rem, 4vw, 2.4rem);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(15, 11, 14, 0.82);
  backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: baseline; gap: 0.6rem; min-width: 0; }
.brand .mark { font-family: var(--serif); font-size: 1.32rem; letter-spacing: 0.01em; }
.brand .sub {
  font-size: 0.62rem; letter-spacing: 0.32em; text-transform: uppercase;
  color: var(--faint);
}
.masthead .who { display: flex; align-items: center; gap: 0.75rem; font-size: 0.85rem; }
.wallet {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.28rem 0.6rem; border: 1px solid var(--line); border-radius: 999px;
  color: var(--soft); font-variant-numeric: tabular-nums;
}
.wallet .spark { color: var(--amber); }
.role-pill {
  font-size: 0.6rem; letter-spacing: 0.18em; text-transform: uppercase;
  padding: 0.2rem 0.5rem; border-radius: 999px; border: 1px solid var(--line-2);
  color: var(--muted);
}
.role-pill.admin { color: #14100c; background: var(--accent); border-color: transparent; font-weight: 700; }

/* ── buttons ──────────────────────────────────────────────────────────────── */
.btn {
  appearance: none; border: 1px solid var(--line-2); background: transparent;
  color: var(--ink); padding: 0.6rem 1rem; border-radius: 11px; cursor: pointer;
  font-size: 0.9rem; transition: border-color 0.15s, background 0.15s, transform 0.05s;
}
.btn:hover { border-color: var(--soft); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary {
  border: 0; color: #17100c; font-weight: 700; background: var(--accent);
  box-shadow: 0 10px 30px -14px rgba(224, 100, 139, 0.7);
}
.btn.ghost { color: var(--soft); }
.btn.wide { width: 100%; }
.btn.small { padding: 0.42rem 0.7rem; font-size: 0.8rem; border-radius: 9px; }
.btn.link { border: 0; background: 0; color: var(--amber); padding: 0; cursor: pointer; }

/* ── auth ─────────────────────────────────────────────────────────────────── */
.auth-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 2rem 1rem;
}
.auth-card {
  width: min(410px, 94vw); background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 2rem 1.7rem; box-shadow: var(--shadow);
}
.auth-card .logo { font-family: var(--serif); font-size: 1.7rem; }
.auth-card .tagline { color: var(--muted); font-size: 0.9rem; margin: 0.3rem 0 1.4rem; }
.tabs { display: flex; gap: 0.4rem; margin-bottom: 1.2rem; }
.tab {
  flex: 1; text-align: center; padding: 0.5rem; border-radius: 10px; cursor: pointer;
  border: 1px solid transparent; color: var(--muted); font-size: 0.88rem;
}
.tab.on { color: var(--ink); border-color: var(--line-2); background: var(--card-2); }

.field { margin-bottom: 0.9rem; }
.field label {
  display: block; font-size: 0.7rem; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--faint); margin-bottom: 0.35rem;
}
.input, select.input, textarea.input {
  width: 100%; background: var(--ground); border: 1px solid var(--line-2); color: var(--ink);
  padding: 0.6rem 0.7rem; border-radius: 10px; font-size: 0.92rem; font-family: inherit;
}
textarea.input { resize: vertical; min-height: 74px; }
.input:focus, select.input:focus, textarea.input:focus {
  outline: none; border-color: var(--amber); box-shadow: 0 0 0 3px rgba(234, 163, 107, 0.16);
}
.hint { color: var(--faint); font-size: 0.78rem; margin-top: 0.5rem; }

.notice { padding: 0.6rem 0.75rem; border-radius: 10px; font-size: 0.85rem; margin-bottom: 0.9rem; }
.notice.err { background: rgba(224, 122, 122, 0.12); border: 1px solid rgba(224, 122, 122, 0.4); color: #f0b3b3; }
.notice.ok { background: rgba(143, 202, 158, 0.12); border: 1px solid rgba(143, 202, 158, 0.4); color: var(--ready); }

/* ── studio layout ───────────────────────────────────────────────────────── */
.studio { display: grid; grid-template-columns: 300px 1fr; gap: 0; align-items: start; }
.rail {
  border-right: 1px solid var(--line); padding: 1.3rem clamp(0.8rem, 1.5vw, 1.2rem);
  position: sticky; top: 64px; height: calc(100vh - 64px); overflow: auto;
}
.main { padding: clamp(1.2rem, 3vw, 2.2rem); min-width: 0; }

.rail h3 {
  font-size: 0.66rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--faint);
  margin: 1.4rem 0 0.6rem;
}
.rail h3:first-of-type { margin-top: 0.4rem; }

.rail-item {
  display: flex; align-items: center; gap: 0.7rem; width: 100%; text-align: left;
  padding: 0.5rem 0.6rem; border-radius: 10px; cursor: pointer; border: 1px solid transparent;
  background: transparent; color: var(--soft); margin-bottom: 0.2rem;
}
.rail-item:hover { background: var(--card); }
.rail-item.on { background: var(--card); border-color: var(--line); }
.rail-item .thumb { width: 30px; height: 30px; border-radius: 8px; flex: none; }
.rail-item .nm { font-size: 0.9rem; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-item .st { font-size: 0.72rem; color: var(--faint); }
.rail-item .col { min-width: 0; }

/* ── portraits ───────────────────────────────────────────────────────────── */
.portrait {
  position: relative; border-radius: 12px; overflow: hidden; background: var(--card-2);
  aspect-ratio: 1 / 1;
}
.portrait svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.portrait::after {
  content: ""; position: absolute; inset: 0;
  background:
    radial-gradient(60% 45% at 62% 30%, var(--rim, rgba(234, 163, 107, 0.5)), transparent 60%),
    radial-gradient(40% 30% at 40% 34%, var(--skl, rgba(255, 240, 232, 0.28)), transparent 55%),
    radial-gradient(120% 120% at 50% 120%, rgba(0, 0, 0, 0.55), transparent 55%);
  mix-blend-mode: screen;
}
.portrait.round { border-radius: 50%; }

/* ── character grid + cards ──────────────────────────────────────────────── */
.head-row { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 0.3rem; flex-wrap: wrap; }
.h-title { font-family: var(--serif); font-size: clamp(1.5rem, 3.5vw, 2rem); letter-spacing: 0.01em; }
.lede { color: var(--muted); max-width: 62ch; margin: 0 0 1.6rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 1rem; }
.ch-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.7rem; cursor: pointer; transition: border-color 0.15s, transform 0.08s;
}
.ch-card:hover { border-color: var(--line-2); transform: translateY(-2px); }
.ch-card .portrait { margin-bottom: 0.6rem; }
.ch-card .nm { font-family: var(--serif); font-size: 1.1rem; }
.ch-card .mt { font-size: 0.8rem; color: var(--muted); display: flex; align-items: center; gap: 0.4rem; margin-top: 0.15rem; }

.badge {
  display: inline-flex; align-items: center; gap: 0.32rem; font-size: 0.68rem; letter-spacing: 0.04em;
  padding: 0.16rem 0.46rem; border-radius: 999px; border: 1px solid var(--line-2); color: var(--muted);
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ready { color: var(--ready); border-color: rgba(143, 202, 158, 0.4); }
.badge.building { color: var(--amber); border-color: rgba(234, 163, 107, 0.4); }
.badge.held, .badge.unavailable { color: var(--danger); border-color: rgba(224, 122, 122, 0.4); }
.badge.draft { color: var(--faint); }
.badge.common { color: var(--blush); border-color: rgba(224, 100, 139, 0.4); }

.empty {
  border: 1px dashed var(--line-2); border-radius: var(--radius); padding: 2rem;
  text-align: center; color: var(--muted);
}

/* ── create form ─────────────────────────────────────────────────────────── */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(1.1rem, 2.4vw, 1.8rem); box-shadow: var(--shadow); }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.9rem 1rem; }
.form-grid .span2 { grid-column: 1 / -1; }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
  padding: 0.34rem 0.66rem; border-radius: 999px; border: 1px solid var(--line-2);
  color: var(--soft); cursor: pointer; font-size: 0.82rem; background: transparent;
}
.chip.on { background: var(--accent); color: #17100c; border-color: transparent; font-weight: 600; }
.form-actions { display: flex; align-items: center; gap: 0.8rem; margin-top: 1.4rem; flex-wrap: wrap; }
.cost { color: var(--muted); font-size: 0.86rem; }
.cost b { color: var(--amber); font-variant-numeric: tabular-nums; }

/* ── build pipeline ──────────────────────────────────────────────────────── */
.detail-head { display: flex; gap: 1.2rem; align-items: center; margin-bottom: 1.4rem; flex-wrap: wrap; }
.detail-head .portrait { width: 110px; flex: none; }
.detail-head .nm { font-family: var(--serif); font-size: 1.8rem; }
.detail-head .mt { color: var(--muted); font-size: 0.9rem; }

.pipeline { display: flex; flex-direction: column; gap: 0.2rem; margin: 0.4rem 0 1rem; }
.stage { display: grid; grid-template-columns: 26px 1fr; gap: 0.7rem; padding: 0.55rem 0; border-bottom: 1px solid var(--line); }
.stage:last-child { border-bottom: 0; }
.stage .ic { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line-2); display: grid; place-items: center; font-size: 0.7rem; color: var(--faint); margin-top: 2px; }
.stage.done .ic { background: var(--ready); border-color: var(--ready); color: #10130f; }
.stage.active .ic { border-color: var(--amber); color: var(--amber); animation: pulse 1.6s ease-in-out infinite; }
.stage.planned { opacity: 0.5; }
.stage .lb { font-size: 0.95rem; }
.stage .sub { font-size: 0.8rem; color: var(--muted); }
.stage.active .lb { color: var(--amber); }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(234, 163, 107, 0.4); } 50% { box-shadow: 0 0 0 5px rgba(234, 163, 107, 0); } }

.bar { height: 7px; border-radius: 999px; background: var(--card-2); overflow: hidden; margin-top: 0.4rem; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: var(--accent); transition: width 0.6s ease; }

.statusline { display: inline-flex; align-items: center; gap: 0.5rem; color: var(--soft); font-size: 0.9rem; margin-bottom: 0.6rem; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 0 rgba(234, 163, 107, 0.6); animation: live 1.4s infinite; }
@keyframes live { 0% { box-shadow: 0 0 0 0 rgba(234, 163, 107, 0.5); } 100% { box-shadow: 0 0 0 8px rgba(234, 163, 107, 0); } }

.cast-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 0.6rem; margin-top: 0.6rem; }
.cast-cell { position: relative; }
.cast-cell .portrait { border-radius: 10px; }
.cast-cell .tag { position: absolute; left: 5px; bottom: 5px; font-size: 0.6rem; padding: 0.1rem 0.34rem; border-radius: 6px; background: rgba(0,0,0,0.6); color: var(--soft); }
.cast-cell.done .tag { color: var(--ready); }

.foot-note { color: var(--faint); font-size: 0.8rem; margin-top: 1rem; }
.aside-actions { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 1.2rem; }

/* ── responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .studio { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .form-grid { grid-template-columns: 1fr; }
}

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