/* GitHub LIGHT theme, green-forward accents, custom fonts */
:root {
  --bg:        #ffffff;
  --subtle:    #f6f8fa;   /* canvas subtle */
  --inset:     #f6f8fa;
  --panel:     #ffffff;
  --panel2:    #f6f8fa;
  --border:    #d0d7de;
  --border-muted:#d8dee4;
  --text:      #1f2328;
  --muted:     #59636e;
  --link:      #1a7f37;   /* green link */
  --green:     #1f883d;   /* primary button */
  --green-hi:  #1a7f37;   /* hover */
  --green-em:  #2da44e;   /* emphasis / accents */
  --green-soft:#dafbe1;   /* light green fill */
  --green-line:#aceebb;
  --warn:      #9a6700;
  --danger:    #cf222e;
  --chip:      #eef6f0;
  --shadow:    0 1px 0 rgba(31,35,40,.04), 0 1px 3px rgba(31,35,40,.06);
  --radius: 8px;
  --ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --display: "Space Grotesk", var(--ui);
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text); font-family: var(--ui);
  font-size: 14.5px; line-height: 1.55;
  background-image: radial-gradient(800px 360px at 100% -8%, rgba(45,164,78,.06), transparent 60%);
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* top bar */
header.top {
  display: flex; align-items: center; gap: 22px; padding: 12px 22px;
  background: var(--bg); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5;
}
header.top .brand { font-family: var(--display); font-weight: 700; letter-spacing:.2px; font-size: 16px; }
header.top nav { display: flex; gap: 2px; flex-wrap: wrap; }
header.top nav a { padding: 6px 12px; border-radius: 7px; color: var(--muted); font-weight: 500; }
header.top nav a:hover { background: var(--subtle); color: var(--text); text-decoration: none; }
header.top nav a.active { color: var(--text); background: var(--subtle); box-shadow: inset 0 -2px 0 var(--green-em); }
header.top .user { margin-left: auto; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
header.top .user .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green-em); box-shadow: 0 0 6px rgba(45,164,78,.6); }
header.top .user .logout { color: var(--muted); border: 1px solid var(--border); padding: 3px 9px; border-radius: 6px; }
header.top .user .logout:hover { color: var(--text); border-color: var(--green-em); text-decoration: none; }

.container { max-width: 1040px; margin: 22px auto; padding: 0 22px; }
.flash { background: var(--green-soft); border: 1px solid var(--green-line); color: var(--green-hi); padding: 10px 14px; border-radius: 8px; margin-bottom: 18px; }

/* ---------- dashboard feed ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 14px; background: var(--subtle); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 22px; }
.toolbar-stats { display: flex; gap: 8px; align-items: center; font-size: 14px; }

.topic-block { margin-bottom: 30px; }
.topic-head { display: flex; align-items: baseline; justify-content: space-between; margin: 0 2px 12px; border-bottom: 2px solid var(--green-line); padding-bottom: 6px; }
.topic-head h2 { font-family: var(--display); font-size: 18px; margin: 0; }

.feed { display: flex; flex-direction: column; gap: 10px; }
.feed-card {
  display: flex; align-items: flex-start; gap: 14px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px;
  box-shadow: var(--shadow); transition: box-shadow .15s, transform .15s, opacity .2s;
}
.feed-card:hover { box-shadow: 0 3px 14px rgba(31,35,40,.10); transform: translateY(-1px); }
.feed-card.htmx-swapping { opacity: 0; transform: translateX(12px); }
.card-rank { font-family: var(--display); font-weight: 700; color: var(--green-em); min-width: 26px; font-size: 18px; line-height: 1.4; }
.card-main { flex: 1; min-width: 0; }
.card-title { font-weight: 600; color: var(--text); font-size: 16px; line-height: 1.35; }
.card-title:hover { color: var(--green-hi); }
.card-desc { color: #424a53; margin: 6px 0 8px; font-size: 14px; }
.card-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-meta .dt { font-size: 12px; }
.ok-btn { background: var(--panel); color: var(--green-hi); border: 1px solid var(--green-line);
  padding: 6px 12px; border-radius: 7px; font-weight: 600; cursor: pointer; font-size: 13px; white-space: nowrap; }
.ok-btn:hover { background: var(--green-soft); }

/* hero (rank 0) is biggest; rank 1-2 medium; rest compact */
.feed-card.rank-0 { border-color: var(--green-line); background: linear-gradient(180deg, var(--green-soft), #fff 60%); padding: 20px; }
.feed-card.rank-0 .card-title { font-size: 21px; }
.feed-card.rank-0 .card-desc { font-size: 15px; }
.feed-card.rank-0 .card-rank { font-size: 24px; }
.feed-card.rank-1 .card-title { font-size: 17px; }
.feed-card.rank-n { padding: 11px 16px; }
.feed-card.rank-n .card-title { font-size: 14.5px; }
.feed-card.rank-n .card-desc { font-size: 13px; }

.empty { text-align: center; padding: 70px 20px; color: var(--muted); }
.empty-emoji { font-size: 50px; }
.empty h2 { font-family: var(--display); color: var(--text); margin: 8px 0 6px; }

/* ---------- generic components ---------- */
.grid { display: grid; gap: 16px; }
.cards { grid-template-columns: repeat(auto-fit, minmax(140px,1fr)); }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card .num { font-family: var(--display); font-size: 28px; font-weight: 700; }
.card .lbl { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing:.5px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; box-shadow: var(--shadow); }
.panel h2 { font-family: var(--display); margin: 0 0 14px; font-size: 16px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.spread { justify-content: space-between; }

button, .btn { background: var(--green); color: #fff; border: 1px solid rgba(31,35,40,.15);
  padding: 8px 14px; border-radius: 7px; font-weight: 600; cursor: pointer; font-size: 13.5px; font-family: var(--ui); }
button:hover, .btn:hover { background: var(--green-hi); text-decoration: none; }
.btn.alt { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn.alt:hover { background: var(--subtle); border-color: var(--green-em); }
.btn.green { background: var(--green); }
.btn.danger { background: var(--bg); color: var(--danger); border:1px solid rgba(207,34,46,.4); padding:4px 10px; }
.btn.danger:hover { background: #ffebe9; }
.btn.sm { padding: 5px 11px; font-size: 12.5px; }

input, textarea, select { background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 8px 10px; border-radius: 7px; font: inherit; width: 100%; font-family: var(--ui); }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--green-em); box-shadow: 0 0 0 3px rgba(45,164,78,.25); }
label { display:block; font-size: 12.5px; color: var(--muted); margin: 8px 0 4px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border-muted); vertical-align: top; }
th { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing:.5px; }
tr:hover td { background: var(--subtle); }

.chip { display:inline-block; background: var(--chip); border:1px solid var(--green-line); color: var(--green-hi); padding: 1px 8px; border-radius: 999px; font-size: 12px; margin: 2px 4px 2px 0; }
.score { font-family: var(--mono); font-weight: 600; }
.score.hi { color: var(--green-em); } .score.mid { color: var(--warn); } .score.lo { color: var(--muted); }
.badge { padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; }
.badge.ok { background: var(--green-soft); color: var(--green-hi); border:1px solid var(--green-line); }
.badge.bad { background: #ffebe9; color: var(--danger); border:1px solid #ffcecb; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.digest-body { white-space: pre-wrap; background: var(--subtle); padding: 14px; border-radius: 8px; border:1px solid var(--border); font-size: 13.5px; }
details summary { cursor: pointer; color: var(--link); }
hr { border:0; border-top:1px solid var(--border); margin: 16px 0; }

/* ---------- login ---------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; margin: 0;
  background: radial-gradient(680px 360px at 50% -10%, rgba(45,164,78,.12), transparent 60%), var(--subtle); }
.login-wrap { width: 340px; text-align: center; padding: 20px; }
.login-logo { font-size: 44px; filter: drop-shadow(0 4px 10px rgba(45,164,78,.35)); }
.login-title { font-family: var(--display); font-size: 26px; margin: 8px 0 2px; }
.login-sub { color: var(--muted); margin: 0 0 22px; font-size: 14px; }
.login-card { background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 24px; box-shadow: 0 8px 30px rgba(31,35,40,.10); }
.gbtn { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
  background: #fff; color: #1f2328; font-weight: 600; padding: 11px; border-radius: 8px; border: 1px solid var(--border); font-size: 14.5px; }
.gbtn:hover { text-decoration: none; box-shadow: 0 0 0 3px rgba(45,164,78,.25); border-color: var(--green-em); transform: translateY(-1px); transition: .12s; }
.login-note { color: var(--muted); font-size: 12px; margin: 14px 0 0; }
.login-error { background: #ffebe9; border:1px solid #ffcecb; color:var(--danger); padding: 9px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; }
.login-foot { color: var(--muted); font-size: 12px; margin-top: 18px; }

/* ---------- mosaic dashboard (Muuri) ---------- */
.container:has(.mosaic), .container:has(.legend) { max-width: 1720px; }
.legend { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 2px 18px; }
.leg { background: var(--bg); color: var(--text); border: 1px solid var(--border);
  padding: 5px 12px; border-radius: 999px; font-size: 13px; font-weight: 500; cursor: pointer;
  display: inline-flex; align-items: center; gap: 7px; }
.leg:hover { border-color: var(--green-em); background: var(--subtle); }
.leg.on { border-color: var(--green-em); background: var(--green-soft); color: var(--green-hi); }
.leg .sw { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

.mosaic { position: relative; width: 100%; }
.b { position: absolute; z-index: 1; }
/* 4 widths (165/250/335/420) × varied heights = dense random mosaic */
.b.s   { width: 165px; height: 135px; }
.b.m   { width: 165px; height: 195px; }
.b.t   { width: 165px; height: 255px; }
.b.w   { width: 250px; height: 140px; }
.b.l   { width: 250px; height: 205px; }
.b.xl  { width: 335px; height: 175px; }
.b.xl2 { width: 335px; height: 265px; }
.b.xw  { width: 420px; height: 165px; }
.b.xxl { width: 420px; height: 250px; }
.b-inner {
  position: absolute; inset: 4px; background: var(--bg);
  border: 1px solid var(--border); border-top: 3px solid var(--c);
  border-radius: 11px; padding: 11px 12px; display: flex; flex-direction: column;
  box-shadow: var(--shadow); overflow: hidden; transition: box-shadow .15s, transform .15s;
}
.b-inner:hover { box-shadow: 0 4px 16px rgba(31,35,40,.13); transform: translateY(-2px); }
.b.hl .b-inner { box-shadow: 0 0 0 2px var(--c), 0 4px 18px color-mix(in srgb, var(--c) 30%, transparent); }
.b-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 5px; }
.b-topic { color: var(--c); font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.b-score { font-family: var(--display); font-size: 15px; font-weight: 700; color: #fff;
  background: var(--c); padding: 1px 9px; border-radius: 999px; white-space: nowrap; line-height: 1.45; }
.b.xl .b-score, .b.xxl .b-score { font-size: 17px; padding: 2px 11px; }
.b-title { font-weight: 600; color: var(--text); font-size: 13.5px; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.b-title:hover { color: var(--green-hi); }
.b.l .b-title, .b.xl .b-title, .b.xxl .b-title { font-size: 15px; }
.b.xxl .b-desc { -webkit-line-clamp: 6; }
.b-desc { color: #57606a; font-size: 12px; line-height: 1.4; margin: 6px 0 0; flex: 1;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.b.s .b-desc { -webkit-line-clamp: 2; }
.b.xl .b-desc { -webkit-line-clamp: 6; }
.b-foot { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.b-tag { font-size: 10px; color: var(--muted); }
.b-actions { position: absolute; right: 7px; bottom: 7px; display: flex; gap: 4px;
  opacity: .4; transition: opacity .12s; }
.b-inner:hover .b-actions { opacity: 1; }
.b-actions button { width: 25px; height: 25px; padding: 0; border-radius: 50%;
  background: var(--bg); border: 1px solid var(--border); font-size: 12px; line-height: 1; cursor: pointer; }
.b-actions .ok { color: var(--green-hi); border-color: var(--green-line); }
.b-actions .ok:hover { background: var(--green-soft); }
.b-actions .like:hover { background: #ddf4ff; }
.b-actions .dislike:hover { background: #ffebe9; }
.b-actions .fb.on { background: #ddf4ff; border-color: #54aeff; }
.b.liked .b-inner { box-shadow: 0 0 0 2px #54aeff; }
.b-src { font-size: 10.5px; color: var(--muted); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; max-width: 100%; }

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  body { font-size: 15px; }
  header.top { flex-wrap: wrap; gap: 10px 14px; padding: 10px 14px; }
  header.top nav { order: 3; width: 100%; gap: 4px; overflow-x: auto; }
  header.top .user { margin-left: auto; font-size: 12px; }
  .container, .container:has(.mosaic), .container:has(.legend) { max-width: 100%; padding: 0 12px; margin-top: 16px; }
  .toolbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .toolbar .row { justify-content: stretch; }
  .toolbar .row form, .toolbar .row button { flex: 1; }
  .legend { gap: 6px; overflow-x: auto; flex-wrap: nowrap; padding-bottom: 6px; }
  .leg { white-space: nowrap; }
  /* tiles: two small columns + full-width big ones */
  .b.s, .b.m, .b.w { width: 44vw; }
  .b.s { height: 140px; } .b.m { height: 180px; } .b.w { height: 150px; }
  .b.l, .b.xl, .b.xxl { width: 92vw; }
  .b.l { height: 165px; } .b.xl { height: 175px; } .b.xxl { height: 240px; }
  .grid[style] { grid-template-columns: 1fr !important; }  /* stack form grids */
  table, thead, tbody, th, td, tr { display: block; }
  thead { display: none; }
  td { border: 0; padding: 4px 0; }
  tr { border-bottom: 1px solid var(--border-muted); padding: 8px 0; }
}
.b-facts { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0 0; }
.b-facts .fact { font-size: 11px; background: var(--subtle); border: 1px solid var(--border);
  padding: 1px 7px; border-radius: 6px; color: #424a53; white-space: nowrap; }
.b-facts .fact.price { background: var(--green-soft); border-color: var(--green-line); color: var(--green-hi); font-weight: 600; }
