@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600;9..144,700&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@500&display=swap');

:root {
  /* Color — ink & brass, built for a sanctuary, not a startup */
  --ink: #12151c;
  --ink-elevated: #1b202b;
  --ink-elevated-2: #232a37;
  --hairline: #323a49;
  --ivory: #f3efe3;
  --ivory-dim: #cfc9b6;
  --muted: #8a92a3;
  --brass: #c9a227;
  --brass-soft: #e4c766;
  --teal: #3c6672;
  --teal-soft: #5c8794;
  --error: #d16a5a;
  --success: #6fa287;

  /* Type */
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;

  --radius: 10px;
  --radius-lg: 16px;
  --shadow-card: 0 12px 32px -12px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}
body {
  background: var(--ink);
  color: var(--ivory);
  font-family: var(--font-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, a, input[type="checkbox"], .tab-btn, .room-card, .music-row {
  touch-action: manipulation;
}

a { color: inherit; }

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brass-soft);
}

p { color: var(--ivory-dim); }

button, input, select { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--brass-soft);
  outline-offset: 2px;
}

/* ---------------------------- Layout shells ---------------------------- */

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  padding: 0 24px;
}

.container--wide {
  max-width: 1080px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 16px 24px;
  padding-top: max(16px, env(safe-area-inset-top));
  padding-left: max(24px, env(safe-area-inset-left));
  padding-right: max(24px, env(safe-area-inset-right));
  border-bottom: 1px solid var(--hairline);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  text-decoration: none;
}
.brand-mark {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  color: var(--ivory);
}
.brand-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------------------------- Staff-line motif ---------------------------- */
/* The recurring signature element: five hairlines like a music staff,
   used as dividers and ambient texture throughout the app. */

.staff {
  width: 100%;
  height: 28px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  opacity: 0.35;
}
.staff span {
  display: block;
  height: 1px;
  background: var(--hairline);
}
.staff--accent span { background: var(--brass); opacity: 0.5; }

/* ------------------------------- Buttons ------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 15px;
  min-height: 44px;
  padding: 12px 20px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
  text-decoration: none;
}
.btn:active { transform: scale(0.98); }

.btn--primary {
  background: var(--brass);
  color: #1a1400;
}
.btn--primary:hover { background: var(--brass-soft); }

.btn--secondary {
  background: transparent;
  border-color: var(--hairline);
  color: var(--ivory);
}
.btn--secondary:hover { border-color: var(--brass-soft); color: var(--brass-soft); }

.btn--ghost {
  background: transparent;
  color: var(--muted);
  padding: 8px 12px;
}
.btn--ghost:hover { color: var(--ivory); }

.btn--danger {
  background: transparent;
  color: var(--error);
  border-color: rgba(209, 106, 90, 0.4);
  padding: 8px 14px;
  font-size: 13px;
}
.btn--danger:hover { background: rgba(209, 106, 90, 0.12); }

.btn--block { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* -------------------------------- Cards -------------------------------- */

.card {
  background: var(--ink-elevated);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

/* ------------------------------- Gate page ------------------------------ */

.gate {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
}

.gate-inner {
  width: 100%;
  max-width: 720px;
  text-align: center;
}

.gate-title {
  font-size: clamp(32px, 6vw, 48px);
  margin: 18px 0 8px;
}

.gate-sub {
  color: var(--muted);
  font-size: 15px;
  margin: 0 0 36px;
}

.gate-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  text-align: left;
}

@media (max-width: 560px) {
  .gate-options { grid-template-columns: 1fr; }
}

.gate-option {
  display: block;
  background: var(--ink-elevated);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  text-decoration: none;
  color: var(--ivory);
  transition: border-color 0.18s ease, transform 0.18s ease, background 0.18s ease;
}
.gate-option:hover {
  border-color: var(--brass);
  transform: translateY(-2px);
  background: var(--ink-elevated-2);
}
.gate-option-icon {
  width: 40px;
  height: 40px;
  margin-bottom: 16px;
  color: var(--brass-soft);
}
.gate-option h2 {
  font-size: 22px;
  margin-bottom: 6px;
}
.gate-option p {
  font-size: 13px;
  margin: 0;
  color: var(--muted);
}
.gate-option--primary {
  background: linear-gradient(165deg, var(--ink-elevated-2), var(--ink-elevated));
  border-color: var(--brass);
}

/* -------------------------------- Forms --------------------------------- */

.field {
  margin-bottom: 18px;
  text-align: left;
}
.field label {
  display: block;
  font-size: 12px;
  font-family: var(--font-mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}
.field input[type="text"],
.field input[type="password"] {
  width: 100%;
  background: var(--ink);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 13px 14px;
  color: var(--ivory);
  font-size: 16px;
}
.field input:focus { border-color: var(--brass-soft); }

.text-input, .select-input {
  width: 100%;
  background: var(--ink);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 13px 14px;
  color: var(--ivory);
  font-size: 16px;
  min-height: 44px;
}
.text-input:focus, .select-input:focus { border-color: var(--brass-soft); }

.inline-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.inline-form .text-input { flex: 1 1 220px; }
.inline-form .btn { flex: 0 0 auto; }

.hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}

.error-msg {
  background: rgba(209, 106, 90, 0.12);
  border: 1px solid rgba(209, 106, 90, 0.4);
  color: #f0b3a6;
  font-size: 13px;
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 18px;
  display: none;
}
.error-msg.visible { display: block; }

/* ------------------------------ Room cards ------------------------------ */

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

.room-card {
  display: block;
  text-decoration: none;
  color: var(--ivory);
  background: var(--ink-elevated);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  padding: 22px;
  transition: border-color 0.18s ease, transform 0.18s ease;
  position: relative;
  overflow: hidden;
}
.room-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(120px 80px at 100% 0%, rgba(201, 162, 39, 0.14), transparent);
  opacity: 0;
  transition: opacity 0.18s ease;
}
.room-card:hover { border-color: var(--brass); transform: translateY(-2px); }
.room-card:hover::before { opacity: 1; }

.room-card h3 { font-size: 18px; margin-bottom: 4px; }
.room-card .room-meta { font-size: 12px; color: var(--muted); font-family: var(--font-mono); }

/* ------------------------------ Music list ------------------------------ */

.music-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.music-row {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--ink);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.file-badge {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink);
  background: var(--teal-soft);
}
.file-badge[data-type="pdf"] { background: #c9a227; color: #1a1400; }
.file-badge[data-type="docx"], .file-badge[data-type="doc"] { background: #5c8794; }
.file-badge[data-type="png"], .file-badge[data-type="jpg"], .file-badge[data-type="jpeg"] { background: #8a92a3; color: #12151c; }

.music-row-info { flex: 1; min-width: 0; }
.music-row-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.music-row-meta {
  font-size: 12px;
  color: var(--muted);
  font-family: var(--font-mono);
  margin-top: 2px;
}

.music-row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.checkbox-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  min-height: 44px;
  padding: 4px;
}
.checkbox-toggle input { width: 22px; height: 22px; accent-color: var(--brass); cursor: pointer; }

/* --------------------------------- Tabs ---------------------------------- */

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--hairline);
  margin-bottom: 24px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  flex-shrink: 0;
  min-height: 44px;
}
.tab-btn.active { color: var(--ivory); border-bottom-color: var(--brass); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ------------------------------- Empty state ------------------------------ */

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}
.empty-state svg { width: 36px; height: 36px; margin-bottom: 14px; color: var(--hairline); }
.empty-state p { margin: 0; font-size: 14px; }

/* --------------------------------- Toast --------------------------------- */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--ink-elevated-2);
  border: 1px solid var(--hairline);
  color: var(--ivory);
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: var(--shadow-card);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 8px;
}
.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); flex-shrink: 0; }

/* -------------------------------- Modal ---------------------------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 14, 0.72);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal-backdrop.visible { display: flex; }

.modal {
  background: var(--ink-elevated);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 900px;
  height: 90vh;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px 14px 20px;
  border-bottom: 1px solid var(--hairline);
  flex-shrink: 0;
}
.modal-header h3 {
  font-size: 15px;
  font-family: var(--font-body);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-right: 8px;
}
.modal-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0;
  background: var(--ink);
  display: flex;
  flex-direction: column;
}
.modal-body iframe { flex: 1; width: 100%; height: 100%; border: none; display: block; background: white; }
.modal-body img { width: 100%; height: auto; display: block; }
.modal-body .docx-view {
  padding: 24px 20px;
  background: var(--ivory);
  color: #1c212b;
  flex: 1;
}
.modal-close-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}
.modal-close-btn:hover { color: var(--ivory); background: var(--ink-elevated-2); }

@media (max-width: 640px) {
  .modal-backdrop { padding: 0; }
  .modal {
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    max-width: 100%;
    border-radius: 0;
    border: none;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ------------------------------ Cache status ------------------------------ */

.cache-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
  font-family: var(--font-mono);
  margin-top: 4px;
}
.cache-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); flex-shrink: 0; }

/* -------------------------------- Utility -------------------------------- */

.flex-row { display: flex; align-items: center; gap: 10px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mt-32 { margin-top: 32px; }
.mb-16 { margin-bottom: 16px; }
.text-muted { color: var(--muted); }
.small { font-size: 12px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--hairline);
  border-top-color: var(--brass);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.icon { width: 18px; height: 18px; flex-shrink: 0; }

.footer-note {
  text-align: center;
  padding: 24px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  color: var(--muted);
  font-size: 12px;
}

/* ----------------------------- Offline banner ----------------------------- */

.offline-banner {
  display: none;
  align-items: center;
  gap: 8px;
  justify-content: center;
  background: var(--ink-elevated-2);
  border-bottom: 1px solid var(--hairline);
  color: var(--brass-soft);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 8px 12px;
}
.offline-banner.visible { display: flex; }
.offline-banner .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--brass-soft);
}
