/* Buyout — a small private library at night. */

:root,
[data-theme="dark"] {
  --bg: #161914;
  --surface: #20251e;
  --surface-2: #2a3026;
  --line: #3a4233;
  --ink: #ede4d0;
  --muted: #a59b84;
  --lamp: #e0a458;        /* warm lamplight */
  --brass: #b9914e;
  --moss: #93a87d;
  --plum: #b08fa3;        /* released foil */
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --glow: 0 0 40px rgba(224, 164, 88, 0.13);
}

[data-theme="light"] {
  --bg: #e9eae1;
  --surface: #f4f3ea;
  --surface-2: #ffffff;
  --line: #cfcdbd;
  --ink: #272b20;
  --muted: #6e6a58;
  --lamp: #a8691f;
  --brass: #8a6a33;
  --moss: #5d7347;
  --plum: #84566e;
  --shadow: 0 8px 24px rgba(60, 56, 40, 0.18);
  --glow: none;
}

* { box-sizing: border-box; }

/* the hidden attribute must beat any explicit display value below */
[hidden] { display: none !important; }

html { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: Seravek, "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}

.display { font-family: Fraunces, Georgia, "Times New Roman", serif; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-variant-numeric: tabular-nums; }

button { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--lamp); outline-offset: 2px; border-radius: 4px; }

/* ---------- chrome ---------- */

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 680px; margin: 0 auto;
  padding: 18px 20px 6px;
}

.app-name {
  font-family: Fraunces, Georgia, serif;
  font-weight: 600; font-size: 1.35rem; letter-spacing: 0.04em;
  margin: 0;
}
.app-name::after { content: "."; color: var(--lamp); }

.iconbtn {
  background: none; border: none; cursor: pointer; color: var(--muted);
  min-width: 44px; min-height: 44px; display: grid; place-items: center;
  border-radius: 10px;
}
.iconbtn:hover { color: var(--ink); }

.view { max-width: 680px; margin: 0 auto; padding: 10px 20px 30px; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; justify-content: center; gap: 4px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  z-index: 30;
}

.tab {
  flex: 0 1 150px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 0.72rem; letter-spacing: 0.03em;
  padding: 6px 10px; min-height: 52px; border-radius: 12px;
}
.tab[aria-current="page"] { color: var(--lamp); }
.tab:hover { color: var(--ink); }

.fab {
  position: fixed; right: 18px; bottom: calc(86px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--lamp); color: #221a0e; border: none; cursor: pointer;
  font-size: 1.9rem; line-height: 1; font-weight: 400;
  box-shadow: var(--shadow), var(--glow);
  z-index: 31;
}
.fab:hover { filter: brightness(1.08); }

.offline {
  position: sticky; top: 0; z-index: 40;
  text-align: center; font-size: 0.85rem;
  background: var(--surface-2); color: var(--muted);
  border-bottom: 1px solid var(--line);
  padding: 8px 16px;
}

/* ---------- shared bits ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--ink);
  padding: 11px 18px; min-height: 44px; cursor: pointer;
  text-decoration: none; font-size: 0.95rem;
}
.btn:hover { border-color: var(--brass); }
.btn.primary {
  background: var(--lamp); border-color: var(--lamp); color: #221a0e; font-weight: 600;
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--plum); }
.btn.big { width: 100%; padding: 16px; font-size: 1.05rem; border-radius: 14px; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.chips { gap: 8px; }
.chip {
  border: 1px solid var(--line); background: transparent; color: var(--muted);
  border-radius: 999px; padding: 8px 14px; min-height: 38px; cursor: pointer;
  font-size: 0.85rem;
}
.chip:hover { color: var(--ink); border-color: var(--brass); }
.chip[aria-pressed="true"] { background: var(--surface-2); color: var(--lamp); border-color: var(--lamp); }

.tag {
  display: inline-block; font-size: 0.72rem; letter-spacing: 0.05em;
  color: var(--moss); border: 1px solid var(--line);
  border-radius: 999px; padding: 2px 9px;
}

.rent {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem; color: var(--muted);
}

.muted { color: var(--muted); }

/* ---------- today ---------- */

.today-empty { text-align: center; padding: 12vh 6px 0; }
.today-empty h2 {
  font-family: Fraunces, Georgia, serif; font-weight: 600;
  font-size: 1.7rem; margin: 0 0 26px;
}
.today-empty .row { justify-content: center; }
.today-hint { margin-top: 28px; font-size: 0.85rem; }

.pick-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow), var(--glow);
  padding: 28px 24px 22px;
  margin-top: 4vh;
}
.pick-card h2 {
  font-family: Fraunces, Georgia, serif; font-weight: 600;
  font-size: 1.85rem; line-height: 1.2; margin: 0 0 10px;
}
.pick-card .meta { display: flex; gap: 12px; align-items: center; margin-bottom: 6px; }
.pick-card .note { color: var(--muted); font-size: 0.92rem; margin: 8px 0 0; }
.pick-actions { margin-top: 26px; display: grid; gap: 10px; }
.pick-actions .quiet-row { display: flex; gap: 10px; }
.pick-actions .quiet-row .btn { flex: 1; font-size: 0.88rem; color: var(--muted); }

.timer {
  margin-top: 16px; display: flex; align-items: center; gap: 12px;
}
.timer-display { font-size: 1.3rem; color: var(--lamp); }

/* ---------- declared done ---------- */

.done-screen {
  position: fixed; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 24px;
  background:
    radial-gradient(ellipse 90% 55% at 50% 30%, rgba(224, 164, 88, 0.07), transparent 70%),
    var(--bg);
  animation: doneFade 1.4s ease both;
}
[data-theme="light"] .done-screen {
  background: radial-gradient(ellipse 90% 55% at 50% 30%, rgba(168, 105, 31, 0.08), transparent 70%), var(--bg);
}
@keyframes doneFade { from { opacity: 0; } }

.done-lamp { margin-bottom: 30px; opacity: 0.9; }
.done-lamp circle { animation: lampDim 6s ease-in-out infinite alternate; }
@keyframes lampDim { from { opacity: 0.85; } to { opacity: 0.55; } }

.done-screen h2 {
  font-family: Fraunces, Georgia, serif; font-weight: 600;
  font-size: 2rem; margin: 0 0 14px; max-width: 22ch;
}
.done-screen p { color: var(--muted); max-width: 36ch; margin: 0 0 30px; }
.done-screen .row { justify-content: center; }

@media (prefers-reduced-motion: reduce) {
  .done-screen, .done-lamp circle { animation: none; }
}

/* ---------- shelf ---------- */

.shelf-head { display: flex; justify-content: space-between; align-items: baseline; margin: 6px 0 14px; }
.shelf-head h2 { font-family: Fraunces, Georgia, serif; font-weight: 600; font-size: 1.25rem; margin: 0; }
.sort select, .field select, .field input, textarea, input[type="text"], input[type="date"], input[type="number"] {
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font: inherit; min-height: 44px;
}
.sort select { min-height: 38px; padding: 6px 10px; font-size: 0.85rem; color: var(--muted); }

.shelf-list { display: grid; gap: 10px; }

.shelf-item {
  width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 16px; cursor: pointer;
  display: grid; gap: 5px;
}
.shelf-item:hover { border-color: var(--brass); }
.shelf-item .title { font-size: 1.02rem; }
.shelf-item .meta { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.empty-state { text-align: center; color: var(--muted); padding: 10vh 20px; font-style: italic; }

/* the designated flaw */
.flaw-item {
  margin-top: 26px;
  transform: rotate(-1.4deg);
  background: transparent;
  border: 1px dashed var(--brass);
  border-radius: 6px;
  padding: 14px 16px;
  color: var(--muted);
  cursor: pointer; width: 100%; text-align: left;
}
.flaw-item .title::after { content: " *"; color: var(--lamp); }
.flaw-caption { font-size: 0.72rem; letter-spacing: 0.06em; color: var(--brass); margin-top: 4px; }

/* ---------- collection ---------- */

.coll-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 560px) { .coll-grid { grid-template-columns: repeat(3, 1fr); } }

.coll-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 14px 12px 18px;
  min-height: 120px;
  display: flex; flex-direction: column; justify-content: space-between; gap: 10px;
  overflow: hidden;
}
.coll-card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px;
}
.coll-card.evicted::before {
  background: linear-gradient(180deg, var(--lamp), var(--brass) 55%, var(--lamp));
}
.coll-card.evicted {
  background:
    linear-gradient(125deg, transparent 35%, rgba(224, 164, 88, 0.06) 48%, transparent 60%),
    var(--surface);
}
.coll-card.released::before {
  background: linear-gradient(180deg, var(--plum), color-mix(in srgb, var(--plum) 55%, var(--bg)) 55%, var(--plum));
}
.coll-card .title { font-family: Fraunces, Georgia, serif; font-size: 0.98rem; line-height: 1.25; }
.coll-card .facts { display: grid; gap: 2px; }
.coll-card .kind { font-size: 0.68rem; letter-spacing: 0.09em; text-transform: uppercase; }
.coll-card.evicted .kind { color: var(--lamp); }
.coll-card.released .kind { color: var(--plum); }
.undo-link {
  background: none; border: none; padding: 2px 0; cursor: pointer;
  color: var(--muted); font-size: 0.75rem; text-decoration: underline; text-align: left;
}

.stats {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 4px 16px; margin-bottom: 16px;
}
.stats summary {
  cursor: pointer; padding: 10px 0; color: var(--muted); font-size: 0.9rem;
  list-style: none;
}
.stats summary::before { content: "› "; color: var(--brass); }
.stats[open] summary::before { content: "˅ "; }
.stats .stat-rows { padding: 2px 0 14px; display: grid; gap: 8px; }
.stat-line { display: flex; justify-content: space-between; gap: 12px; font-size: 0.9rem; }
.stat-line .rent { font-size: 0.9rem; color: var(--ink); }
.signature-stat {
  font-family: Fraunces, Georgia, serif; font-size: 1.02rem; color: var(--lamp);
  border-top: 1px solid var(--line); padding-top: 12px; margin-top: 4px;
}

/* ---------- sheets / dialogs ---------- */

.sheet {
  border: 1px solid var(--line); border-radius: 18px;
  background: var(--surface); color: var(--ink);
  width: min(92vw, 480px); padding: 20px;
  box-shadow: var(--shadow);
}
.sheet::backdrop { background: rgba(10, 12, 9, 0.6); backdrop-filter: blur(2px); }
@media (max-width: 560px) {
  .sheet {
    margin: auto auto 0; width: 100vw; max-width: 100vw;
    border-radius: 18px 18px 0 0; border-bottom: none;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }
}
.sheet.center { text-align: center; margin: auto; }

.sheet-title { font-family: Fraunces, Georgia, serif; font-size: 1.2rem; font-weight: 600; margin: 0 0 16px; }
.sheet-actions { justify-content: flex-end; margin-top: 18px; }
.sheet form { display: grid; gap: 14px; }

.sheet input[type="text"], .sheet textarea { width: 100%; }
#add-title { font-size: 1.05rem; padding: 14px; }

.more summary { color: var(--muted); font-size: 0.85rem; cursor: pointer; }
.more textarea { width: 100%; margin: 10px 0; }

.field { display: grid; gap: 6px; margin: 0 0 14px; font-size: 0.9rem; color: var(--muted); }
.field.check { grid-template-columns: auto 1fr; align-items: center; color: var(--ink); }
.field input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--lamp); }

/* ---------- shuffle ---------- */

.shuffle-label { color: var(--muted); font-size: 0.85rem; margin: 0 0 14px; }
.shuffle-card {
  font-family: Fraunces, Georgia, serif; font-size: 1.3rem; font-weight: 600;
  min-height: 76px; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface-2); padding: 16px;
}
.shuffle-card.landed { border-color: var(--lamp); box-shadow: var(--glow); }

/* ---------- celebration ---------- */

.celebrate {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(10, 12, 9, 0.75); backdrop-filter: blur(3px);
  display: grid; place-items: center;
}

.celebrate-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--lamp);
  border-radius: 14px;
  box-shadow: var(--shadow), 0 0 60px rgba(224, 164, 88, 0.25);
  padding: 26px 28px;
  max-width: min(80vw, 380px);
  text-align: center;
}
.celebrate-card .title { font-family: Fraunces, Georgia, serif; font-size: 1.4rem; font-weight: 600; }
.celebrate-card .seal {
  display: inline-block; margin-top: 12px;
  font-size: 0.7rem; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--lamp); border: 1px solid var(--lamp); border-radius: 4px;
  padding: 3px 10px; transform: rotate(-4deg);
}

.celebrate.animate .celebrate-card { animation: buyout 1.9s cubic-bezier(0.5, 0, 0.4, 1) both; }
@keyframes buyout {
  0%   { transform: scale(0.6) rotateY(0); opacity: 0; }
  18%  { transform: scale(1.05) rotateY(0); opacity: 1; }
  30%  { transform: scale(1) rotateY(0); }
  55%  { transform: scale(1) rotateY(360deg); }
  72%  { transform: scale(1) rotateY(360deg) translate(0, 0); opacity: 1; }
  100% { transform: scale(0.12) rotateY(360deg) translate(280vw, 380vh); opacity: 0.25; }
}

.celebrate-after {
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 26px 24px; text-align: center; max-width: min(90vw, 420px);
}
.celebrate-after h3 { font-family: Fraunces, Georgia, serif; font-weight: 600; font-size: 1.25rem; margin: 0 0 8px; }
.celebrate-after p { color: var(--muted); margin: 0 0 16px; }
.celebrate-after .chips { justify-content: center; }
.skip-note { font-size: 0.72rem; color: var(--muted); margin-top: 14px; }

@media (prefers-reduced-motion: reduce) {
  .celebrate.animate .celebrate-card { animation: none; }
  * { transition-duration: 0.01ms !important; }
}

/* ---------- login ---------- */

.login-screen {
  position: fixed; inset: 0; z-index: 70;
  background:
    radial-gradient(ellipse 90% 55% at 50% 30%, rgba(224, 164, 88, 0.07), transparent 70%),
    var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 24px; text-align: center;
}
.login-screen .app-name { font-size: 2.2rem; }

.pin-input {
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 14px;
  font-size: 2rem; letter-spacing: 0.55em; text-align: center; text-indent: 0.55em;
  width: min(80vw, 300px); padding: 14px 8px; min-height: 64px;
}
.pin-input:focus-visible { outline: 2px solid var(--lamp); outline-offset: 2px; }

.login-err { color: var(--plum); min-height: 1.4em; font-size: 0.9rem; margin: 0; }

.login-screen.shake .pin-input { animation: pinShake 0.35s ease; }
@keyframes pinShake {
  20% { transform: translateX(-8px); } 40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); } 80% { transform: translateX(3px); }
}
@media (prefers-reduced-motion: reduce) { .login-screen.shake .pin-input { animation: none; } }

/* ---------- confirm / misc ---------- */

.confirm-msg { margin: 4px 0 2px; line-height: 1.5; }

.signed-in-row { justify-content: space-between; border-top: 1px solid var(--line); padding-top: 14px; }

.remove-link {
  background: none; border: none; padding: 2px 0; cursor: pointer;
  color: var(--muted); font-size: 0.75rem; text-decoration: underline; text-align: left;
}

/* ---------- toast ---------- */

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(96px + env(safe-area-inset-bottom));
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 12px 18px; font-size: 0.92rem; max-width: min(86vw, 440px);
  z-index: 60; text-align: center;
}
