/*
  Two themes, Dark and Parchment, as in Familiar. Picked with the header button and
  remembered per device; js/theme.js applies it before the page draws. With no choice
  saved it follows the device's light or dark setting.

  Dark is Familiar's layout with the browns taken out: neutral charcoal and gold.
  Parchment is Familiar's own palette, old paper and brown ink.
  Every colour below comes from these variables, so a theme only has to set them.
*/

:root {
  --bg: #121418;
  --surface: #1b1e24;
  --surface-2: #23272f;
  --col: #181b20;
  --text: #e8eaf0;
  --muted: #9aa1b2;
  --border: #323844;
  --accent: #d9a441;
  --accent-hover: #e8b65a;
  --accent-ink: #15171c;
  --danger: #e07a6a;
  --danger-border: #6b3a34;
  --bug: #f0956a;
  --improvement: #8fb4ff;
  --input-bg: #15181d;
  --admin-bg: #1e2430;
  --admin-border: #34405a;
  --shadow: none;
  --backdrop: rgba(0, 0, 0, .6);
  color-scheme: dark;
}

:root[data-theme="parchment"] {
  --bg: #efe2c6;
  --surface: #f6ecd6;
  --surface-2: #e6d5b3;
  --col: #e8d8b8;
  --text: #3b2a17;
  --muted: #6b5234;
  --border: #d3bf98;
  --accent: #7a3e12;
  --accent-hover: #63310c;
  --accent-ink: #fff8ec;
  --danger: #8b2a1a;
  --danger-border: #d9a594;
  --bug: #9a4a16;
  --improvement: #3a5a8c;
  --input-bg: #fbf4e4;
  --admin-bg: #e9dcc0;
  --admin-border: #c9b089;
  --shadow: 0 1px 2px rgba(59, 42, 23, .10), 0 4px 12px rgba(59, 42, 23, .08);
  --backdrop: rgba(59, 42, 23, .45);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 640px; padding-top: 2rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* Header */
.site-head { background: var(--surface); border-bottom: 1px solid var(--border); }
.site-head .wrap { display: flex; align-items: center; gap: 10px; min-height: 64px; flex-wrap: wrap; }
.site-head.bare { background: none; border: none; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 800; font-size: 1.15rem; }
.brand img { width: 40px; height: 40px; }
.head-spacer { flex: 1; }
.admin-pill { background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 4px 10px; font-size: .8rem; font-weight: 700; }

/* Landing */
.hero { text-align: center; padding: 1rem 0 1.5rem; }
.hero img { width: min(160px, 40vw); height: auto; margin-bottom: .75rem; }
.hero h1 { font-size: clamp(1.9rem, 6vw, 2.8rem); font-weight: 900; letter-spacing: -.02em; }
.hero p { color: var(--muted); margin: 0; }
.app-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; padding: 1.5rem 0 3rem; }
.app-btn {
  display: flex; align-items: center; gap: 14px; padding: 18px; min-height: 92px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
  color: var(--text); text-decoration: none; transition: transform .12s, border-color .12s;
}
.app-btn:hover, .app-btn:focus-visible { transform: translateY(-2px); border-color: var(--accent); }
.app-btn strong { display: block; font-size: 1.1rem; }
.app-btn span { color: var(--muted); font-size: .92rem; }
.app-btn .counts { display: block; margin-top: 2px; font-size: .8rem; }
.app-icon {
  flex: none; width: 52px; height: 52px; border-radius: 12px; display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 1.4rem; overflow: hidden; background: var(--c, var(--accent));
}
.app-icon img { width: 100%; height: 100%; object-fit: cover; }
.app-icon.lg { width: 44px; height: 44px; font-size: 1.2rem; }

/* Buttons and forms */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); border-radius: 10px;
  padding: 9px 14px; min-height: 42px; cursor: pointer; font-weight: 600; text-decoration: none; color: var(--text);
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--danger); border-color: var(--danger-border); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: .85rem; }
.btn:disabled { opacity: .6; cursor: default; }

label { display: block; font-weight: 600; font-size: .92rem; margin: 12px 0 4px; }
label .opt { font-weight: 400; color: var(--muted); }
input[type=text], input[type=email], input[type=password], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--input-bg); min-height: 44px;
}
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.redact-row { display: flex; justify-content: flex-end; margin-top: 4px; }
.msg { margin: 10px 0 0; font-size: .92rem; }
.msg.err { color: var(--danger); }
.turnstile { margin-top: 12px; min-height: 65px; }
.notice {
  margin: 4px 0 8px; padding: 10px 12px; border-radius: 10px; font-size: .92rem; font-weight: 600;
  background: var(--surface-2); border-left: 4px solid var(--accent);
}

/* App page */
.app-head { display: flex; align-items: center; gap: 12px; padding: 1.5rem 0 1rem; flex-wrap: wrap; }
.app-head h1 { margin: 0; font-size: 1.6rem; }
.app-head p { margin: 0; color: var(--muted); }

.board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; padding-bottom: 3rem; align-items: start; }
.col { background: var(--col); border: 1px solid var(--border); border-radius: 14px; padding: 10px; min-height: 160px; }
.col.drop { outline: 2px dashed var(--accent); outline-offset: -2px; }
.col h2 { font-size: .95rem; display: flex; justify-content: space-between; padding: 4px 6px 10px; margin: 0; }
.col h2 .n { background: var(--surface); border-radius: 999px; padding: 0 9px; font-size: .8rem; line-height: 1.6; }
.col-empty { color: var(--muted); font-size: .88rem; text-align: center; padding: 18px 6px; }

.card {
  display: block; width: 100%; text-align: left; cursor: pointer; margin-bottom: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px; box-shadow: var(--shadow);
}
.card:hover { border-color: var(--accent); }
.card.is-hidden { opacity: .55; border-style: dashed; }
.card[draggable=true] { cursor: grab; }
.card h3 { font-size: 1rem; margin: 6px 0 8px; overflow-wrap: anywhere; }
.card-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); }
.card-meta .grow { flex: 1; }

.chip { display: inline-block; border-radius: 999px; padding: 1px 9px; font-size: .75rem; font-weight: 700; border: 1px solid currentColor; }
.chip.bug { color: var(--bug); }
.chip.improvement { color: var(--improvement); }
.chip.status { color: var(--text); border-color: var(--border); background: var(--surface-2); }
.chip.hidden-chip { color: var(--danger); }

.vote {
  display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--border); background: var(--surface-2);
  border-radius: 999px; padding: 2px 10px; font-weight: 700; font-size: .85rem; cursor: pointer; min-height: 30px; color: var(--text);
}
.vote.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.vote .arrow { font-size: .7rem; }

/* Dialogs */
dialog {
  border: 1px solid var(--border); border-radius: 18px; padding: 0; width: min(680px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px); box-shadow: 0 20px 60px rgba(0, 0, 0, .35); color: var(--text); background: var(--surface);
}
dialog::backdrop { background: var(--backdrop); }
.dlg-head { display: flex; align-items: flex-start; gap: 10px; padding: 18px 20px 10px; position: sticky; top: 0; background: var(--surface); border-bottom: 1px solid var(--border); z-index: 1; }
.dlg-head h2 { flex: 1; margin: 0; font-size: 1.25rem; overflow-wrap: anywhere; }
.dlg-close { border: none; background: none; font-size: 1.6rem; line-height: 1; cursor: pointer; padding: 0 4px; color: var(--muted); }
.dlg-body { padding: 14px 20px 20px; }
.desc { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.facts { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .85rem; color: var(--muted); margin: 10px 0; }
.section-title { font-size: 1rem; margin: 22px 0 8px; }

.timeline { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--border); }
.timeline li { position: relative; padding: 0 0 12px 14px; font-size: .9rem; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.timeline .when { color: var(--muted); font-size: .8rem; }
.timeline .note { white-space: pre-wrap; overflow-wrap: anywhere; }

.comment { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.comment.mine { border-color: var(--accent); background: var(--surface-2); }
.comment.is-hidden { opacity: .55; border-style: dashed; }
.comment .who { font-weight: 700; font-size: .9rem; }
.comment .body { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 2px; }
.comment .tools { margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; }

.admin-box { background: var(--admin-bg); border: 1px solid var(--admin-border); border-radius: 12px; padding: 4px 14px 14px; margin-top: 22px; }
.admin-box h3 { margin: 16px 0 0; font-size: 1rem; }

.lock { max-width: 420px; margin: 3rem auto; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 24px; box-shadow: var(--shadow); }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; z-index: 100; max-width: calc(100vw - 32px); box-shadow: var(--shadow);
}

/* Phones: columns become a swipeable row, forms go single column */
@media (max-width: 760px) {
  .board { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; gap: 10px; margin: 0 -16px; padding: 0 16px 2rem; }
  .col { flex: 0 0 86%; scroll-snap-align: center; }
  .row2 { grid-template-columns: 1fr; }
  .dlg-head, .dlg-body { padding-left: 14px; padding-right: 14px; }
  .app-head .btn.primary { width: 100%; }
}
