/* ============================================================
   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;
  /* solid surfaces so every block looks identical regardless of the
     background glow behind it */
  --box-bg: #14161d;
  --card-bg: #1b1e27;
  --card-bg-hover: #232734;
  --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; }

/* No accidental zoom on touchscreens — behave like a native app.
   pan-x pan-y keeps scrolling but blocks pinch & double-tap zoom;
   text-size-adjust stops mobile from auto-resizing text. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { touch-action: pan-x pan-y; overscroll-behavior-y: none; }

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(--box-bg);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  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(--card-bg);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
  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(--card-bg-hover);
  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 source editor (shown in Edit mode) */
.feed-edit { display: none; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--stroke); }
body.editing .feed-edit { display: block; }
.feed-edit-title { font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.feed-list { list-style: none; margin: 0 0 10px; padding: 0; }
.feed-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0; font-size: 13px; }
.feed-del { border: none; background: transparent; color: var(--muted); font-size: 17px; line-height: 1; cursor: pointer; padding: 0 4px; }
.feed-del:hover { color: var(--danger); }
.feed-add { width: 100%; padding: 8px; border: 1px dashed var(--stroke-strong); border-radius: 10px; background: var(--glass); color: var(--accent); font-size: 13px; font-weight: 600; cursor: pointer; }
.feed-add:hover { border-color: var(--accent); }

/* news — near-fixed height with internal scroll so it never dominates
   and the masonry stays balanced even after headlines load in */
.news-scroll { min-height: 260px; max-height: 320px; 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: 90;   /* above the Life Saver overlay (70) */
  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; }
.install-help p { margin: 0 0 10px; font-size: 14px; }
.install-help ol { margin: 0 0 8px; padding-left: 20px; font-size: 14px; line-height: 1.8; }
.install-help b { color: var(--text); }
.ih-ic { display: inline-block; transform: translateY(1px); }
.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;
}

/* ---------------- NETWORK WIDGET ---------------- */
.net-speed { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.net-mbps { font-size: 30px; font-weight: 700; line-height: 1.1; }
.net-mbps small { font-size: 14px; font-weight: 600; color: var(--muted); margin-left: 3px; }
.net-dim { color: var(--muted); }
.net-testing { font-size: 18px; color: var(--accent); }
.net-btns { display: flex; gap: 6px; }
.net-test {
  padding: 7px 12px; border: 1px solid var(--stroke); border-radius: 10px;
  background: var(--glass); color: var(--text); font-size: 12px; font-weight: 600; cursor: pointer;
}
.net-test:hover:not(:disabled) { border-color: var(--accent); }
.net-test:disabled { opacity: .6; cursor: default; }
.net-test.on { border-color: #16b39a; color: #2fe0c4; background: rgba(22,179,154,0.12); }
.net-ping { font-size: 12px; color: var(--muted); margin: 4px 0 12px; min-height: 14px; }
.net-rows { display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid var(--stroke); }
.net-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px; }
.net-row span { color: var(--muted); }
.net-row b { font-weight: 600; text-align: right; word-break: break-all; }

/* ---------------- CLOCK ---------------- */
.clock {
  display: flex; flex-direction: column; align-items: flex-end;
  line-height: 1.1; margin-right: 4px;
}
.clock-time { font-size: 18px; font-weight: 700; }
.clock-date { font-size: 11px; color: var(--muted); }

/* ---------------- SEARCH BAR ---------------- */
.searchbar {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  margin: 0 0 22px;
  padding: 12px 16px;
  background: var(--box-bg);
  border: 1px solid var(--stroke);
  border-radius: 14px;
}
.searchbar:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(109,124,255,0.18); }
.search-ico { font-size: 15px; opacity: .7; }
#search {
  flex: 1; border: none; background: transparent;
  color: var(--text); font-size: 15px; outline: none;
}
.search-clear {
  border: none; background: var(--glass); color: var(--muted);
  width: 24px; height: 24px; border-radius: 7px; cursor: pointer; font-size: 16px; line-height: 1;
}
.search-clear:hover { color: var(--text); }
.search-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 14px;
}
.search-empty { color: var(--muted); font-size: 14px; padding: 8px 2px; }

/* ---------------- ANIMATIONS ---------------- */
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.board.intro .box { animation: fadeUp .45s ease both; }
.board.intro .box:nth-child(2) { animation-delay: .05s; }
.board.intro .box:nth-child(3) { animation-delay: .10s; }
.board.intro .box:nth-child(n+4) { animation-delay: .15s; }
.card-icon, .card-fallback { transition: transform .15s ease; }
.card:hover .card-icon, .card:hover .card-fallback { transform: scale(1.06); }

/* ---------------- DRAG ---------------- */
.card { cursor: pointer; }
.card.dragging { opacity: .35; }
.box-grid { border-radius: 12px; }

/* ---------------- LIFE SAVER BUTTON ---------------- */
.btn.lifesaver { background: linear-gradient(180deg, #16b39a, #0e8f7c); }
.btn.lifesaver:hover { box-shadow: 0 12px 30px rgba(22,179,154,0.30); }

/* ---------------- LIFE SAVER (vault) ---------------- */
.vault {
  position: fixed; inset: 0; z-index: 70;
  display: flex; flex-direction: column;
  padding: 22px;
  background:
    radial-gradient(900px 600px at 50% -10%, rgba(22,179,154,0.12), transparent 60%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0));
}
body.vault-open { overflow: hidden; }
.vault-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap; margin-bottom: 16px;
}
.vault-title { font-size: 22px; font-weight: 700; }
.vault-title span { font-size: 13px; font-weight: 400; color: var(--muted); margin-left: 8px; }
.vault-actions { display: flex; gap: 10px; }

.vault-searchbar {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px; margin-bottom: 14px;
  background: var(--box-bg); border: 1px solid var(--stroke); border-radius: 14px;
}
.vault-searchbar:focus-within { border-color: #16b39a; box-shadow: 0 0 0 3px rgba(22,179,154,0.18); }
#vault-search { flex: 1; border: none; background: transparent; color: var(--text); font-size: 16px; outline: none; }

.vault-cats { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.vchip {
  padding: 7px 13px; border: 1px solid var(--stroke); border-radius: 999px;
  background: var(--glass); color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all .12s;
}
.vchip:hover { color: var(--text); border-color: var(--stroke-strong); }
.vchip.active { color: #fff; background: linear-gradient(180deg, rgba(22,179,154,0.30), rgba(14,143,124,0.18)); border-color: #16b39a; }

.vault-scroll { flex: 1; overflow-y: auto; padding-right: 4px; }
.vault-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 14px;
}
.vault-status { margin-top: 10px; }
.vault-empty { color: var(--muted); font-size: 14px; line-height: 1.6; text-align: center; padding: 40px 12px; }
.vault-more {
  display: block; margin: 18px auto; padding: 10px 22px;
  border: 1px solid var(--stroke); border-radius: 12px; background: var(--glass);
  color: var(--text); font-size: 14px; font-weight: 600; cursor: pointer;
}
.vault-more:hover { border-color: #16b39a; }

@media (max-width: 680px) {
  .vault { padding: 16px; }
  .vault-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
}

/* ---------------- 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)); }
}
