:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --bg-elev: #12151c;
  --bg-elev-2: #1a1e28;
  --border: #262b38;
  --text: #e8eaf0;
  --text-dim: #9aa1b2;
  --accent: #7c6cf6;
  --accent-2: #5ee6c9;
  --danger: #f2555a;
  --radius: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(124, 108, 246, 0.18), transparent 60%),
    radial-gradient(900px 500px at 90% 10%, rgba(94, 230, 201, 0.10), transparent 55%),
    var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

a { color: inherit; }

.wrap {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 32px 20px 64px;
  flex: 1;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 20px 0;
}

@media (min-width: 1600px) {
  .wrap, .topbar { max-width: 1500px; }
}

@media (max-width: 480px) {
  .wrap { padding: 18px 12px 36px; }
  .topbar { padding: 14px 12px 0; }
  .page-header { margin-bottom: 18px; }
  .page-header h1 { font-size: 21px; }
  .page-header p { font-size: 13px; }
  .card { padding: 16px; }
  .panel { padding: 14px; }
  .panel + .panel { margin-top: 12px; }
  .gate-card, .pin-card { padding: 26px 20px 22px; max-width: 320px; }
  .center-screen { min-height: calc(100vh - 48px); }
  .admin-layout { gap: 12px; }
  .grid, .poster-grid { gap: 10px; }
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-size: 18px;
}

.brand .dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 14px rgba(124, 108, 246, 0.7);
}

.topbar nav a, .topbar nav button {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 14px;
  margin-left: 18px;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}
.topbar nav a:hover, .topbar nav button:hover { color: var(--text); }

.center-screen {
  min-height: calc(100vh - 60px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.gate-card {
  width: 100%;
  max-width: 380px;
  background: linear-gradient(180deg, var(--bg-elev), var(--bg-elev-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 32px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  text-align: center;
}

.gate-card .icon {
  width: 52px;
  height: 52px;
  margin: 0 auto 18px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.gate-card h1 {
  font-size: 20px;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}

.gate-card p {
  color: var(--text-dim);
  font-size: 14px;
  margin: 0 0 24px;
}

input[type="password"], input[type="text"], textarea {
  width: 100%;
  background: #0d1017;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}
input[type="password"]:focus, input[type="text"]:focus, textarea:focus {
  border-color: var(--accent);
}

textarea { resize: vertical; min-height: 70px; }

button, .btn {
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  transition: transform 0.1s, opacity 0.15s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
button:active, .btn:active { transform: scale(0.98); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #6a5cf0);
  color: white;
  width: 100%;
  margin-top: 16px;
  padding: 13px;
}
.btn-primary:hover { opacity: 0.92; }

.btn-secondary {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-secondary:hover { border-color: #3a4152; }

.btn-danger {
  background: rgba(242, 85, 90, 0.12);
  color: var(--danger);
  border: 1px solid rgba(242, 85, 90, 0.3);
}
.btn-danger:hover { background: rgba(242, 85, 90, 0.2); }

.error-msg {
  background: rgba(242, 85, 90, 0.12);
  border: 1px solid rgba(242, 85, 90, 0.3);
  color: #ff8b8f;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 18px;
  text-align: left;
}

.page-header {
  margin-bottom: 28px;
}
.page-header h1 {
  font-size: 26px;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
}
.page-header p {
  color: var(--text-dim);
  margin: 0;
  font-size: 14px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.card {
  background: linear-gradient(180deg, var(--bg-elev), var(--bg-elev-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card h3 {
  margin: 0;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.card p.desc {
  margin: 0;
  color: var(--text-dim);
  font-size: 13.5px;
  line-height: 1.5;
  flex: 1;
}

.meta-row {
  display: flex;
  gap: 14px;
  font-size: 12.5px;
  color: var(--text-dim);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-dim);
}

.file-details { margin-top: 12px; }
.file-details summary {
  cursor: pointer;
  font-size: 12.5px;
  color: var(--text-dim);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.file-details summary::-webkit-details-marker { display: none; }
.file-details summary::before { content: '▸'; font-size: 10px; }
.file-details[open] summary::before { content: '▾'; }
.file-details summary:hover { color: var(--text); }

.file-download-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.file-download-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}
.file-download-list li:last-child { border-bottom: none; }
.file-download-list li .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-download-list li .size { color: var(--text-dim); font-size: 11.5px; flex-shrink: 0; }
.file-download-list li a.btn { padding: 5px 9px; font-size: 12px; flex-shrink: 0; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}
.empty-state .icon { font-size: 40px; margin-bottom: 12px; }

/* admin */
.admin-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 20px;
  align-items: start;
}
@media (max-width: 860px) {
  .admin-layout { grid-template-columns: 1fr; }
}

.panel {
  background: linear-gradient(180deg, var(--bg-elev), var(--bg-elev-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.panel + .panel { margin-top: 16px; }
.panel h2 {
  font-size: 15px;
  margin: 0 0 14px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--text-dim); margin-bottom: 6px; }

.group-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.group-row:last-child { border-bottom: none; }
.group-row .info h4 { margin: 0 0 3px; font-size: 15px; }
.group-row .info p { margin: 0; font-size: 12.5px; color: var(--text-dim); }
.group-row .actions { display: flex; gap: 8px; flex-shrink: 0; }
.group-row .actions a, .group-row .actions button { font-size: 12.5px; padding: 7px 11px; }

.pill-toggle {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.pill-toggle.on { color: var(--accent-2); border-color: rgba(94,230,201,0.4); background: rgba(94,230,201,0.08); }
.pill-toggle.off { color: var(--text-dim); }

.copy-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.copy-row input { flex: 1; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 13.5px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

footer.hint {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  margin-top: 24px;
}

/* ---- PIN screen ---- */
.pin-card {
  width: 100%;
  max-width: 360px;
  background: linear-gradient(180deg, var(--bg-elev), var(--bg-elev-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 32px 30px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  text-align: center;
}
.pin-card .icon {
  width: 52px;
  height: 52px;
  margin: 0 auto 16px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}
.pin-card h1 { font-size: 20px; margin: 0 0 6px; letter-spacing: -0.01em; }
.pin-card p.sub { color: var(--text-dim); font-size: 13.5px; margin: 0 0 22px; }

.pin-field {
  position: relative;
  cursor: text;
  padding: 6px 0;
}
.pin-display {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 46px;
}
.pin-display .digit {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 22px;
}
.pin-display .digit .num {
  font-size: 28px;
  font-weight: 700;
  line-height: 34px;
  height: 34px;
  color: var(--text);
}
.pin-display .digit .line {
  width: 100%;
  height: 3px;
  border-radius: 2px;
  background: var(--border);
}
.pin-display .digit.filled .line { background: var(--accent-2); }

.pin-real-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: none;
  padding: 0;
  font-size: 16px;
}

/* ---- poster grid ---- */
.poster-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
}
@media (max-width: 480px) {
  .poster-grid { grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); gap: 10px; }
}
.poster-card {
  position: relative;
  cursor: pointer;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid transparent;
  background: var(--bg-elev-2);
  transition: transform 0.12s, border-color 0.12s;
  aspect-ratio: 2 / 3;
  display: flex;
  align-items: flex-end;
}
.poster-card:hover { transform: translateY(-3px); }
.poster-card.selected { border-color: var(--accent-2); }
.poster-card .cover {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  text-align: center;
  padding: 14px 10px;
  color: rgba(255,255,255,0.92);
  line-height: 1.3;
  letter-spacing: -0.01em;
}
.poster-card .cover::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 40%, rgba(0,0,0,0.55) 100%);
}
.poster-card .cover span { position: relative; z-index: 1; }
.poster-card .badge-type {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(4px);
  color: rgba(255,255,255,0.85);
}
.poster-card .check {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: rgba(0,0,0,0.4);
  border: 1.5px solid rgba(255,255,255,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: transparent;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.poster-card.selected .check {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #0b0d12;
}

.selection-tray {
  position: sticky;
  bottom: 16px;
  margin-top: 20px;
  background: linear-gradient(180deg, var(--bg-elev-2), #171b25);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
.selection-tray .count { font-size: 14px; font-weight: 600; }
.selection-tray .count span { color: var(--accent-2); }
@media (max-width: 560px) {
  .selection-tray { flex-direction: column; align-items: stretch; }
  .selection-tray > div { display: flex; }
  .selection-tray button { flex: 1; }
}

/* ---- compose / confirm views ---- */
.compose-list {
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.compose-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  padding: 6px 8px 6px 12px;
  border-radius: 999px;
  font-size: 13px;
}
.compose-list li button { background: none; border: none; color: var(--text-dim); font-size: 15px; padding: 2px; }
.compose-list li button:hover { color: var(--danger); }

.confirm-box { text-align: center; padding: 20px 10px; }
.confirm-box .icon {
  width: 60px; height: 60px; margin: 0 auto 16px; border-radius: 999px;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  display: flex; align-items: center; justify-content: center; font-size: 28px;
}
.confirm-box h3 { margin: 0 0 8px; font-size: 19px; }
.confirm-box p { color: var(--text-dim); font-size: 13.5px; margin: 0 0 18px; }

.crumb-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.crumb-tabs button {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 999px;
}
.crumb-tabs button.active { border-color: var(--accent); color: var(--text); background: rgba(124,108,246,0.14); }
