/* ============ InkTrail ============ */
:root {
  --bg: #fafaf8;
  --paper: #ffffff;
  --paper-line: #ececea;
  --ink: #1c1c1a;
  --ink-soft: #6b6b66;
  --ink-faint: #a3a39c;
  --accent: #d64533;
  --accent-soft: #fbeae7;
  --border: #e4e4e0;
  --shadow: 0 1px 3px rgba(0,0,0,.07), 0 4px 14px rgba(0,0,0,.05);
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans", "Noto Sans JP", sans-serif;
  --font-serif: "Iowan Old Style", "Hiragino Mincho ProN", "Yu Mincho", Georgia, serif;
  /* paper is physical: it stays light in every theme */
  --stamp-paper: #fdfcf6;
  --stamp-rule: rgba(90, 130, 180, .18);
  --stamp-margin: rgba(214, 69, 51, .25);
}

[data-theme="washi"] {
  --bg: #f5efe2;
  --paper: #fbf6ea;
  --paper-line: #eadfc8;
  --ink: #33302a;
  --ink-soft: #7a7264;
  --ink-faint: #a89d88;
  --accent: #b7332c;
  --accent-soft: #f3e0d8;
  --border: #e2d8c2;
  --stamp-paper: #fbf6ea;
  --stamp-rule: rgba(150, 110, 60, .18);
}

[data-theme="dark"] {
  --bg: #15151a;
  --paper: #1e1e24;
  --paper-line: #2a2a32;
  --ink: #ececea;
  --ink-soft: #9a9aa2;
  --ink-faint: #62626a;
  --accent: #e8564a;
  --accent-soft: #3a2320;
  --border: #2c2c34;
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.3);
  --stamp-paper: #f4f0e3;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  overscroll-behavior-y: none;
  display: flex;
  flex-direction: column;
}

/* ---- Top bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 18px 12px;
  background: var(--bg);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark { color: var(--accent); }
.brand-name { font-size: 19px; font-weight: 650; letter-spacing: -0.02em; }
.icon-btn {
  background: none; border: none; color: var(--ink-soft); cursor: pointer;
  width: 38px; height: 38px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: var(--border); }
.icon-btn.danger { color: var(--accent); }
.top-actions { display: flex; gap: 2px; }

/* ---- Views ---- */
.view { flex: 1; display: none; overflow-y: auto; position: relative; }
.view.active { display: block; }
#view-notebook.active { display: flex; flex-direction: column; overflow: hidden; }

/* ---- Album ---- */
#album-content { padding: 4px 18px 110px; max-width: 640px; margin: 0 auto; }
.album-day { margin-top: 18px; }
.album-day-label {
  display: flex; align-items: center; gap: 10px;
  font-size: 12.5px; font-weight: 600; letter-spacing: .06em;
  color: var(--ink-faint); text-transform: uppercase;
  margin-bottom: 10px;
}
.album-day-label::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.album-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.album-cell {
  background: var(--paper); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--border);
  padding: 12px 10px 10px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  transition: transform .12s ease;
}
.album-cell:active { transform: scale(.97); }
.album-cell img {
  width: 100%; aspect-ratio: 1; object-fit: contain;
  background: var(--stamp-paper); border-radius: 8px; padding: 7px; box-sizing: border-box;
}
.album-cell .cell-name {
  font-size: 12.5px; font-weight: 550; color: var(--ink);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.album-cell .cell-loc { font-size: 11px; color: var(--ink-faint); margin-top: -5px; }

/* ---- Empty state ---- */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 80px 32px; gap: 10px; color: var(--ink-soft);
}
.empty-stamp { color: var(--ink-faint); margin-bottom: 6px; }
.empty-state h2 { font-size: 20px; font-weight: 650; color: var(--ink); }
.empty-state p { font-size: 14.5px; max-width: 260px; line-height: 1.55; }
.hidden { display: none !important; }

/* ---- Notebook: continuous = the same pages, scrolled left-to-right ---- */
#notebook-scroll {
  flex: 1; overflow-x: auto; overflow-y: hidden;
  background: var(--bg); padding: 12px 14px;
}
#notebook-canvas.strip {
  position: relative;
  background: var(--stamp-paper);
  border-radius: 12px;
  box-shadow: 0 2px 6px rgba(0,0,0,.10), 0 12px 34px rgba(0,0,0,.15);
}
.page-crease {
  position: absolute; top: 0; bottom: 0; width: 1px;
  background: rgba(120, 100, 70, .20);
  box-shadow: 0 0 8px 1px rgba(120, 100, 70, .10);
  pointer-events: none;
}
.strip-pageno { right: auto; }

/* ---- Notebook: pages = a real book that turns ---- */
#notebook-scroll.pages { overflow: hidden; display: flex; padding: 14px 14px 6px; }
#notebook-canvas.book {
  position: relative;
  flex: 1; min-height: 0; max-width: none;
  background: transparent; box-shadow: none; border-radius: 0;
  perspective: 1600px;
}
.book-spread {
  position: absolute; inset: 0;
  display: flex; justify-content: center;
  transform-origin: 50% 0;
}
.book-pages {
  position: relative; display: flex; height: 100%;
}
.book-page {
  position: relative;
  flex: 0 0 auto; height: 100%;
  background: var(--stamp-paper);
  border-radius: 10px;
  box-shadow: 0 2px 6px rgba(0,0,0,.10), 0 12px 34px rgba(0,0,0,.15);
}
@media (min-width: 1000px) {
  /* facing pages share a spine (book mode only) */
  .book-spread .book-page:first-child:not(:only-child) {
    border-radius: 12px 2px 2px 12px;
    box-shadow: 0 2px 6px rgba(0,0,0,.10), 0 12px 34px rgba(0,0,0,.15), inset -22px 0 26px -20px rgba(100,80,50,.45);
  }
  .book-spread .book-page:last-child:not(:only-child) {
    border-radius: 2px 12px 12px 2px;
    box-shadow: 0 2px 6px rgba(0,0,0,.10), 0 12px 34px rgba(0,0,0,.15), inset 22px 0 26px -20px rgba(100,80,50,.45);
  }
}
.book-pageno {
  position: absolute; bottom: 10px; right: 16px;
  font-size: 12px; font-weight: 600; letter-spacing: .06em;
  color: rgba(120, 100, 70, .5);
  font-family: var(--font-serif);
  pointer-events: none;
}
.book-ghost { pointer-events: none; z-index: 5; }
.turn-up { animation: pageup .45s ease-in forwards; }
@keyframes pageup {
  to { transform: rotateX(76deg) translateY(-30px); opacity: 0; }
}
.turn-down { animation: pagedown .45s ease-out; }
@keyframes pagedown {
  from { transform: rotateX(76deg) translateY(-30px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

#book-nav {
  display: flex; align-items: center; justify-content: center; gap: 16px;
  padding: 8px 0 10px; background: var(--bg);
}
#book-nav button {
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--paper); color: var(--ink);
  font-size: 22px; line-height: 1; cursor: pointer;
}
#book-nav button:disabled { opacity: .3; }
#nb-pageinfo {
  font-size: 12.5px; font-weight: 600; color: var(--ink-soft);
  min-width: 56px; text-align: center;
}
.nb-stamp {
  position: absolute; touch-action: none; cursor: grab;
  user-select: none; -webkit-user-drag: none; z-index: 1;
}
.nb-stamp img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; -webkit-user-drag: none; }
.nb-stamp.selected { outline: 2px dashed var(--accent); outline-offset: 6px; border-radius: 4px; }
.nb-stamp.dragging { cursor: grabbing; z-index: 30; }

.stamp-toolbar {
  position: absolute; bottom: calc(env(safe-area-inset-bottom, 0px) + 86px);
  left: 50%; transform: translateX(-50%);
  display: flex; gap: 4px; padding: 6px;
  background: var(--paper); border: 1px solid var(--border);
  border-radius: 999px; box-shadow: var(--shadow); z-index: 40;
}
.stamp-toolbar button {
  width: 42px; height: 42px; border-radius: 50%; border: none;
  background: none; color: var(--ink); font-size: 18px; cursor: pointer;
}
.stamp-toolbar button:active { background: var(--accent-soft); }

/* ---- Tab bar ---- */
.tabbar {
  display: flex; align-items: center; justify-content: space-around;
  padding: 8px 24px calc(env(safe-area-inset-bottom, 0px) + 10px);
  background: var(--paper); border-top: 1px solid var(--border);
  position: relative; z-index: 25;
}
.tab {
  background: none; border: none; color: var(--ink-faint); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 11px; font-weight: 550; font-family: var(--font);
  padding: 4px 18px; border-radius: 12px;
}
.tab.active { color: var(--accent); }
.fab {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: #fff; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(214,69,51,.35);
  margin-top: -26px;
  transition: transform .12s ease;
}
.fab:active { transform: scale(.93); }

/* ---- Bottom sheet ---- */
.sheet { position: fixed; inset: 0; z-index: 60; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.35); }
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--paper); border-radius: 22px 22px 0 0;
  padding: 10px 20px calc(env(safe-area-inset-bottom, 0px) + 22px);
  animation: sheetup .22s ease;
}
@keyframes sheetup { from { transform: translateY(40%); opacity: .5; } to { transform: none; opacity: 1; } }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 4px auto 14px; }
.sheet-body h3 { font-size: 17px; font-weight: 650; margin-bottom: 14px; }
.sheet-option {
  display: flex; align-items: center; gap: 14px; width: 100%;
  background: none; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; margin-bottom: 10px; cursor: pointer; text-align: left;
  font-family: var(--font); color: var(--ink);
}
.sheet-option:active { background: var(--accent-soft); }
.opt-icon {
  width: 46px; height: 46px; border-radius: 12px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.opt-icon-red { background: var(--accent-soft); color: var(--accent); }
.opt-icon-blue { background: #e8f0fb; color: #2d6cb5; }
[data-theme="dark"] .opt-icon-blue { background: #1f2a3a; color: #7fb0e8; }
.opt-text { display: flex; flex-direction: column; gap: 2px; }
.opt-text strong { font-size: 15px; font-weight: 600; }
.opt-text small { font-size: 12.5px; color: var(--ink-soft); line-height: 1.4; }

/* ---- Modals (editor / detail / settings) ---- */
.modal {
  position: fixed; inset: 0; z-index: 70;
  background: var(--bg);
  display: flex; flex-direction: column;
  animation: fadein .18s ease;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.modal-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 10px;
}
.modal-top h3 { font-size: 16.5px; font-weight: 650; }

/* Editor */
.editor-preview-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 16px; overflow: hidden; }
.editor-paper {
  background-color: var(--stamp-paper);
  background-image: linear-gradient(var(--stamp-rule) 1px, transparent 1px);
  background-size: 100% 26px;
  border-radius: 10px; box-shadow: var(--shadow); border: 1px solid var(--border);
  padding: 26px; max-width: 90%; max-height: 100%;
  display: flex; align-items: center; justify-content: center;
}
#editor-canvas { max-width: 100%; max-height: 46vh; }
.editor-controls { padding: 6px 22px; display: flex; flex-direction: column; gap: 14px; }
.ctl-row { display: flex; align-items: center; gap: 12px; }
.ctl-row label { font-size: 13px; font-weight: 550; color: var(--ink-soft); width: 84px; flex-shrink: 0; }
.ctl-row input[type=range] { flex: 1; accent-color: var(--accent); }
.chip-row { display: flex; gap: 8px; flex: 1; flex-wrap: wrap; }
.chip {
  border: 1.5px solid var(--border); background: var(--paper); color: var(--ink-soft);
  border-radius: 999px; padding: 7px 14px; font-size: 13px; font-weight: 550;
  cursor: pointer; font-family: var(--font);
}
.chip.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.ink-dot {
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer;
  border: 2.5px solid transparent; padding: 0; background-clip: padding-box;
}
.ink-dot.active { border-color: var(--ink); }
.editor-actions { padding: 10px 22px calc(env(safe-area-inset-bottom, 0px) + 18px); }
.btn-primary {
  width: 100%; padding: 15px; border: none; border-radius: var(--radius);
  background: var(--accent); color: #fff; font-size: 16px; font-weight: 650;
  font-family: var(--font); cursor: pointer;
  transition: transform .1s ease;
}
.btn-primary:active { transform: scale(.98); }
#btn-empty-add { width: auto; padding: 13px 26px; margin-top: 10px; }

/* Detail */
.detail-scroll { flex: 1; overflow-y: auto; padding: 4px 20px calc(env(safe-area-inset-bottom, 0px) + 24px); }
.detail-paper {
  background-color: var(--stamp-paper);
  background-image: linear-gradient(var(--stamp-rule) 1px, transparent 1px);
  background-size: 100% 26px;
  border-radius: 10px; border: 1px solid var(--border); box-shadow: var(--shadow);
  padding: 30px; display: flex; align-items: center; justify-content: center;
  margin-bottom: 20px;
}
.detail-paper img { max-width: 100%; max-height: 38vh; }
.detail-fields { display: flex; flex-direction: column; gap: 14px; max-width: 560px; margin: 0 auto; }
.detail-fields label { font-size: 12.5px; font-weight: 600; color: var(--ink-faint); display: flex; flex-direction: column; gap: 6px; letter-spacing: .03em; text-transform: uppercase; }
.detail-fields input, .detail-fields textarea {
  font-family: var(--font); font-size: 15px; color: var(--ink);
  background: var(--paper); border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 13px; outline: none; resize: none;
}
.detail-fields input:focus, .detail-fields textarea:focus { border-color: var(--accent); }
.detail-fields textarea { font-family: var(--font-serif); font-size: 16px; line-height: 1.6; }
.detail-meta { font-size: 12.5px; color: var(--ink-faint); display: flex; flex-direction: column; gap: 4px; padding-top: 4px; }

/* Settings */
.settings-body { padding: 10px 22px; }
.settings-body h4 { font-size: 13px; font-weight: 600; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .05em; margin: 18px 0 12px; }
.theme-row { display: flex; gap: 10px; }
.theme-chip, .flow-chip {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: var(--paper); border: 1.5px solid var(--border); border-radius: var(--radius);
  padding: 14px 18px; font-size: 13px; font-weight: 550; color: var(--ink-soft);
  cursor: pointer; font-family: var(--font); flex: 1;
}
.theme-chip.active, .flow-chip.active { border-color: var(--accent); color: var(--accent); }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 1px solid rgba(0,0,0,.1); }
.sw-modern { background: linear-gradient(135deg, #fafaf8 50%, #d64533 50%); }
.sw-washi { background: linear-gradient(135deg, #f5efe2 50%, #b7332c 50%); }
.sw-dark { background: linear-gradient(135deg, #15151a 50%, #e8564a 50%); }
.settings-about { font-size: 14px; color: var(--ink-soft); line-height: 1.6; }

/* Desktop niceties */
@media (min-width: 700px) {
  .sheet-body { max-width: 480px; left: 50%; transform: translateX(-50%); border-radius: 22px; bottom: 24px; }
  .modal { max-width: 720px; margin: 0 auto; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}
