:root {
  color-scheme: light;
  --page: #f6f8f5;
  --paper: #fff;
  --ink: #172823;
  --muted: #4f655d;
  --line: #d3ded6;
  --soft: #edf4ee;
  --accent: #205344;
  --active: #164034;
  --danger: #953329;
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: var(--page);
  font-synthesis: none;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font-size: 15px; line-height: 1.5; }
h1, h2, h3, p, ol { margin: 0; }
h1, h2, h3 { line-height: 1.16; overflow-wrap: anywhere; }
h1 { font-size: clamp(1.75rem, 3.4vw, 2.625rem); letter-spacing: -.04em; font-weight: 720; }
h2 { font-size: 1.35rem; letter-spacing: -.025em; font-weight: 700; }
button, input, textarea, select { font: inherit; }
a { color: var(--accent); }
button, summary { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid #327b63; outline-offset: 3px; }

.top { border-bottom: 1px solid var(--line); background: var(--paper); }
.top-inner, .wrap { width: min(1320px, calc(100% - 64px)); margin-inline: auto; }
.top-inner { display: flex; align-items: center; gap: 20px; min-height: 65px; }
.brand { display: inline-flex; align-items: center; gap: 11px; color: var(--ink); text-decoration: none; font-size: 22px; font-weight: 810; letter-spacing: -.07em; }
.brand-mark { position: relative; display: inline-block; width: 31px; height: 31px; border-radius: 8px; background: var(--accent); }
.brand-mark::before, .brand-mark::after { content: ""; position: absolute; top: 8px; width: 8px; height: 15px; background: #fff; }
.brand-mark::before { left: 7px; transform: skewY(14deg); border-radius: 2px 1px 1px 2px; }
.brand-mark::after { right: 7px; transform: skewY(-14deg); border-radius: 1px 2px 2px 1px; }
.top-label { color: var(--muted); border-left: 1px solid var(--line); padding-left: 20px; }
.top-action { margin-left: auto; }
.wrap { padding-block: 36px 56px; }
.centered { width: min(540px, calc(100% - 36px)); margin: 56px auto; }
.stack { display: grid; gap: 14px; margin-top: 24px; }
.stack > .button { justify-self: start; min-width: 115px; }
.flow { display: grid; gap: 6px; }
.muted, .meta, .rail-count { color: var(--muted); }
.meta { font-size: .9rem; font-weight: 620; }
.helper { margin: 12px 0; font-size: .875rem; }
.page-head, .book-head { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.page-head { margin-bottom: 15px; }
.page-head > .button { flex: none; }
.save-bar { display: flex; align-items: center; gap: 14px; min-height: 30px; margin-bottom: 8px; font-size: .875rem; }
.notice { border: 1px solid var(--line); background: var(--soft); border-radius: 8px; padding: 12px 14px; margin: 12px 0; overflow-wrap: anywhere; }
.notice.error { background: #fff5f2; color: var(--danger); border-color: #e9c5ba; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 14px;
  min-height: 44px;
  background: var(--paper);
  color: var(--ink);
  font-weight: 640;
  text-decoration: none;
  line-height: 1.22;
  text-align: center;
}
.button:hover { background: var(--soft); border-color: #9cb3a5; }
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button.primary:hover { background: var(--active); border-color: var(--active); }
.button.small { font-size: .875rem; min-height: 36px; padding: 6px 10px; }
.button:disabled { opacity: .56; }
.text-button { border: 0; background: none; color: var(--accent); padding: 7px 2px; text-decoration: underline; text-underline-offset: 3px; }
.text-button.danger { color: var(--danger); }
.inline-form { display: flex; align-items: center; gap: 9px; }
.inline-form input { flex: 1; min-width: 0; }
.inline-form .button { flex: 0 0 auto; }
label { display: grid; gap: 6px; font-weight: 620; }
input:not([type=file]), textarea, select {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper);
  padding: 8px 11px;
  font-weight: 400;
  color: var(--ink);
}
textarea { resize: vertical; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.workspace { display: grid; grid-template-columns: minmax(190px, 248px) minmax(0, 1fr); align-items: start; gap: 26px; margin-top: 8px; }
.rail { padding-top: 3px; }
.rail-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.rail-top h2 { padding-left: 4px; font-size: 1.12rem; }
.book-list { display: grid; gap: 4px; }
.book-button { border: 1px solid transparent; background: transparent; color: var(--ink); border-radius: 8px; text-align: left; width: 100%; padding: 9px 10px; min-height: 45px; display: flex; align-items: center; gap: 11px; }
.book-button:hover { background: var(--soft); }
.book-button[aria-current=true] { background: #e0eee4; border-color: #accaba; color: #173c32; }
.book-button > .item-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.book-button small { display: block; color: var(--muted); font-size: .79rem; }
.rail-count { margin: 14px 4px 0; font-size: .84rem; }
.folder-symbol { display: inline-block; position: relative; flex: none; width: 20px; height: 14px; border: 1.5px solid currentColor; border-radius: 2px; color: var(--accent); margin-top: 3px; }
.folder-symbol::before { content: ""; position: absolute; left: -1.5px; top: -5px; width: 10px; height: 5px; border: 1.5px solid currentColor; border-bottom: 0; border-radius: 2px 3px 0 0; }
.folder-symbol.large { transform: scale(1.6); margin-bottom: 12px; }
.content-area { min-width: 0; border: 1px solid var(--line); padding: clamp(17px, 3vw, 30px); border-radius: 13px; background: var(--paper); }
.empty-panel { min-height: 315px; padding: 30px 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; }
.empty-panel .button { margin-top: 8px; }
.book-head { margin-bottom: 16px; }
.book-notes { padding-block: 9px; border-block: 1px solid var(--line); }
.book-notes summary { padding: 6px 0; font-weight: 640; color: var(--accent); }
.note-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; padding-block: 10px; }
.upload-drop { padding: 18px 12px; margin-top: 16px; background: var(--page); border-radius: 9px; border: 1px dashed #a5bbae; text-align: center; }
.upload-drop:empty { display: none; }
.upload-drop.drop-active { background: #deeee4; border-color: var(--accent); }
.upload-drop p { margin-top: 7px; font-size: .84rem; }
.transfer { margin-top: 13px; padding: 10px 12px; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 6px 12px; border-radius: 8px; background: var(--soft); }
.transfer progress { width: 100%; height: 9px; accent-color: var(--accent); grid-column: 1 / -1; }
.transfer button { grid-row: 1; grid-column: 2; }

.photo-grid {
  --columns: repeat(auto-fill, minmax(min(100%, 156px), 1fr));
  background: var(--page);
  display: grid;
  grid-template-columns: var(--columns);
  padding: 12px;
  gap: 12px;
  margin-block: 10px;
  border-radius: 9px;
  list-style: none;
}
.photo-grid:empty { display: none; }
.photo-card { min-width: 0; background: var(--paper); border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.photo-card.drag-ghost { opacity: .45; }
.photo-image { position: relative; display: grid; place-content: center; aspect-ratio: 4 / 3; background: #e9efea; border-bottom: 1px solid var(--line); color: var(--muted); }
.photo-image img { position: absolute; width: 100%; height: 100%; object-fit: cover; inset: 0; }
.photo-index { position: absolute; left: 6px; top: 6px; min-width: 30px; padding: 1px 5px; border-radius: 4px; background: #173b32; color: #fff; text-align: center; font-variant-numeric: tabular-nums; font-size: .8rem; }
.photo-placeholder { font-size: .78rem; padding: 6px; text-align: center; }
.photo-placeholder.failed { color: var(--danger); }
.photo-caption { display: flex; align-items: center; padding: 4px 5px; gap: 3px; min-height: 42px; }
.photo-name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; flex: 1; font-size: .8rem; }
.tile-action, .grip { flex: none; display: grid; place-items: center; width: 34px; height: 34px; border: 0; background: transparent; color: var(--accent); border-radius: 6px; font-size: 1.22rem; padding: 0; }
.tile-action:hover, .grip:hover { background: var(--soft); }
.grip { cursor: grab; touch-action: none; }
.grip:active { cursor: grabbing; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 16px; }

.share { background: var(--page); border: 1px solid var(--line); border-radius: 8px; padding: 12px; display: grid; gap: 6px; margin-bottom: 14px; }
.share p:empty { display: none; }
.version-tools, .photo-fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; margin-bottom: 10px; }
.read-note { padding: 10px 12px; background: var(--page); border: 1px solid var(--line); border-radius: 7px; min-width: 0; }
.read-note strong { display: block; font-size: .86rem; margin-bottom: 4px; }
.read-note p { white-space: pre-wrap; overflow-wrap: anywhere; }

dialog { border: 1px solid var(--line); border-radius: 12px; width: min(530px, calc(100% - 28px)); max-height: calc(100dvh - 26px); padding: 0; color: var(--ink); background: var(--paper); }
dialog::backdrop { background: rgba(19, 38, 31, .52); }
.dialog-form { display: grid; padding: 22px; gap: 14px; }
.dialog-actions, .dialog-buttons { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.dialog-actions { justify-content: space-between; }
.dialog-actions .dialog-buttons { margin-left: auto; }
.dialog-form .photo-fields { margin-bottom: 0; }
.file-label { overflow-wrap: anywhere; }
.dialog-preview { display: block; width: 100%; max-height: 24vh; object-fit: contain; border-radius: 6px; background: var(--page); }

@media (max-width: 820px) {
  .top-inner, .wrap { width: calc(100% - 34px); }
  .wrap { padding-top: 24px; }
  .workspace { grid-template-columns: minmax(0, 1fr); gap: 13px; }
  .book-list { display: flex; gap: 6px; overflow-x: auto; padding: 4px 3px 7px; }
  .book-button { width: auto; flex: 0 0 auto; max-width: 260px; background: var(--paper); border: 1px solid var(--line); }
  .rail-top { margin-bottom: 3px; }
  .rail-count { margin-top: 4px; }
  .page-head:has(.inline-form) { align-items: stretch; flex-direction: column; }
  .photo-grid { --columns: repeat(auto-fill, minmax(min(100%, 139px), 1fr)); }
}

@media (max-width: 520px) {
  .top-inner { gap: 11px; min-height: 57px; }
  .top-label { padding-left: 11px; font-size: .8rem; line-height: 1.2; }
  .brand { font-size: 20px; gap: 8px; }
  .page-head { align-items: flex-start; flex-direction: column; gap: 11px; }
  .page-head > .button { width: 100%; }
  .content-area { padding: 13px; }
  .note-fields { grid-template-columns: minmax(0, 1fr); }
  .book-head { gap: 8px; align-items: flex-start; }
  .book-head .button { max-width: 44%; }
  .photo-grid { --columns: repeat(2, minmax(0, 1fr)); padding: 5px; gap: 8px; }
  .photo-caption { padding-inline: 5px; }
  .tile-action, .grip { min-width: 42px; min-height: 44px; }
  .button.small { min-height: 44px; }
  .inline-form .button { padding-inline: 9px; }
  .dialog-form { padding: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0s !important; transition-duration: 0s !important; }
}
