/* ============================================================
   LOG BOOK — a digital ledger register
   Tokens
   ============================================================ */
:root {
  --paper: #ECE7D8;
  --paper-card: #F5F1E4;
  --paper-line: #D8D0B8;
  --ink: #1E2A38;
  --ink-soft: #5B5346;
  --red: #8C2F39;
  --red-deep: #6E2129;
  --stamp-green: #2E5E45;
  --gold: #B08D3E;

  --font-stamp: 'Special Elite', 'Courier New', monospace;
  --font-body: 'Lora', Georgia, serif;
  --font-mono: 'Courier Prime', 'Courier New', monospace;

  --radius: 3px;
  --max-w: 480px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

body {
  background-image: repeating-linear-gradient(
    to bottom,
    transparent,
    transparent 34px,
    var(--paper-line) 35px
  );
  min-height: 100vh;
}

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

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

/* ============================================================
   Ledger margin rule — the red vertical line down a register page
   ============================================================ */
.margin-rule {
  position: fixed;
  top: 0;
  bottom: 0;
  left: max(18px, calc(50% - var(--max-w) / 2 + 34px));
  width: 2px;
  background: var(--red);
  opacity: 0.55;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 28px 20px 64px 46px;
}

/* ============================================================
   Header
   ============================================================ */
.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.app-title {
  font-family: var(--font-stamp);
  font-size: 1.7rem;
  font-weight: 400;
  letter-spacing: 0.02em;
  margin: 0 0 4px 0;
  color: var(--ink);
  line-height: 1.15;
  word-break: break-word;
}

.app-sub {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.icon-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--paper-line);
  background: var(--paper-card);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.icon-btn:hover { border-color: var(--red); transform: rotate(18deg); }
.icon-btn:active { transform: rotate(18deg) scale(0.94); }

.rule-double {
  height: 4px;
  margin: 16px 0 18px;
  background:
    linear-gradient(var(--ink), var(--ink)) top / 100% 1px no-repeat,
    linear-gradient(var(--red), var(--red)) bottom / 100% 2px no-repeat;
  opacity: 0.85;
}

.rule-single {
  height: 1px;
  margin: 28px 0 18px;
  background: var(--paper-line);
}

.eyebrow {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

/* ============================================================
   Banner
   ============================================================ */
.banner {
  background: var(--paper-card);
  border: 1px dashed var(--red);
  color: var(--ink);
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 0.88rem;
  margin-bottom: 18px;
  line-height: 1.5;
}

/* ============================================================
   Ledger panel / form
   ============================================================ */
.ledger-panel {
  background: var(--paper-card);
  border: 1px solid var(--paper-line);
  border-radius: var(--radius);
  padding: 20px 18px;
  box-shadow: 0 1px 0 rgba(30, 42, 56, 0.05);
}

.field { margin-bottom: 20px; }
.field:last-of-type { margin-bottom: 0; }

input[type="date"],
input[type="text"],
input[type="url"] {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--paper-line);
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.95rem;
  border-radius: var(--radius);
  transition: border-color 0.15s ease;
}
input[type="date"]:focus,
input[type="text"]:focus,
input[type="url"]:focus {
  border-color: var(--red);
}

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

/* Photo picker */
.photo-row {
  display: flex;
  gap: 14px;
  align-items: stretch;
}

.preview-frame {
  width: 96px;
  height: 96px;
  flex-shrink: 0;
  border: 1px solid var(--paper-line);
  border-radius: var(--radius);
  background: var(--paper);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.preview-placeholder {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--ink-soft);
  text-align: center;
  padding: 4px;
  letter-spacing: 0.03em;
}

.preview-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-actions {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  flex: 1;
}

input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-block;
  text-align: center;
  border: 1px solid var(--ink);
  background: transparent;
  color: var(--ink);
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  letter-spacing: 0.03em;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.btn:hover { background: var(--ink); color: var(--paper); }

.btn-secondary { border-color: var(--paper-line); color: var(--ink); }
.btn-secondary:hover { background: var(--ink); border-color: var(--ink); }

.btn-ghost {
  border-color: transparent;
  color: var(--red);
  padding-left: 4px;
  padding-right: 4px;
}
.btn-ghost:hover { background: transparent; color: var(--red-deep); text-decoration: underline; }

.btn-primary {
  width: 100%;
  border-color: var(--red);
  background: var(--red);
  color: var(--paper);
  padding: 12px;
  font-size: 0.85rem;
}
.btn-primary:hover { background: var(--red-deep); border-color: var(--red-deep); }

/* Stamp submit button — the signature element */
.stamp-btn {
  display: block;
  margin: 26px auto 0;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
}

.stamp-ring {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 108px;
  height: 108px;
  border-radius: 50%;
  border: 3px solid var(--red);
  color: var(--red);
  font-family: var(--font-stamp);
  font-size: 0.85rem;
  letter-spacing: 0.03em;
  transform: rotate(-6deg);
  transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.stamp-btn:hover .stamp-ring {
  transform: rotate(-6deg) scale(1.04);
  background: var(--red);
  color: var(--paper);
}
.stamp-btn:active .stamp-ring {
  transform: rotate(-6deg) scale(0.96);
}
.stamp-btn:disabled { cursor: progress; opacity: 0.6; }

.form-msg {
  text-align: center;
  min-height: 1.2em;
  margin: 14px 0 0;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--stamp-green);
}
.form-msg.is-error { color: var(--red); }

/* ============================================================
   Entries ledger list
   ============================================================ */
.section-heading { margin-bottom: 14px; }

.empty-state {
  font-size: 0.9rem;
  color: var(--ink-soft);
  font-style: italic;
  padding: 10px 0;
}

.entries-list { display: flex; flex-direction: column; }

.entry-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--paper-line);
}
.entry-row:first-child { padding-top: 0; }

.entry-thumb {
  width: 52px;
  height: 52px;
  border-radius: var(--radius);
  object-fit: cover;
  border: 1px solid var(--paper-line);
  flex-shrink: 0;
  background: var(--paper-card);
  cursor: zoom-in;
}

.entry-meta { flex: 1; min-width: 0; }

.entry-date {
  font-family: var(--font-mono);
  font-size: 0.92rem;
  color: var(--ink);
}

.entry-index {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--gold);
  letter-spacing: 0.05em;
}

/* ============================================================
   Settings drawer
   ============================================================ */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 42, 56, 0.45);
  display: flex;
  justify-content: flex-end;
  z-index: 20;
}
.drawer-overlay[hidden] { display: none; }

.drawer {
  width: min(360px, 88vw);
  height: 100%;
  background: var(--paper);
  border-left: 2px solid var(--red);
  padding: 22px 20px 30px;
  overflow-y: auto;
  animation: slide-in 0.22s ease;
}

@keyframes slide-in {
  from { transform: translateX(24px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.drawer-head h2 {
  font-family: var(--font-stamp);
  font-weight: 400;
  font-size: 1.25rem;
  margin: 0;
}

.drawer-foot {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--paper-line);
  text-align: center;
}

#settings-msg { text-align: left; }

/* ============================================================
   Stamp confirmation overlay (the signature moment)
   ============================================================ */
.stamp-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  z-index: 30;
}

.stamp-graphic {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  border: 6px solid var(--stamp-green);
  color: var(--stamp-green);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-stamp);
  font-size: 1.5rem;
  letter-spacing: 0.06em;
  transform: scale(2.4) rotate(-18deg);
  opacity: 0;
}

.stamp-overlay.is-active {
  animation: stamp-flash 0.7s ease forwards;
}
.stamp-overlay.is-active .stamp-graphic {
  animation: stamp-down 0.55s cubic-bezier(.2,.9,.3,1.2) forwards;
}

@keyframes stamp-flash {
  0% { opacity: 0; }
  10% { opacity: 1; }
  75% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes stamp-down {
  0% { transform: scale(2.4) rotate(-18deg); opacity: 0; }
  55% { transform: scale(0.92) rotate(-10deg); opacity: 1; }
  70% { transform: scale(1.05) rotate(-10deg); }
  100% { transform: scale(1) rotate(-10deg); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .icon-btn:hover, .stamp-btn:hover .stamp-ring, .stamp-btn:active .stamp-ring {
    transform: none;
  }
  .stamp-overlay.is-active,
  .stamp-overlay.is-active .stamp-graphic,
  .drawer {
    animation: none;
    opacity: 1;
  }
}

/* ============================================================
   Small screens
   ============================================================ */
@media (max-width: 380px) {
  .app { padding-left: 34px; }
  .margin-rule { left: 12px; }
  .stamp-ring { width: 92px; height: 92px; }
}
