:root {
  --bg: #02011A;
  --panel: #0E0D2C;
  --panel-raised: #14133A;
  --text: #F2F1F8;
  --text-dim: #8B88A8;
  --accent: #C9A66B;      /* brass — the "archive" accent */
  --accent-dim: #a9865290;
  --danger: #D97757;
  --border: #232152;
  --radius: 16px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

/* The hidden attribute must always win over any class that sets display,
   otherwise elements like the lightbox can render even while "hidden". */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  height: 100%;
  overflow: hidden;
}

body {
  display: flex;
  justify-content: center;
  align-items: stretch;
  min-height: 100vh;
}

#app, #lock-overlay {
  width: 100%;
  max-width: 460px;
  min-height: 100vh;
  position: relative;
  background: var(--bg);
  margin: 0 auto;
}

#lock-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  max-width: 100%;
}

/* ---------- Screens ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .28s ease, transform .28s ease;
  padding: 28px 22px;
}

.screen.active {
  display: flex;
  opacity: 1;
  transform: translateY(0);
}

/* ---------- Login ---------- */
#login-screen {
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 40px;
}

.brand-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
}

.brand-sub {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#login-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 220px;
}

.field-label {
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}

.text-input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-raised);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  outline: none;
  transition: border-color .2s ease, box-shadow .2s ease;
}

.text-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.error-msg {
  min-height: 16px;
  font-size: 12px;
  color: var(--danger);
  margin: 0;
}

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--font);
  font-weight: 600;
  font-size: 14px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: transform .12s ease, opacity .2s ease, background .2s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.96); }

.btn-primary {
  background: var(--accent);
  color: #14100a;
  padding: 13px 18px;
}
.btn-primary:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--panel-raised);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 14px 18px;
}

.btn-ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border);
  padding: 9px 14px;
}

.btn-wide { width: 100%; }
.btn-small { font-size: 13px; padding: 9px 14px; }
.btn-enter { width: 100px; align-self: center; }

.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  padding: 6px;
  cursor: pointer;
  display: flex;
  transition: opacity .15s ease, transform .12s ease;
}
.icon-btn:active { transform: scale(0.9); }
.icon-btn svg { width: 24px; height: 24px; }

/* ---------- Welcome ---------- */
#welcome-screen {
  justify-content: center;
  align-items: center;
}
.welcome-text {
  font-size: 20px;
  font-weight: 600;
  opacity: 0;
  animation: fadeIn .6s ease forwards;
}
@keyframes fadeIn {
  to { opacity: 1; }
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.topbar-label {
  background: var(--panel-raised);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
}

/* ---------- Home ---------- */
#home-screen .topbar { justify-content: center; margin-bottom: 0; }
.home-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
}

/* ---------- Upload ---------- */
.upload-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
.upload-circle {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform .15s ease, background .2s ease;
}
.upload-circle:active { transform: scale(0.94); }
.upload-circle svg { width: 42px; height: 42px; }
.upload-caption { font-weight: 600; font-size: 15px; margin: 0; }

.upload-grid-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  padding-bottom: 90px;
}

.thumb-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  overflow: hidden;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  cursor: pointer;
}
.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .2s ease;
}
.thumb:active img { transform: scale(1.06); }
.thumb.new::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px solid var(--accent);
  border-radius: 10px;
}

.bottom-dock {
  position: absolute;
  left: 22px;
  right: 22px;
  bottom: 26px;
}

/* ---------- View screen ---------- */
.view-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-dim);
  font-size: 14px;
}
.view-grid {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 90px;
  align-content: start;
}

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(2, 1, 26, 0.94);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px;
  animation: fadeIn .2s ease;
}
.lightbox img {
  max-width: 100%;
  max-height: 70vh;
  border-radius: 10px;
  object-fit: contain;
}
.lightbox-close {
  position: absolute;
  top: 22px;
  right: 22px;
}
.lightbox-delete {
  color: var(--danger);
  border-color: var(--danger);
}

/* ---------- Album / Book ---------- */
.book {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  perspective: 1600px;
}
.page-stack {
  position: relative;
  width: 100%;
  max-width: 320px;
  aspect-ratio: 3 / 4;
}
.page {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  overflow: hidden;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  box-shadow: 0 12px 30px rgba(0,0,0,0.45);
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform .55s cubic-bezier(.45,.05,.35,1);
  backface-visibility: hidden;
}
.page img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.page.flipped {
  transform: rotateY(-180deg);
}
.page-counter {
  position: absolute;
  bottom: -34px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
}
.book-hint {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 35%;
  z-index: 5;
  cursor: pointer;
}
.left-hint { left: 0; }
.right-hint { right: 0; }
