/* My9Books — one screen: wordmark, 3×3 grid of 2:3 book frames sized to the window height, a one-line "Most chosen" strip. */
:root {
  --paper: #eef0ec;
  --surface: #f9faf7;
  --ink: #1d2420;
  --muted: #5f6a63;
  --rule: #c9cfc8;
  --accent: #2f5d48;       /* bookcloth green */
  --accent-ink: #f4f7f2;
  --danger: #9b2f2a;
  --shadow: 0 1px 2px rgba(20,30,25,.12), 0 6px 18px rgba(20,30,25,.10);
  --display: "Young Serif", Georgia, "Times New Roman", serif;
  --body: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #161a18;
    --surface: #1f2421;
    --ink: #e7ebe6;
    --muted: #9aa59e;
    --rule: #39413c;
    --accent: #7fb79a;
    --accent-ink: #10201a;
    --danger: #e0857e;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 22px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 var(--body);
  padding-block: clamp(16px, 3vh, 40px);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
/* Column width follows the window height so header, grid and strip fit on one screen. */
.wrap {
  --fit: clamp(300px, calc((100vh - 345px) / 1.5), 560px);
  --fit: clamp(300px, calc((100dvh - 345px) / 1.5), 560px);
  width: min(100%, var(--fit)); margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px;
}
.share-page .wrap { width: min(100%, 560px); }
.wrap.narrow { max-width: 560px; }

.masthead { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
h1, .wordmark { font: 400 clamp(30px, 5vh, 42px)/1 var(--display); margin: 0; letter-spacing: -.01em; }
.wordmark span, .brand span { color: var(--accent); }
.tagline { margin: 6px 0 0; font-size: 11px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.brand { font: 400 26px/1.1 var(--display); color: var(--ink); text-decoration: none; }
.count { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 6px; }

/* Buttons */
.btn {
  font: inherit; font-weight: 600; padding: 10px 18px; border-radius: 7px; border: 1px solid transparent;
  background: var(--accent); color: var(--accent-ink); cursor: pointer; text-decoration: none; display: inline-block; text-align: center;
}
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn:disabled { background: var(--rule); color: var(--muted); cursor: not-allowed; }
.btn.ghostbtn { background: transparent; color: var(--ink); border-color: var(--rule); }
.btn.ghostbtn:hover:not(:disabled) { border-color: var(--accent); filter: none; }
.btn.big { padding: 13px 24px; font-size: 16px; }
button.text { background: none; border: 0; padding: 4px 0; font: inherit; color: var(--muted); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
button.text:hover { color: var(--ink); }
button.text.danger { color: var(--danger); }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Grid */
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.slot { display: grid; gap: 6px; min-width: 0; align-content: start; }
.frame {
  position: relative; width: 100%; max-width: 100%; aspect-ratio: 2 / 3; container-type: inline-size;
  border-radius: 3px; border: 0; padding: 0; margin: 0;
  background: transparent; color: inherit; cursor: pointer; font: inherit;
  display: grid; place-items: center; overflow: hidden;
  -webkit-user-select: none; user-select: none;
}
.frame:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.frame.empty {
  border: 1.5px dashed var(--rule);
  background: color-mix(in srgb, var(--surface) 60%, transparent);
  transition: border-color .15s, background .15s;
}
.frame.empty:hover { border-color: var(--accent); background: var(--surface); }
.plus { width: 34%; max-width: 44px; aspect-ratio: 1; color: var(--muted); transition: color .15s, transform .15s; }
.frame.empty:hover .plus { color: var(--accent); transform: scale(1.08); }
.frame.filled { box-shadow: var(--shadow); touch-action: none; cursor: grab; background: var(--surface); }
.frame.filled img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.frame.lifted { opacity: .25; }
.frame.target { outline: 3px solid var(--accent); outline-offset: 3px; }
.frame.landed { animation: land .35s ease-out; }
@keyframes land { from { transform: scale(.94); } to { transform: none; } }

.caption { height: 17px; font-size: 12.5px; line-height: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.tally { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; }

/* Typographic cover for books without artwork */
.gen {
  width: 100%; height: 100%; padding: 11% 9%; hyphens: auto; -webkit-hyphens: auto;
  display: flex; flex-direction: column; justify-content: space-between;
  color: #f6f3ea; background: var(--cloth, #2f5d48);
  box-shadow: inset 0 0 0 4px rgba(255,255,255,.08), inset 0 0 0 5px rgba(0,0,0,.18);
  text-align: left; overflow: hidden;
}
.gen .gt { font: 400 clamp(9px, 13cqi, 18px)/1.15 var(--display); display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.gen .ga { font-size: clamp(7px, 6.5cqi, 11px); letter-spacing: .06em; text-transform: uppercase; opacity: .8; }
.gen.mini { padding: 10% 8%; }
.gen.mini .gt { font-size: clamp(5px, 15cqi, 9px); -webkit-line-clamp: 4; }
.gen.mini .ga { display: none; }

.gridfoot { display: flex; justify-content: space-between; align-items: center; gap: 12px; color: var(--muted); font-size: 12.5px; }
.gridfoot #hint { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gridfoot #clearWrap { flex: none; }
kbd { font: 12px var(--body); border: 1px solid var(--rule); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; }
.confirm { display: inline-flex; gap: 12px; align-items: center; }

.ghost { position: fixed; z-index: 50; pointer-events: none; border-radius: 3px; overflow: hidden; box-shadow: 0 12px 32px rgba(0,0,0,.3); transform: rotate(-3deg) scale(1.04); }
.ghost img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Most chosen: one line of small covers; hover or focus shows an Add overlay */
.top { display: grid; gap: 8px; width: min(calc(100vw - 32px), 520px); justify-self: center; }
.top-head { display: flex; align-items: baseline; gap: 10px; }
.top-head h2 { margin: 0; font-size: 11px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--ink); }
.top-head .count { margin: 0; font-size: 11px; letter-spacing: .04em; text-transform: none; }
.top-strip {
  list-style: none; margin: 0; padding: 2px 2px 4px; display: grid;
  grid-auto-flow: column; grid-auto-columns: minmax(40px, 1fr); grid-template-columns: repeat(10, minmax(40px, 1fr));
  gap: 7px; overflow-x: auto; scrollbar-width: thin;
}
.top-strip .note { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.tb { position: relative; aspect-ratio: 2 / 3; max-width: 100%; border-radius: 2px; cursor: default; outline: none; }
.tb-cover { position: absolute; inset: 0; border-radius: 2px; overflow: hidden; container-type: inline-size; background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.tb-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tb-rank {
  position: absolute; bottom: -5px; left: -5px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px;
  background: var(--ink); color: var(--paper); font-size: 10px; font-weight: 600; line-height: 17px; text-align: center;
  font-variant-numeric: tabular-nums; z-index: 2;
}
.tb-over {
  position: absolute; inset: 0; border-radius: 2px; z-index: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  background: rgba(12,18,15,.72); color: #f4f7f2; opacity: 0; transition: opacity .12s;
  text-align: center; padding: 2px;
}
.tb:hover .tb-over, .tb:focus-within .tb-over { opacity: 1; }
.tb:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.tb-add {
  font: inherit; font-size: 10.5px; font-weight: 600; white-space: nowrap; border: 0; border-radius: 999px;
  padding: 3px 6px; background: #f4f7f2; color: #1d2420; cursor: pointer;
}
.tb-add:hover { background: #fff; }
.tb-add:focus-visible { outline: 2px solid #7fb79a; outline-offset: 1px; }
.tb-note { font-size: 9.5px; line-height: 1.15; font-weight: 600; }
.note { margin: 0; font-size: 13px; color: var(--muted); }

/* Dialogs */
dialog {
  width: min(560px, calc(100vw - 24px)); max-height: min(760px, calc(100dvh - 24px));
  padding: 0; border: 1px solid var(--rule); border-radius: 10px;
  background: var(--surface); color: var(--ink); box-shadow: 0 24px 64px rgba(0,0,0,.3);
}
dialog.wide { width: min(880px, calc(100vw - 24px)); }
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: rgba(15,20,18,.5); }
.dhead { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 18px 20px 0; }
.dhead h2 { margin: 0; font: 400 22px/1.2 var(--display); }
.x { background: none; border: 0; font-size: 24px; line-height: 1; color: var(--muted); cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.x:hover { color: var(--ink); background: var(--paper); }
.search { padding: 14px 20px; }
.field { width: 100%; font: inherit; font-size: 16px; padding: 11px 13px; border-radius: 7px; border: 1px solid var(--rule); background: var(--paper); color: var(--ink); min-width: 0; }
.field:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.results { flex: 1; overflow-y: auto; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); min-height: 140px; }
.status { padding: 28px 20px; color: var(--muted); text-align: center; }
.result {
  display: grid; grid-template-columns: 46px minmax(0, 1fr); gap: 14px; align-items: center;
  width: 100%; padding: 10px 20px; border: 0; border-bottom: 1px solid color-mix(in srgb, var(--rule) 55%, transparent);
  background: none; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.result:hover, .result:focus-visible { background: var(--paper); outline: none; }
.result:focus-visible { box-shadow: inset 3px 0 0 var(--accent); }
.thumb { width: 46px; aspect-ratio: 2 / 3; border-radius: 2px; overflow: hidden; container-type: inline-size; background: var(--paper); box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.rt { font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.rm { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.rp { margin-top: 3px; font-size: 12px; font-weight: 600; color: var(--accent); }

.own { padding: 14px 20px 18px; display: grid; gap: 12px; }
.own summary { cursor: pointer; color: var(--accent); font-weight: 600; width: fit-content; }
.own form { display: grid; gap: 10px; margin-top: 12px; }
.own label, .stack { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); display: grid; gap: 4px; }
.own .row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: space-between; }
.dfoot { display: flex; justify-content: space-between; align-items: center; padding: 0 20px 16px; gap: 12px; }
input[type=file] { font-size: 13px; color: var(--muted); max-width: 100%; }

/* Share dialog */
.share-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 24px; padding: 18px 20px 20px; overflow-y: auto; }
.poster-wrap { min-width: 0; }
#poster { width: 100%; max-width: 100%; height: auto; display: block; border-radius: 4px; box-shadow: var(--shadow); border: 1px solid var(--rule); }
.share-side { display: grid; gap: 18px; align-content: start; min-width: 0; }
.themes { border: 0; padding: 0; margin: 0; display: flex; gap: 10px; flex-wrap: wrap; }
.themes legend { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 0; margin-bottom: 8px; }
.swatch { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border: 1px solid var(--rule); border-radius: 999px; cursor: pointer; font-size: 14px; }
.swatch input { position: absolute; opacity: 0; pointer-events: none; }
.swatch .chip { width: 22px; height: 22px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 1px rgba(0,0,0,.2); position: relative; }
.swatch .chip::after { content: ""; position: absolute; inset: 8px 5px; border-radius: 1px; background: var(--i); opacity: .7; }
.swatch:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.swatch:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.msg { min-height: 1.4em; font-size: 13px; color: var(--accent); margin-top: -8px; }
.msg.err { color: var(--danger); }
.msg a { color: inherit; font-weight: 600; text-underline-offset: 2px; }
.linkbox { display: grid; gap: 6px; }
.linkbox .label { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.linkrow { display: flex; gap: 8px; }
.linkrow .field { font-size: 14px; padding: 9px 11px; }
.platforms { display: flex; flex-wrap: wrap; gap: 8px; }
.platforms a {
  font-size: 14px; font-weight: 500; padding: 7px 14px; border-radius: 999px; border: 1px solid var(--rule);
  color: var(--ink); text-decoration: none; background: var(--paper);
}
.platforms a:hover { border-color: var(--accent); color: var(--accent); }
.platforms a[aria-disabled="true"] { opacity: .5; pointer-events: none; }

/* Share landing page */
.shared { display: grid; gap: 24px; justify-items: center; }
.shared-poster { width: 100%; max-width: 100%; height: auto; border-radius: 4px; box-shadow: var(--shadow); }
.shared-list { width: 100%; margin: 0; padding-left: 1.6em; display: grid; gap: 6px; }
.shared-list .t { font-weight: 600; }
.shared-list .a { color: var(--muted); }
.lede { font-size: 18px; color: var(--muted); }

@media (max-width: 720px) {
  .share-body { grid-template-columns: minmax(0, 1fr); }
  .poster-wrap { max-width: 320px; justify-self: center; width: 100%; }
}
@media (hover: none) {
  .tb { cursor: pointer; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  .ghost { transform: none; }
}
