:root {
  --ink: #0a0c0f;
  --panel: #12151a;
  --panel-2: #191e25;
  --line: #262d36;
  --line-soft: #1d232b;
  --text: #ece7dd;
  --muted: #8b939c;
  --accent: #e6a13c;
  --accent-soft: rgba(230, 161, 60, .14);
  --accent-ink: #171004;
  --ok: #5fd68f;
  --bad: #e5534b;
  --flash: #ffd479;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
  --serif: "Instrument Serif", Georgia, serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  color: var(--text);
  font-family: var(--sans);
  background:
    radial-gradient(1100px 520px at 78% -12%, rgba(230, 161, 60, .075), transparent 62%),
    radial-gradient(900px 500px at -10% 110%, rgba(95, 214, 143, .045), transparent 60%),
    var(--ink);
  min-height: 100%;
}

/* film grain */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='.6'/%3E%3C/svg%3E");
}

.mono { font-family: var(--mono); }
.serif { font-family: var(--serif); font-style: italic; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* ---------- header ---------- */

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line-soft);
  animation: rise .45s ease both;
}

.brand { display: flex; align-items: baseline; gap: 10px; }
.brand .mark { width: 22px; height: 22px; color: var(--accent); align-self: center; }
.brand .tag {
  font-size: 12px;
  letter-spacing: .18em;
  color: var(--text);
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 3px 8px;
  border-radius: 4px;
}
.brand .serif { font-size: 21px; color: var(--muted); }

#statusBar { display: flex; align-items: center; gap: 16px; font-size: 12px; }
.cluster { display: inline-flex; align-items: center; gap: 7px; }
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #4a5158; display: inline-block;
}
.dot.online { background: var(--ok); box-shadow: 0 0 0 0 rgba(95, 214, 143, .5); animation: pulse 2.4s infinite; }
.dot.offline { background: var(--bad); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(95, 214, 143, .45); }
  70% { box-shadow: 0 0 0 7px rgba(95, 214, 143, 0); }
  100% { box-shadow: 0 0 0 0 rgba(95, 214, 143, 0); }
}

/* ---------- layout ---------- */

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 22px 22px 90px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 20px;
  align-items: start;
}

#rail { display: grid; gap: 16px; }

.card {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  animation: rise .5s ease both;
}
#rail .card:nth-child(2) { animation-delay: .07s; }

.label {
  margin: 2px 0 10px;
  font-size: 11px;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 500;
}

/* ---------- viewer ---------- */

#imgWrap {
  position: relative;
  aspect-ratio: 4 / 3;
  background: #000;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
#imgWrap::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,.42), transparent 22%, transparent 78%, rgba(0,0,0,.42));
  pointer-events: none;
  z-index: 1;
}
#photo {
  width: 100%; height: 100%;
  object-fit: contain;
  display: block;
  transition: opacity .22s ease;
}
#photo.swap { opacity: 0; }

.overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 13px;
  background: rgba(8, 10, 13, .78);
  backdrop-filter: blur(2px);
}

.spinner {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#snapBtn {
  position: absolute;
  right: 14px; bottom: 14px;
  z-index: 3;
  width: 56px; height: 56px;
  border-radius: 50%;
  border: 1px solid rgba(230, 161, 60, .55);
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 22px rgba(230, 161, 60, .28);
  transition: transform .09s ease, box-shadow .2s ease, filter .2s ease;
}
#snapBtn:hover { box-shadow: 0 8px 28px rgba(230, 161, 60, .42); filter: brightness(1.06); }
#snapBtn:active { transform: scale(.9); }
#snapBtn:disabled { filter: grayscale(.6) brightness(.7); cursor: default; box-shadow: none; }
.icon { width: 18px; height: 18px; }
.icon.big { width: 26px; height: 26px; }

#liveBtn {
  position: absolute;
  top: 12px; right: 12px;
  z-index: 3;
}

.chip {
  border: 1px solid var(--line);
  background: rgba(18, 21, 26, .82);
  color: var(--text);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  backdrop-filter: blur(3px);
  transition: border-color .15s ease, color .15s ease;
}
.chip:hover { border-color: var(--muted); }
.chip.live {
  color: var(--ok);
  border-color: rgba(95, 214, 143, .55);
  font-family: var(--mono);
  letter-spacing: .14em;
  font-weight: 500;
}
.chip.ghost { background: transparent; color: var(--muted); }
.chip.ghost:hover { color: var(--text); }
.chip.solid { background: var(--panel-2); border-radius: 8px; padding: 6px 12px; }
.chip.solid:hover { border-color: var(--accent); color: var(--accent); }
.chip:disabled { opacity: .45; cursor: default; }
.right { margin-left: auto; }

#captionRow {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 2px 4px;
  font-size: 12.5px;
  letter-spacing: .04em;
}
#tsLabel { color: var(--text); }
.badge {
  font-size: 10px;
  letter-spacing: .16em;
  padding: 2px 8px;
  border-radius: 3px;
  color: var(--flash);
  border: 1px solid rgba(255, 212, 121, .45);
  background: rgba(255, 212, 121, .08);
}

/* ---------- timeline ---------- */

.timeline { margin-top: 10px; }

input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 99px;
  background: linear-gradient(to right, var(--accent) var(--fill, 100%), var(--line) var(--fill, 100%));
  outline: none;
  cursor: pointer;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--ink);
  box-shadow: 0 0 0 1px var(--accent), 0 2px 8px rgba(0,0,0,.6);
  transition: transform .12s ease;
}
input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.15); }
input[type=range]::-moz-range-thumb {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--ink);
  box-shadow: 0 0 0 1px var(--accent);
}

#rangeLabels {
  display: flex;
  justify-content: space-between;
  font-size: 10.5px;
  color: var(--muted);
  margin-top: 6px;
  letter-spacing: .05em;
}

/* ---------- transport ---------- */

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.transport { margin-top: 14px; }

.play {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font: 600 13px var(--sans);
  letter-spacing: .02em;
  padding: 9px 18px;
  cursor: pointer;
  transition: filter .15s ease, transform .09s ease;
}
.play:hover { filter: brightness(1.07); }
.play:active { transform: scale(.96); }

.speed {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: .08em;
}
.speed input[type=range] { width: 110px; height: 3px; }
.speed #speedVal { color: var(--text); min-width: 2ch; text-align: right; }

/* ---------- rail controls ---------- */

#rail .row { margin: 4px 0 8px; }
#rail label { font-size: 11px; letter-spacing: .1em; color: var(--muted); }
#rail p { margin: 2px 0 0; line-height: 1.5; }

input[type=number], input[type=time], input[type=date], select {
  font: 400 13px var(--mono);
  color: var(--text);
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  transition: border-color .15s ease;
}
input[type=number]:focus, input[type=time]:focus, input[type=date]:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}
input[type=date] { color-scheme: dark; }

.rangeRow {
  font-size: 11px;
  letter-spacing: .06em;
  gap: 8px;
  margin: 0 0 10px;
  color: var(--muted);
}
.rangeRow input[type=date] { padding: 5px 8px; }
.rangeRow .chip { padding: 5px 12px; }
input[type=number] { width: 74px; }
select { width: 100%; margin-bottom: 2px; }
#rail .row select { flex: 1; }

/* ---------- login gate ---------- */

#splash {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
  justify-content: center;
  background: var(--ink);
}
#splash .mark { width: 44px; height: 44px; color: var(--accent); animation: rise .5s ease both; }
#splash h1 {
  margin: 0;
  font-weight: 400;
  font-size: 28px;
  color: var(--text);
  letter-spacing: .04em;
  animation: rise .5s .08s ease both;
}
#splash .spinner { margin-top: 4px; }
#splash.fade { opacity: 0; transition: opacity .25s ease; pointer-events: none; }

.gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(900px 480px at 50% -10%, rgba(230, 161, 60, .1), transparent 60%),
    var(--ink);
}
.gateCard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: min(340px, 88vw);
  padding: 34px 30px 26px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .55);
  animation: rise .5s ease both;
  text-align: center;
}
.gateCard .mark { width: 34px; height: 34px; color: var(--accent); }
.gateCard h1 {
  margin: 2px 0 0;
  font: 500 13px var(--mono);
  letter-spacing: .3em;
  text-transform: uppercase;
}
.gateCard p { margin: 0; }
#gatePw {
  width: 100%;
  margin-top: 10px;
  font: 400 15px var(--mono);
  text-align: center;
  letter-spacing: .2em;
  color: var(--text);
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  transition: border-color .15s ease;
}
#gatePw:focus { outline: none; border-color: var(--accent); }
#gateBtn { width: 100%; justify-content: center; margin-top: 4px; }
.gateErr { min-height: 16px; font-size: 12px; color: var(--bad); margin: 2px 0 0; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}
.gateCard.shake { animation: shake .4s ease; }

/* ---------- toast ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  margin: 0;
  padding: 9px 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(18, 21, 26, .92);
  backdrop-filter: blur(6px);
  font-size: 12px;
  letter-spacing: .04em;
  color: var(--ok);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 20;
  max-width: min(92vw, 560px);
  text-align: center;
}
#toast:not(:empty) { opacity: 1; transform: translateX(-50%) translateY(-4px); }

.tspin {
  display: inline-block;
  width: 13px;
  height: 13px;
  vertical-align: -2px;
  margin-right: 2px;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}

/* ---------- responsive ---------- */

@media (max-width: 940px) {
  main { grid-template-columns: 1fr; padding: 16px 14px 90px; }
  header { padding: 12px 14px; }
  #rail { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 620px) {
  #rail { grid-template-columns: 1fr; }
  #statusBar { gap: 10px; font-size: 11px; }
}

/* ---------------- delete ---------------- */

/* sits beside #snapBtn, deliberately smaller and quieter than the capture FAB */
#delBtn {
  position: absolute;
  right: 80px; bottom: 20px;
  z-index: 3;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(18, 21, 26, .82);
  color: var(--muted);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(3px);
  transition: color .15s ease, border-color .15s ease, transform .09s ease;
}
#delBtn:hover { color: var(--bad); border-color: rgba(229, 83, 75, .55); }
#delBtn:active { transform: scale(.9); }
#delBtn:disabled { opacity: .45; cursor: default; }

.chip.danger { color: var(--bad); }
.chip.danger:hover:not(:disabled) { border-color: rgba(229, 83, 75, .55); }
.play.danger { background: var(--bad); color: #fff; }
.play.danger:disabled { opacity: .5; cursor: default; filter: none; }

#confirmDlg {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  padding: 0;
  max-width: 420px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
}
#confirmDlg::backdrop { background: rgba(6, 8, 11, .72); backdrop-filter: blur(2px); }
.confirmCard { padding: 20px 22px 18px; display: grid; gap: 12px; }
.confirmCard h2 { margin: 0; font: 400 21px var(--serif); }
.confirmCard p { margin: 0; line-height: 1.5; }
#confirmTypeRow { display: grid; gap: 6px; color: var(--muted); }
#confirmTypeRow b { color: var(--bad); font-weight: 500; }
#confirmType {
  border: 1px solid var(--line);
  background: var(--ink);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font: 400 13px var(--mono);
}
#confirmType:focus { outline: none; border-color: var(--bad); }
.confirmRow { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
