:root {
  --bg: #f7f5f1; --surface: #fff; --text: #1d1b18; --muted: #6f6a62; --line: #e3ded5;
  --accent: #b4532a; --accent-text: #fff; --ok: #2f7d4f; --warn: #a56a00; --danger: #b3261e;
  --radius: 10px; --serif: Georgia, "Iowan Old Style", "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #17150f; --surface: #221f19; --text: #ede8df; --muted: #a39d92; --line: #36322a;
          --accent: #e07a4a; --accent-text: #17150f; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.55 var(--sans); }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; }
h2 { font-size: 1.2rem; margin: 1.4rem 0 .6rem; }
h2:first-child { margin-top: 0; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 1rem;
       padding: .8rem 1.25rem; border-bottom: 1px solid var(--line); background: var(--surface); }
.brand { font-family: var(--serif); font-size: 1.25rem; font-weight: 700; color: var(--text); text-decoration: none; }
.top nav { display: flex; gap: 1rem; align-items: center; }
.top nav a { color: var(--text); text-decoration: none; }
.wrap { max-width: 1040px; margin: 0 auto; padding: 1.5rem 16px 4rem; }
.wide { max-width: 1400px; margin: 0 auto; padding: 1.5rem 16px 4rem; }
.narrow { max-width: 520px; margin: 2rem auto; }
.center { text-align: center; }
.pagetitle { margin: 0 0 1rem; }
.muted { color: var(--muted); } .small { font-size: .87rem; } .nowrap { white-space: nowrap; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.inline { display: inline; margin: 0; }

input, textarea, select { font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: .55rem .7rem; width: 100%; }
input[type=checkbox] { width: auto; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.row input { width: auto; flex: 1; min-width: 10rem; }
label { display: block; margin: 0 0 .8rem; font-size: .92rem; color: var(--muted); }
label input, label textarea { margin-top: .25rem; color: var(--text); }
label.check { display: flex; gap: .5rem; align-items: center; color: var(--text); }

.btn { display: inline-block; font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--surface);
       color: var(--text); padding: .55rem 1rem; border-radius: 8px; cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.linkbtn { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: 0 .3rem; text-decoration: underline; }
.iconbtn { background: none; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); cursor: pointer; padding: 0 .45rem; }
.iconbtn.danger:hover { color: var(--danger); border-color: var(--danger); }

.flash { padding: .7rem 1rem; border-radius: 8px; margin: 0 0 1rem; border: 1px solid var(--line); background: var(--surface); }
.flash.ok { border-color: var(--ok); } .flash.error { border-color: var(--danger); color: var(--danger); }
.flash.warn { border-color: var(--warn); }
.tag { font-size: .8rem; padding: .1rem .5rem; border-radius: 99px; border: 1px solid var(--line); white-space: nowrap; }
.tag.ok { color: var(--ok); border-color: var(--ok); } .tag.warn { color: var(--warn); border-color: var(--warn); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; align-items: start; }
@media (max-width: 800px) { .cols { grid-template-columns: 1fr; } }

/* shop */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 1.4rem; }
.card { text-decoration: none; color: var(--text); }
.card .cover { aspect-ratio: 2/3; border-radius: 6px; overflow: hidden; box-shadow: 0 6px 18px rgba(0,0,0,.14); }
.card:hover .cover { transform: translateY(-3px); transition: transform .15s; }
.cover img, .bookcover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.nocover { height: 100%; display: flex; align-items: center; justify-content: center; text-align: center; padding: 1rem;
           background: linear-gradient(160deg, var(--accent), #5b2a14); color: #fff; font-family: var(--serif); font-size: 1.2rem; }
.nocover.big { aspect-ratio: 2/3; font-size: 1.8rem; border-radius: 8px; }
.cardbody { display: flex; flex-direction: column; padding: .6rem 0; gap: .1rem; }
.price { font-weight: 700; color: var(--accent); } .price.big { font-size: 1.6rem; }
.bookpage { display: grid; grid-template-columns: 300px 1fr; gap: 2.5rem; align-items: start; }
@media (max-width: 760px) { .bookpage { grid-template-columns: 1fr; } .bookcover { max-width: 240px; } }
.bookcover img { border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.18); height: auto; }
.bookinfo h1 { margin: 0 0 .3rem; font-size: 2rem; }
.subtitle { font-size: 1.15rem; margin: 0 0 .3rem; }
.buybox { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; margin: 1.5rem 0; }
.buybox .btn { width: 100%; }
.toclist { color: var(--muted); }
.dlbuttons { display: flex; gap: .8rem; justify-content: center; margin: 1.5rem 0; flex-wrap: wrap; }

/* admin */
table.list { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.list th, .list td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.list th { font-size: .82rem; color: var(--muted); font-weight: 600; }
@media (max-width: 760px) { table.list { display: block; overflow-x: auto; } }
.chapters { padding-left: 1.3rem; }
.chapters li { padding: .35rem 0; border-bottom: 1px dashed var(--line); }
.chapters .actions { float: right; }
.thumb { max-width: 120px; border-radius: 6px; display: block; margin: 0 0 .8rem; }
details { margin: 1rem 0; } summary { cursor: pointer; color: var(--muted); }
.danger-zone summary { color: var(--danger); }
.titleinput { font-family: var(--serif); font-size: 1.5rem; font-weight: 600; border: 0; background: transparent; padding: .2rem 0; flex: 1; }
.toolbar { display: flex; gap: .3rem; align-items: center; flex-wrap: wrap; margin: .8rem 0 .5rem; }
.toolbar button { font: inherit; min-width: 2.2rem; padding: .25rem .5rem; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 6px; cursor: pointer; }
.editor { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; height: calc(100vh - 220px); min-height: 420px; }
@media (max-width: 900px) { .editor { grid-template-columns: 1fr; height: auto; } .editor textarea { min-height: 60vh; } .preview { display: none; } }
.editor textarea { height: 100%; resize: none; font: 15px/1.6 ui-monospace, "SF Mono", Menlo, Consolas, monospace; padding: 1rem; }
.preview { overflow-y: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 1rem 1.6rem;
           font-family: var(--serif); font-size: 1.05rem; line-height: 1.65; }
.preview img { max-width: 100%; }
.preview blockquote { border-left: 3px solid var(--line); margin-left: 0; padding-left: 1rem; color: var(--muted); font-style: italic; }
.desc { margin: 1rem 0; }

.mailbox { margin: 0 0 1rem; padding: .8rem 1rem; }
