:root {
  --ink: #191714;
  --soft-ink: #5d5750;
  --paper: #f7f2eb;
  --white: #fffaf3;
  --rose: #b65c72;
  --gold: #d7a14a;
  --forest: #23463f;
  --night: #080706;
  --line: rgba(25, 23, 20, 0.12);
  --shadow: 0 24px 80px rgba(27, 19, 12, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(215, 161, 74, 0.18), transparent 30%),
    linear-gradient(135deg, #faf6ef 0%, #efe6db 48%, #e6ddd2 100%);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.film-mode {
  overflow-x: hidden;
  background: var(--night);
}

button,
input,
textarea {
  font: inherit;
}

a {
  color: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.is-hidden {
  display: none !important;
}

.home-shell,
.unlock-screen {
  min-height: 100vh;
}

.unlock-screen {
  display: grid;
  place-items: center;
  padding: 24px;
  transition: opacity 700ms ease, transform 700ms ease, filter 700ms ease;
}

.unlock-screen.is-leaving {
  opacity: 0;
  transform: scale(0.98);
  filter: blur(8px);
}

.code-panel {
  width: min(420px, 100%);
  text-align: center;
}

.eyebrow,
.film-kicker,
.letter-label,
.admin-kicker {
  margin: 0 0 12px;
  color: var(--rose);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
.film-title {
  margin: 0;
  font-family: "Playfair Display", Georgia, serif;
  font-size: clamp(2.4rem, 8vw, 5.6rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.code-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-top: 32px;
}

.code-input,
.field,
.textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 250, 243, 0.86);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset;
  outline: none;
}

.code-input {
  min-width: 0;
  padding: 18px 16px;
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-align: center;
}

.code-input:focus,
.field:focus,
.textarea:focus {
  border-color: rgba(182, 92, 114, 0.62);
  box-shadow: 0 0 0 4px rgba(182, 92, 114, 0.14);
}

.primary-button,
.secondary-button,
.danger-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

.primary-button {
  color: #fff;
  background: var(--forest);
}

.secondary-button {
  color: var(--forest);
  background: rgba(35, 70, 63, 0.1);
}

.danger-link {
  min-height: 36px;
  color: #9d2f45;
  background: rgba(157, 47, 69, 0.08);
}

.form-message,
.admin-message {
  min-height: 24px;
  margin: 18px 0 0;
  color: #9d2f45;
  font-weight: 700;
}

.film {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
  color: #fffaf3;
  background:
    linear-gradient(rgba(8, 7, 6, 0.48), rgba(8, 7, 6, 0.82)),
    url("https://images.unsplash.com/photo-1495567720989-cebdbdd97913?auto=format&fit=crop&w=1800&q=80") center/cover fixed;
}

.film-grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.18;
  background-image:
    repeating-radial-gradient(circle at 20% 30%, rgba(255, 255, 255, 0.24) 0 1px, transparent 1px 4px);
  mix-blend-mode: overlay;
}

.film-stage {
  position: relative;
  z-index: 1;
  display: grid;
  min-height: 100vh;
  align-content: center;
  justify-items: center;
  padding: 44px 18px;
  text-align: center;
}

.film-kicker,
.film-title {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 1000ms ease, transform 1000ms ease;
}

.film-kicker.is-visible,
.film-title.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.film-kicker {
  max-width: 620px;
  color: rgba(255, 250, 243, 0.74);
}

.memory-frame {
  width: min(860px, 92vw);
  margin: 38px 0 0;
  opacity: 0;
  transform: translateY(28px) scale(0.97);
  transition: opacity 800ms ease, transform 900ms ease;
}

.memory-frame.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.memory-frame img {
  display: block;
  width: 100%;
  max-height: 68vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 34px 120px rgba(0, 0, 0, 0.48);
}

.memory-frame figcaption {
  min-height: 28px;
  margin-top: 18px;
  color: rgba(255, 250, 243, 0.82);
  font-size: clamp(1rem, 2vw, 1.28rem);
  font-weight: 600;
}

.letter-card {
  width: min(780px, 94vw);
  max-height: 76vh;
  margin-top: 32px;
  padding: clamp(24px, 5vw, 54px);
  overflow: auto;
  color: var(--ink);
  text-align: left;
  background: rgba(255, 250, 243, 0.95);
  border-radius: 8px;
  box-shadow: 0 34px 120px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transform: translateY(22px);
  transition: opacity 900ms ease, transform 900ms ease;
}

.letter-card.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.letter-text {
  font-family: "Playfair Display", Georgia, serif;
  font-size: clamp(1.35rem, 3.3vw, 2rem);
  line-height: 1.6;
}

.final-wall {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  width: min(900px, 92vw);
  margin-top: 24px;
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 900ms ease, transform 900ms ease;
}

.final-wall.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.final-wall img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
}

.admin-shell {
  min-height: 100vh;
  background:
    radial-gradient(circle at 80% 10%, rgba(35, 70, 63, 0.16), transparent 30%),
    #f8f4ee;
}

.admin-wrap {
  width: min(1100px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 56px;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 26px;
}

.admin-title {
  margin: 0;
  font-size: clamp(2rem, 5vw, 4rem);
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(280px, 0.85fr);
  gap: 22px;
  align-items: start;
}

.admin-card,
.login-card,
.recipient-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 243, 0.82);
  box-shadow: var(--shadow);
}

.admin-card,
.login-card {
  padding: 22px;
}

.login-card {
  width: min(420px, calc(100% - 32px));
  margin: 12vh auto 0;
}

.install-wrap {
  width: min(760px, calc(100% - 32px));
  margin: 0 auto;
  padding: 8vh 0 56px;
}

.install-card {
  padding: clamp(20px, 4vw, 34px);
}

.install-form {
  margin-top: 24px;
}

.install-grid {
  display: grid;
  grid-template-columns: 1fr 150px;
  gap: 14px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0 18px;
  color: var(--soft-ink);
  font-weight: 800;
}

.field-group {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.field-group label,
.memory-upload label {
  color: var(--soft-ink);
  font-size: 0.9rem;
  font-weight: 800;
}

.field {
  min-height: 46px;
  padding: 12px;
}

.textarea {
  min-height: 180px;
  resize: vertical;
  padding: 12px;
  line-height: 1.5;
}

.hint {
  margin: 6px 0 0;
  color: var(--soft-ink);
  font-size: 0.88rem;
}

.memory-upload {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px dashed rgba(25, 23, 20, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.42);
}

.recipient-list {
  display: grid;
  gap: 12px;
}

.recipient-card {
  padding: 14px;
}

.recipient-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.code-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  color: #fff;
  background: var(--forest);
  font-weight: 900;
  letter-spacing: 0.12em;
}

.recipient-meta {
  margin: 8px 0 0;
  color: var(--soft-ink);
  font-size: 0.9rem;
}

@media (max-width: 760px) {
  .code-form,
  .admin-grid,
  .admin-header,
  .install-grid {
    grid-template-columns: 1fr;
  }

  .code-form {
    display: grid;
  }

  .admin-header {
    display: grid;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }
}

/* Shared controls and soundtrack editor. */
::selection { color: var(--white); background: var(--rose); }
button, a, input { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, summary:focus-visible, input[type="range"]:focus-visible {
  outline: 3px solid var(--rose);
  outline-offset: 5px;
}
button { transition: background 180ms ease, transform 180ms ease; }
button:disabled { opacity: 0.6; cursor: wait; }
.primary-button:hover:not(:disabled) { background: #315c50; transform: translateY(-1px); }
.secondary-button:hover { background: rgba(35, 70, 63, 0.17); }

.admin-wrap { padding-top: 45px; }
.admin-header .hint { margin-top: 16px; line-height: 1.6; }
.admin-card { padding: clamp(20px, 3vw, 32px); }
.admin-grid > *, .field-group, .memory-upload, .trim-grid > * { min-width: 0; }
.memory-upload input[type="file"] { min-width: 0; width: 100%; font-size: 12px; }
.field-group { margin-bottom: 22px; }
.field-group label { font-weight: 500; }
.hint { line-height: 1.6; }
.audio-editor { min-width: 0; margin: 28px 0; padding: 20px; border: 1px solid #23463f26; border-radius: 6px; background: #23463f05; }
.audio-editor legend { padding: 0 8px; color: var(--forest); font-family: "Playfair Display", Georgia, serif; font-size: 20px; }
.audio-editor > .hint { font-size: 11px; margin-top: 0; }
.music-upload { display: grid; grid-template-columns: 25px minmax(0, 1fr); gap: 10px; padding: 18px 14px; margin: 18px 0 12px; border: 1px dashed #23463f50; border-radius: 4px; background: #fffaf3; cursor: pointer; }
.upload-symbol { color: var(--rose); font-size: 27px; }
.music-upload strong { display: block; font-size: 12px; font-weight: 600; overflow-wrap: anywhere; }
.music-upload small { display: block; font-size: 9px; color: var(--soft-ink); margin-top: 5px; line-height: 1.5; }
.music-upload input { grid-column: 1 / -1; width: 100%; font-size: 10px; color: var(--soft-ink); }
.music-upload input::file-selector-button { padding: 6px 10px; margin-right: 8px; border: 1px solid var(--line); border-radius: 4px; color: var(--forest); background: #edf0e6; cursor: pointer; }
.audio-status { font-size: 11px; }
.audio-status.is-error { color: #9d2f45; }
.trim-controls { margin-top: 22px; }
.trim-heading { display: flex; justify-content: space-between; gap: 8px; font-size: 10px; color: var(--soft-ink); }
.trim-heading span:last-child { color: var(--forest); font-variant-numeric: tabular-nums; white-space: nowrap; }
.selection-track { position: relative; height: 25px; margin: 14px 0 18px; overflow: hidden; border-radius: 3px; background: #23463f12; }
.selection-track > div { position: absolute; top: 0; height: 100%; border-inline: 3px solid var(--forest); background: #23463f30; }
.trim-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.trim-grid label { display: flex; justify-content: space-between; gap: 4px; font-size: 11px; color: var(--soft-ink); }
.trim-grid label span { color: var(--forest); font-variant-numeric: tabular-nums; }
.trim-grid input[type="range"] { display: block; width: 100%; margin: 14px 0; accent-color: var(--forest); cursor: pointer; }
.trim-grid .time-input { width: min(90px, 100%); min-height: 34px; padding: 8px; font-size: 11px; font-variant-numeric: tabular-nums; }
.trim-grid small { font-size: 9px; color: var(--soft-ink); }
.preview-row { display: flex; align-items: center; gap: 14px; margin: 18px 0 12px; }
.preview-row .secondary-button { min-height: 37px; font-size: 11px; font-weight: 500; padding-inline: 14px; }
.preview-time { color: var(--forest); font-variant-numeric: tabular-nums; font-size: 11px; }
.trim-controls > .hint { font-size: 10px; }
.music-details { margin-top: 18px; margin-bottom: 14px; }
.music-details summary { color: var(--forest); font-size: 12px; cursor: pointer; padding: 4px 0; }
.music-details .audio-editor { margin-block: 20px 14px; padding: 14px; }
.music-details .audio-editor legend { font-size: 17px; }
.music-details .trim-grid { gap: 10px; }
.remove-music { display: flex; align-items: center; gap: 8px; margin-top: 16px; font-size: 11px; color: var(--soft-ink); }


@media (max-width:760px) { .preview-row .secondary-button { width:auto; } .admin-title { line-height:1.1; } }
@media (prefers-reduced-motion:reduce) { *, *::before, *::after { animation-duration:0.01ms !important; animation-iteration-count:1 !important; transition-duration:0.01ms !important; scroll-behavior:auto !important; } }

.view-history { margin-top: 20px; padding: 14px 0; border-block: 1px solid var(--line); }
.view-history summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--forest); font-size: 12px; font-weight: 600; cursor: pointer; list-style: none; }
.view-history summary::-webkit-details-marker { display: none; }
.view-history summary > span:first-child::before { content: '▸'; display: inline-block; width: 16px; }
.view-history[open] summary > span:first-child::before { content: '▾'; }
.view-count { flex-shrink: 0; padding: 4px 9px; border-radius: 999px; background: #23463f0c; font-size: 11px; font-weight: 500; }
.view-last { margin: 9px 0 0; color: var(--soft-ink); font-size: 10px; line-height: 1.7; }
.view-history:not([open]) .view-last { display: block; }
.history-content { padding-top: 8px; }
.history-explainer { font-size: 10px; line-height: 1.7; }
.history-status { margin: 12px 0; color: var(--soft-ink); font-size: 11px; line-height: 1.6; }
.history-status:empty { display: none; }
.history-status.is-error { color: #9d2f45; }
.history-rows { display: grid; gap: 0; margin: 12px 0; padding: 0; list-style: none; }
.history-rows li { display: grid; gap: 5px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.history-rows strong { font-size: 12px; font-weight: 500; overflow-wrap: anywhere; }
.history-rows time { color: var(--soft-ink); font-size: 10px; line-height: 1.6; font-variant-numeric: tabular-nums; }
.history-pagination { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.history-pagination > span { color: var(--soft-ink); font-size: 10px; }
.history-button { min-height: 35px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 5px; color: var(--forest); background: transparent; font-size: 10px; cursor: pointer; }
.history-button:disabled { opacity: .35; cursor: default; }
.history-refresh { min-height: 36px; padding: 10px 0 0; border: 0; color: var(--forest); background: transparent; font-size: 10px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
