:root {
  --primary: #6b4226;
  --secondary: #f5e6d3;
  --accent: #d4a843;
  --leather-dark: #5a3720;
  --ink: #4a2f1b;
  --paper-edge: #ecd9bd;
  --danger: #a33a2b;
  --shadow: rgba(60, 36, 16, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: #2c1a0d;
  font-family: Georgia, "Times New Roman", serif;
  color: var(--ink);
  display: flex;
  justify-content: center;
}

/* ---------- Diary shell ---------- */
.diary {
  position: relative;
  width: 100%;
  max-width: 520px;
  height: 100dvh;
  background:
    radial-gradient(circle at 12% 18%, rgba(0,0,0,0.18), transparent 60%),
    linear-gradient(115deg, #7a4f2e 0%, var(--primary) 30%, #5d3a22 70%, #7a4f2e 100%);
  box-shadow: 0 0 0 6px #2c1a0d;
}

.leather {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 14px;
  background:
    repeating-linear-gradient(90deg,
      rgba(0,0,0,0.06) 0 2px, transparent 2px 6px);
}

.spine {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 20px;
  background: linear-gradient(90deg, #3f2716, #5d3a22 60%, #6b4226);
  box-shadow: inset -3px 0 6px rgba(0,0,0,0.5);
  border-radius: 14px 0 0 14px;
}

.paper {
  position: absolute;
  top: 12px;
  bottom: 76px;
  left: 26px;
  right: 12px;
  background:
    repeating-linear-gradient(0deg, transparent 0 27px,
      rgba(107,66,38,0.06) 28px),
    var(--secondary);
  border-radius: 12px;
  box-shadow: 0 8px 24px var(--shadow), inset 0 0 0 1px var(--paper-edge);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
}

/* ---------- Tabs / pages ---------- */
.tab { animation: fade 0.22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

.app-title {
  font-family: Georgia, serif;
  font-weight: 700;
  color: var(--primary);
  margin: 8px 0 2px;
  font-size: 30px;
  letter-spacing: 0.5px;
}
.tagline { color: #8a6a4f; font-size: 13px; margin: 0 0 18px; font-style: italic; }

.page-title {
  color: var(--primary);
  font-size: 24px;
  margin: 4px 0 6px;
  border-bottom: 2px solid var(--accent);
  padding-bottom: 6px;
}

/* ---------- Gold number plates ---------- */
.plates {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 10px 0 20px;
}

.plate {
  background:
    radial-gradient(circle at 30% 20%, #f0d47f, transparent 55%),
    linear-gradient(160deg, #d4a843, #a87f2a);
  border: 1px solid #8a6a2c;
  border-radius: 10px;
  padding: 16px 10px 12px;
  text-align: center;
  box-shadow: 0 4px 10px var(--shadow), inset 0 1px 0 rgba(255,255,255,0.5);
  color: #3a250d;
}

.plate-num {
  display: block;
  font-size: 40px;
  font-weight: 700;
  line-height: 1;
  font-family: Georgia, serif;
}
.plate-label {
  display: block;
  margin-top: 6px;
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  font-family: "Courier New", monospace;
  color: #3a250d;
}

/* ---------- Record button (brass clasp) ---------- */
.record-btn {
  display: block;
  width: 100%;
  margin: 6px 0 6px;
  padding: 15px 18px;
  font-family: Georgia, serif;
  font-size: 17px;
  color: #2c1a0d;
  border: 2px solid #8a6a2c;
  border-radius: 12px;
  cursor: pointer;
  background:
    radial-gradient(circle at 50% 30%, #eccf83, transparent 60%),
    linear-gradient(180deg, #d4a843, #b58a33);
  box-shadow: 0 4px 12px var(--shadow), inset 0 1px 0 rgba(255,255,255,0.5);
}
.record-btn:active { transform: translateY(1px); }

.hint { color: #8a6a4f; font-size: 12px; text-align: center; font-style: italic; }

/* ---------- Search ---------- */
.search {
  width: 100%;
  padding: 11px 12px;
  margin-bottom: 14px;
  font-family: "Courier New", monospace;
  font-size: 14px;
  color: var(--ink);
  background: #fdf3e4;
  border: 1.5px solid var(--primary);
  border-radius: 8px;
  outline: none;
}
.search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(212,168,67,0.25); }

/* ---------- Ticket stubs ---------- */
.list { display: flex; flex-direction: column; gap: 14px; }

.stub {
  position: relative;
  background: #fbf1e1;
  padding: 14px 52px 14px 14px;
  border-radius: 6px;
  border-top: 2px dashed #b99b6b;
  border-bottom: 2px dashed #b99b6b;
  cursor: pointer;
  box-shadow: 0 3px 8px rgba(90,55,32,0.18);
}
.stub:active { background: #f4e5cf; }

.stub h3 {
  margin: 0 0 4px;
  font-family: Georgia, serif;
  font-size: 17px;
  color: var(--primary);
}
.stub .exh {
  margin: 0 0 4px;
  font-style: italic;
  color: #7d5a3c;
  font-size: 14px;
}
.stub .date {
  margin: 0;
  font-family: "Courier New", monospace;
  font-size: 13px;
  color: #9c6f45;
}
.stub .piece {
  margin: 6px 0 0;
  font-size: 12px;
  color: #8a6a4f;
}

/* engraved pillar icon */
.pillar {
  position: absolute;
  top: 50%;
  right: 14px;
  transform: translateY(-50%);
  width: 12px;
  height: 10px;
  border: 2px solid #a87f2a;
  border-radius: 0 0 4px 4px;
  opacity: 0.75;
}
.pillar::before {
  content: "";
  position: absolute;
  top: -7px;
  left: -1px;
  width: 14px;
  height: 8px;
  border: 2px solid #a87f2a;
  border-radius: 8px 8px 0 0;
  border-bottom: none;
}

.empty { color: #8a6a4f; font-style: italic; text-align: center; }

/* ---------- Stamp album ---------- */
.stamp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 14px;
}

.stamp {
  background: #e8d9be;
  padding: 8px;
  border-radius: 6px;
  border: 3px dashed #fff;
  box-shadow: 0 3px 8px rgba(90,55,32,0.25);
  text-align: center;
}

.stamp-inner {
  background: var(--stamp-bg, #d4a843);
  border-radius: 3px;
  padding: 14px 8px 10px;
  color: #3a250d;
}

.stamp-dome {
  width: 34px;
  height: 20px;
  margin: 0 auto 0;
  background: #3a250d;
  border-radius: 18px 18px 0 0;
}
.stamp-body {
  width: 26px;
  height: 26px;
  margin: 0 auto 6px;
  background: #3a250d;
  border-radius: 0 0 3px 3px;
  position: relative;
}
.stamp-body::after {
  content: "";
  position: absolute;
  left: 8px;
  top: 6px;
  width: 10px;
  height: 13px;
  background: var(--stamp-bg, #d4a843);
  border-radius: 6px 6px 0 0;
}

.stamp-oval {
  width: 90%;
  margin: 6px auto 4px;
  border: 1.5px solid #3a250d;
  border-radius: 50%;
  padding: 3px 4px;
  font-size: 9px;
  line-height: 1.1;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-family: "Courier New", monospace;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.stamp-date {
  font-size: 10px;
  font-family: "Courier New", monospace;
  margin-top: 3px;
  opacity: 0.85;
}

/* ---------- Form ---------- */
.form { display: flex; flex-direction: column; gap: 14px; margin-top: 8px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field span {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #7d5a3c;
  font-family: "Courier New", monospace;
}
.field input {
  padding: 11px 12px;
  font-size: 16px;
  color: var(--ink);
  background: #fdf3e4;
  border: 1.5px solid var(--primary);
  border-radius: 8px;
  outline: none;
  font-family: Georgia, serif;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(212,168,67,0.25); }

.form-error {
  color: var(--danger);
  font-size: 13px;
  margin: 0;
  text-align: center;
}

.primary-btn {
  padding: 14px;
  font-family: Georgia, serif;
  font-size: 16px;
  color: #2c1a0d;
  background: linear-gradient(180deg, #d4a843, #b58a33);
  border: 2px solid #8a6a2c;
  border-radius: 10px;
  cursor: pointer;
  box-shadow: 0 3px 10px var(--shadow);
}
.primary-btn:active { transform: translateY(1px); }

/* ---------- Bottom tab bar ---------- */
.tabbar {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: calc(8px + env(safe-area-inset-bottom));
  height: 60px;
  background: linear-gradient(180deg, #7a4f2e, #5a3720);
  border: 2px solid #3f2716;
  border-radius: 14px;
  box-shadow: 0 -3px 12px var(--shadow);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 5;
}

.tab-btn {
  flex: 1;
  height: 100%;
  background: none;
  border: none;
  color: #e7d6b8;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  font-family: "Courier New", monospace;
  font-size: 9px;
  letter-spacing: 0.5px;
  position: relative;
}

.rivet {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f2dd9c, #b58a33 70%, #8a6a2c);
  border: 2px solid #6b4a1e;
  box-shadow: 0 2px 5px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.6);
  position: relative;
}
.rivet::after {
  content: "";
  position: absolute;
  left: 3px;
  right: 3px;
  top: 8px;
  height: 2px;
  background: #8a6a2c;
  border-radius: 2px;
}

.tab-btn.active { color: var(--accent); }
.tab-btn.active .rivet {
  background: radial-gradient(circle at 35% 30%, #ffe9a8, #d4a843 70%, #a87f2a);
  border-color: #d4a843;
}

/* silk ribbon loop threaded through active rivet */
.tab-btn.active .rivet::before {
  content: "";
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  width: 18px;
  height: 16px;
  border: 3px solid var(--accent);
  border-radius: 10px 10px 0 0;
  border-bottom: none;
  opacity: 0.9;
}

.tab-label { line-height: 1; }

/* ---------- Overlay / edit ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(28,16,7,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.overlay-panel {
  width: 100%;
  max-width: 440px;
  background: var(--secondary);
  border: 2px solid var(--primary);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 12px 34px rgba(0,0,0,0.5);
  max-height: 90dvh;
  overflow-y: auto;
}

.btn-row { display: flex; gap: 10px; }
.btn-row .primary-btn { flex: 2; }

.danger-btn {
  flex: 1;
  padding: 14px;
  font-family: Georgia, serif;
  font-size: 16px;
  color: #fdf3e4;
  background: var(--danger);
  border: 2px solid #7d2c20;
  border-radius: 10px;
  cursor: pointer;
}

.ghost-btn {
  padding: 10px;
  font-family: Georgia, serif;
  font-size: 14px;
  color: #7d5a3c;
  background: none;
  border: 1.5px solid #b99b6b;
  border-radius: 8px;
  cursor: pointer;
}

@media (min-width: 520px) {
  body { padding: 14px 0; }
  .diary { height: calc(100dvh - 28px); }
}