/* ============================================================
   My Digital Library — Dark "Soft Glass" theme
   ============================================================ */

:root {
  --bg-0: #0b0d12;
  --bg-1: #11141b;
  --glass: rgba(255, 255, 255, 0.04);
  --glass-2: rgba(255, 255, 255, 0.06);
  --stroke: rgba(255, 255, 255, 0.08);
  --stroke-strong: rgba(255, 255, 255, 0.14);
  --text: #e8eaf0;
  --muted: #9aa3b2;
  --accent: #6d7cff;
  --accent-2: #4f46e5;
  --danger: #f06565;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --shadow-hi: 0 18px 50px rgba(79, 70, 229, 0.30);
}

* { box-sizing: border-box; }

/* HTML `hidden` must always win over author display rules */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 12% -8%, rgba(109, 124, 255, 0.18), transparent 55%),
    radial-gradient(1000px 700px at 110% 0%, rgba(79, 70, 229, 0.14), transparent 50%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0));
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

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

/* ---------------- LOGIN ---------------- */
.login-overlay {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 600px at 50% -10%, rgba(109,124,255,0.25), transparent 60%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0));
  z-index: 50;
}
.login-card {
  width: 100%; max-width: 360px;
  display: flex; flex-direction: column; gap: 14px;
  padding: 34px 28px;
  background: var(--glass-2);
  border: 1px solid var(--stroke);
  border-radius: 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  text-align: center;
}
.login-logo { font-size: 40px; }
.login-card h1 { margin: 4px 0 0; font-size: 20px; }
.login-tag { margin: 0 0 6px; color: var(--muted); font-size: 13px; }
.login-card input {
  width: 100%;
  padding: 13px 14px;
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--stroke);
  border-radius: 12px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.login-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(109,124,255,0.25);
}
#login-btn {
  margin-top: 4px;
  padding: 13px;
  border: none; border-radius: 12px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 15px; font-weight: 600;
  cursor: pointer;
  transition: transform .12s, box-shadow .12s, opacity .12s;
}
#login-btn:hover { box-shadow: var(--shadow-hi); transform: translateY(-1px); }
#login-btn:disabled { opacity: .7; cursor: default; }
.login-error { color: var(--danger); font-size: 13px; min-height: 16px; }

body.locked #app { display: none; }

/* ---------------- TOPBAR ---------------- */
#app { max-width: 1180px; margin: 0 auto; padding: 26px 22px 60px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 18px; flex-wrap: wrap;
  margin-bottom: 20px;
}
.brand h1 { margin: 0; font-size: 24px; letter-spacing: .2px; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 14px; }

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

.weather { display: block; }

.btn {
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 14px; font-weight: 600;
  cursor: pointer;
  transition: transform .12s, box-shadow .12s, background .12s, border-color .12s;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-hi); }
.btn.ghost {
  background: var(--glass-2);
  border-color: var(--stroke);
  color: var(--text);
  font-weight: 500;
}
.btn.ghost:hover { border-color: var(--stroke-strong); box-shadow: none; }
.btn.ghost.active { border-color: var(--accent); color: #fff; }
.btn.danger { background: linear-gradient(180deg, #ff7a7a, #e04848); }

/* ---------------- BOARD (masonry columns) ---------------- */
.board {
  display: flex;
  gap: 18px;
  align-items: flex-start;   /* each column tops out independently */
}
.board-col {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ---------------- BOX (one category / widget) ---------------- */
.box {
  width: 100%;
  margin: 0;
  padding: 18px 18px 20px;
  background: var(--glass-2);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}
.box-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 14px;
}
.box-head h3 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: .2px; }
.box-tools { display: none; gap: 6px; flex-wrap: wrap; }
body.editing .box-tools { display: flex; }

.box-sub {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin: 16px 0 10px;
}
.box-sub h4 {
  margin: 0; font-size: 12px; font-weight: 700; letter-spacing: .6px;
  text-transform: uppercase; color: var(--muted);
}
.sub-tools { display: none; gap: 6px; }
body.editing .sub-tools { display: flex; }

/* add-category button styled like a dashed box */
.add-box {
  display: none;
  width: 100%;
  padding: 22px;
  border: 1px dashed var(--stroke-strong);
  border-radius: var(--radius);
  background: var(--glass);
  color: var(--accent);
  font-size: 14px; font-weight: 600;
  cursor: pointer;
}
body.editing .add-box { display: block; }

/* ---------------- GRID + CARDS ---------------- */
.box-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 12px;
}
.card {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px;
  padding: 16px 10px;
  min-height: 112px;
  background: var(--glass-2);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
  backdrop-filter: blur(10px);
  transition: transform .15s, box-shadow .15s, border-color .15s, background .15s;
  -webkit-tap-highlight-color: transparent;
}
.card:hover {
  transform: translateY(-4px);
  border-color: var(--accent);
  background: var(--glass-2);
  box-shadow: var(--shadow-hi);
}
.card.placeholder { border-style: dashed; opacity: .8; }
.card.placeholder:hover { opacity: 1; }

.card-icon {
  width: 48px; height: 48px;
  border-radius: 13px;
  background: #fff;
  padding: 6px;
  object-fit: contain;
}
.card-fallback {
  width: 48px; height: 48px;
  display: grid; place-items: center;
  border-radius: 13px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 22px; font-weight: 700;
}
.card-fallback.is-empty {
  background: var(--glass);
  border: 1px dashed var(--stroke-strong);
  color: var(--muted);
}
.card-label {
  font-size: 14px; font-weight: 500;
  color: var(--text);
  word-break: break-word;
}

/* per-card edit/delete tools */
.card-tools {
  position: absolute; top: 8px; right: 8px;
  display: none; gap: 6px;
}
body.editing .card-tools { display: flex; }
.card.add-card { display: none; }
body.editing .card.add-card { display: flex; }

.mini {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border: 1px solid var(--stroke);
  border-radius: 8px;
  background: rgba(0,0,0,0.35);
  color: var(--text);
  font-size: 13px; line-height: 1;
  cursor: pointer;
  transition: border-color .12s, color .12s, background .12s;
}
.mini:hover { border-color: var(--accent); }
.mini.danger:hover { border-color: var(--danger); color: var(--danger); }
.box-tools .mini, .sub-tools .mini { width: auto; padding: 5px 10px; font-size: 12px; }

/* ---------------- WEATHER BOX ---------------- */
.wx-loading { color: var(--muted); font-size: 13px; }
.wx-now { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.wx-ico { font-size: 40px; line-height: 1; }
.wx-meta { display: flex; flex-direction: column; }
.wx-temp { font-size: 28px; font-weight: 700; line-height: 1.1; }
.wx-sub { font-size: 13px; color: var(--muted); }
.wx-days {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 8px; padding-top: 12px;
  border-top: 1px solid var(--stroke);
}
.wx-day {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  text-align: center;
}
.wx-dname { font-size: 11px; color: var(--muted); }
.wx-dico { font-size: 20px; }
.wx-dhl { font-size: 12px; font-weight: 600; }
.wx-dhl i { color: var(--muted); font-style: normal; font-weight: 400; margin-left: 3px; }

/* change-location control */
.wx-loc { margin-top: 14px; }
.wx-loc-btn {
  background: none; border: none; padding: 0;
  color: var(--muted); font-size: 12px; cursor: pointer;
}
.wx-loc-btn:hover { color: var(--accent); }
.wx-picker { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.wx-picker input {
  padding: 9px 11px; background: rgba(0,0,0,0.25);
  border: 1px solid var(--stroke); border-radius: 10px;
  color: var(--text); font-size: 13px; outline: none;
}
.wx-picker input:focus { border-color: var(--accent); }
.wx-auto {
  text-align: left; background: var(--glass);
  border: 1px solid var(--stroke); border-radius: 10px;
  color: var(--text); font-size: 12px; padding: 8px 11px; cursor: pointer;
}
.wx-auto:hover { border-color: var(--accent); }
.wx-results { display: flex; flex-direction: column; gap: 4px; max-height: 180px; overflow-y: auto; }
.wx-result {
  text-align: left; background: transparent;
  border: 1px solid transparent; border-radius: 8px;
  color: var(--text); font-size: 13px; padding: 7px 9px; cursor: pointer;
}
.wx-result:hover { background: var(--glass); border-color: var(--stroke); }
.wx-result span { color: var(--muted); font-size: 11px; margin-left: 4px; }
.wx-noresult { color: var(--muted); font-size: 12px; padding: 6px; }

/* local news group highlight */
.news-group.local .news-source { color: #4ade80; }

/* news — near-fixed height with internal scroll so it never dominates
   and the masonry stays balanced even after headlines load in */
#news { min-height: 280px; max-height: 340px; overflow-y: auto; padding-right: 4px; }
.news-loading { color: var(--muted); font-size: 13px; padding: 4px 0; }
.news-group { margin-bottom: 14px; }
.news-source {
  font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase;
  color: var(--accent); margin-bottom: 6px;
}
.news-list { list-style: none; margin: 0; padding: 0; }
.news-list li { margin: 0 0 7px; }
.news-list a {
  color: var(--text); text-decoration: none; font-size: 13.5px; line-height: 1.4;
  display: block; transition: color .12s;
}
.news-list a:hover { color: var(--accent); }

/* shopping */
.shop-input {
  width: 100%;
  padding: 10px 12px;
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--stroke);
  border-radius: 10px;
  color: var(--text); font-size: 14px;
  outline: none; margin-bottom: 12px;
}
.shop-input:focus { border-color: var(--accent); }
.shop-list { list-style: none; margin: 0; padding: 0; }
.shop-empty { color: var(--muted); font-size: 13px; }
.shop-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 6px;
  border-bottom: 1px solid var(--stroke);
  cursor: pointer;
}
.shop-item:last-child { border-bottom: none; }
.shop-box { font-size: 16px; }
.shop-text { flex: 1; font-size: 14px; }
.shop-item.done .shop-text { text-decoration: line-through; color: var(--muted); }
.shop-del {
  border: none; background: transparent; color: var(--muted);
  font-size: 18px; cursor: pointer; line-height: 1; padding: 0 4px;
}
.shop-del:hover { color: var(--danger); }

/* ---------------- MODAL ---------------- */
.modal {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  padding: 20px;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
}
.modal-card {
  width: 100%; max-width: 380px;
  background: var(--bg-1);
  border: 1px solid var(--stroke-strong);
  border-radius: 18px;
  padding: 22px;
  box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0 0 14px; }
.modal-card label {
  display: block; font-size: 13px; color: var(--muted); margin-bottom: 14px;
}
.modal-card input {
  width: 100%; margin-top: 6px;
  padding: 11px 12px;
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--stroke);
  border-radius: 10px; color: var(--text); font-size: 14px; outline: none;
}
.modal-card input:focus { border-color: var(--accent); }
.modal-hint { font-size: 12px; color: var(--muted); margin: 0 0 16px; }
.auto-tag {
  display: inline-block; margin-left: 6px;
  font-size: 10px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase;
  color: var(--accent);
  padding: 1px 7px; border: 1px solid var(--accent); border-radius: 999px;
  vertical-align: middle;
}
.modal-actions { display: flex; align-items: center; gap: 10px; }
.modal-actions .spacer { flex: 1; }

/* ---------------- FOOTER ---------------- */
.foot {
  margin-top: 40px; text-align: center;
  color: var(--muted); font-size: 12px;
}

/* ---------------- RESPONSIVE ----------------
   Column COUNT is handled in JS (masonry); these just tune spacing. */
@media (max-width: 680px) {
  .brand h1 { font-size: 20px; }
  .topbar { gap: 12px; }
  .box-grid { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); }
}
