:root {
  --bg: #eceef0;
  --surface: #ffffff;
  --surface-2: #f2f3f6;
  --text: #23282a;
  --muted: #6f777a;
  --border: #dde1e4;
  --line: #e8ebed;
  --accent: #b9a7e0;
  --accent-strong: #7d68c4;
  --accent-soft: #ece6f9;
  --danger: #d9534f;
  --radius: 14px;
  --radius-sm: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden; overscroll-behavior: none;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }

.view { position: fixed; inset: 0; z-index: 50; }
#view-login { display: none; background: var(--bg); }
#view-login.show { display: block; }
.login { max-width: 340px; margin: 22vh auto 0; padding: 0 24px; text-align: center; }
.login h1 { font-size: 30px; margin: 0 0 6px; }
.login p { color: var(--muted); font-size: 14px; }
.field { width: 100%; padding: 13px 14px; margin: 8px 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); font-size: 16px; outline: none; }
.field:focus { border-color: var(--accent-strong); }
.btn { padding: 12px 18px; border-radius: var(--radius-sm); font-weight: 600; font-size: 15px; background: var(--accent-strong); color: #fff; }
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.err { color: var(--danger); min-height: 18px; font-size: 13px; }

/* horizontal pager */
.pager { height: 100dvh; width: 100vw; display: flex; overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory; scroll-snap-stop: always; scrollbar-width: none; background: var(--bg); }
.pager::-webkit-scrollbar { display: none; }
.page { flex: 0 0 100vw; width: 100vw; height: 100dvh; scroll-snap-align: start; position: relative; overflow: hidden; }

/* -------- feed -------- */
.feed { position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; scroll-snap-type: y mandatory; scroll-snap-stop: always; scrollbar-width: none; background: var(--bg); }
.feed::-webkit-scrollbar { display: none; }
.card { position: relative; width: 100%; height: 100%; scroll-snap-align: start; background: var(--surface-2); overflow: hidden; }
.card img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: var(--surface-2); }
/* fade to bottom instead of a text shadow */
.card .scrim { position: absolute; left: 0; right: 0; bottom: 0; height: 58%; pointer-events: none;
  background: linear-gradient(to top, rgba(0,0,0,0.74) 0%, rgba(0,0,0,0.38) 42%, rgba(0,0,0,0) 100%); }
.card .info { position: absolute; left: 16px; right: 76px; bottom: calc(12px + var(--safe-b)); color: #fff; }
.card .kicker { font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; font-weight: 700; color: #fff; opacity: .95; }
.card h2 { font-size: 24px; line-height: 1.16; margin: 6px 0 8px; color: #fff; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.card .tags { font-size: 12.5px; color: #fff; opacity: .95; }
.card .like-badge { position: absolute; top: calc(var(--safe-t) + 16px); left: 16px; font-size: 12px; padding: 5px 10px; border-radius: 10px; background: var(--accent-strong); color: #fff; opacity: 0; transition: opacity .2s; }
.card.liked .like-badge { opacity: 1; }

/* icons attached to the feed, flat 2D, white with a soft shadow (TikTok) */
.action-rail { position: absolute; right: 14px; bottom: calc(14px + var(--safe-b)); z-index: 5; display: flex; flex-direction: column; align-items: center; gap: 16px; }
.rail-btn { width: 46px; height: 46px; background: none; border: none; color: #fff; display: flex; align-items: center; justify-content: center; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.55)); }
.rail-btn svg { width: 30px; height: 30px; }
.rail-btn:active { transform: scale(0.92); }
.rail-btn.like.active { color: var(--accent); }
.rail-btn.like.active svg { fill: var(--accent); }

.top-fab { position: absolute; top: calc(var(--safe-t) + 8px); right: 14px; z-index: 5; width: 46px; height: 46px; background: none; border: none; color: #fff; font-size: 27px; display: flex; align-items: center; justify-content: center; filter: drop-shadow(0 1px 2px rgba(0,0,0,0.55)); }
.top-fab:active { transform: scale(0.92); }

.feed-back { position: absolute; top: calc(var(--safe-t) + 12px); left: 14px; z-index: 5; display: none; padding: 0 14px; height: 40px; border-radius: var(--radius-sm); background: rgba(0,0,0,0.4); color: #fff; font-weight: 600; font-size: 14px; }
.feed-back.show { display: inline-flex; align-items: center; }

.feed-hint { position: absolute; left: 50%; top: calc(var(--safe-t) + 60px); transform: translateX(-50%); color: var(--text); font-size: 12px; pointer-events: none; opacity: 0; transition: opacity .4s; white-space: nowrap; z-index: 6; background: var(--surface); border: 1px solid var(--border); padding: 6px 13px; border-radius: var(--radius-sm); box-shadow: 0 2px 8px rgba(25,35,30,0.10); }
.feed-hint.show { opacity: .96; }

/* -------- grid -------- */
#page-grid { background: var(--bg); }
.liked-head { padding: calc(var(--safe-t) + 14px) 18px 8px; font-size: 22px; font-weight: 700; }
.liked-grid { position: absolute; left: 0; right: 0; top: calc(var(--safe-t) + 58px); bottom: 0; overflow-y: auto; padding: 4px 14px calc(24px + var(--safe-b)); display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-content: start; }
.liked-grid .cell { position: relative; border-radius: var(--radius); overflow: hidden; aspect-ratio: 1 / 1; background: var(--surface-2); }
.liked-grid .cell img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.liked-grid .scrim { position: absolute; left: 0; right: 0; bottom: 0; height: 72%; pointer-events: none;
  background: linear-gradient(to top, rgba(0,0,0,0.82) 0%, rgba(0,0,0,0.45) 45%, rgba(0,0,0,0) 100%); }
.liked-grid .cap { position: absolute; left: 9px; right: 9px; bottom: 8px; color: #fff; font-weight: 600; font-size: 12px; line-height: 1.18; overflow: hidden; }
.liked-grid .empty { grid-column: 1 / -1; color: var(--muted); text-align: center; margin-top: 30vh; }

/* inline KI-Plan divider card */
.plan-card { position: relative; width: 100%; height: 100%; scroll-snap-align: start; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 32px 26px; }
.plan-card .inner { max-width: 420px; text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 26px 22px; box-shadow: 0 2px 10px rgba(25,35,30,0.06); }
.plan-card .kicker { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--accent-strong); font-weight: 700; margin-bottom: 12px; }
.plan-card .text { font-size: 18px; line-height: 1.42; }
.plan-card.loading .text { color: var(--muted); }
.plan-card .spinwrap { margin-top: 16px; display: flex; justify-content: center; }

/* -------- preferences (two halves) -------- */
.prefs-overlay { position: fixed; inset: 0; z-index: 62; display: none; flex-direction: column; background: var(--bg); }
.prefs-overlay.show { display: flex; }
.prefs-head { display: flex; align-items: center; justify-content: space-between; padding: calc(var(--safe-t) + 18px) 18px 8px; font-size: 21px; font-weight: 700; }
.prefs-top { flex: 1 1 50%; padding: 0 18px; overflow-y: auto; border-bottom: 1px solid var(--border); }
.prefs-label { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 14px 0 8px; }
.prefs-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 7px; padding: 7px 11px; border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--accent-strong); border: 1px solid #dbd0f4; font-size: 13.5px; font-weight: 600; }
.chip .x { color: var(--accent-strong); font-size: 15px; line-height: 1; opacity: .8; }
.chip.add { background: var(--surface); border: 1px dashed var(--border); color: var(--muted); font-weight: 500; }
.chip.sug { background: var(--surface); border: 1px dashed var(--accent); color: var(--accent-strong); }
.prefs-sug { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: 20px; }
.prefs-bottom { flex: 1 1 50%; padding: 8px 18px calc(16px + var(--safe-b)); background: var(--surface); display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }
.listen-btn { width: 100%; height: 62px; border-radius: 16px; background: var(--accent-strong); color: #fff; font-weight: 700; font-size: 17px; display: flex; align-items: center; justify-content: center; gap: 10px; }
.listen-btn svg { width: 26px; height: 26px; }
.listen-btn.rec { background: var(--danger); }
.filter-input { display: flex; gap: 8px; padding: 0; align-items: center; flex-wrap: wrap; }
.filter-input .field { flex: 1 1 160px; margin: 0; }
.filter-status { padding: 6px 0 0; color: var(--muted); font-size: 13px; min-height: 18px; }

/* -------- sheets + detail -------- */
.detail { position: absolute; inset: 0; overflow-y: auto; padding: calc(var(--safe-t) + 58px) 16px calc(28px + var(--safe-b)); -webkit-overflow-scrolling: touch; background: var(--bg); }
.detail .hero { width: 100%; height: 220px; border-radius: var(--radius); object-fit: cover; background: var(--surface-2); border: 1px solid var(--border); }
.detail h1 { font-size: 25px; margin: 14px 0 4px; }
.detail .meta { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.detail h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--accent-strong); margin: 20px 0 8px; }
.detail ul, .detail ol { margin: 0; padding-left: 20px; }
.detail li { margin-bottom: 7px; line-height: 1.45; }
.detail .tags { margin-top: 10px; color: var(--muted); font-size: 13px; }
.detail .like-row { display: flex; gap: 10px; margin-top: 18px; }
.detail .like-row .btn { flex: 1; }
.detail .empty { color: var(--muted); margin-top: 40vh; text-align: center; }

.sheet-overlay { position: fixed; inset: 0; z-index: 60; display: none; background: rgba(30,35,33,0.35); align-items: flex-end; }
.sheet-overlay.show { display: flex; }
.sheet { width: 100%; max-height: 86dvh; background: var(--surface); border-top: 1px solid var(--border); border-radius: 20px 20px 0 0; display: flex; flex-direction: column; padding-bottom: calc(8px + var(--safe-b)); animation: up .22s ease; }
@keyframes up { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 8px; font-weight: 700; font-size: 17px; }
.iconbtn { width: 36px; height: 36px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); font-size: 15px; }
.sheet-body { padding: 6px 18px 18px; overflow-y: auto; }
.row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: none; }
.row label { color: var(--muted); font-size: 14px; }
.badge { font-size: 12px; padding: 4px 10px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }

.heart-fly { position: fixed; z-index: 70; pointer-events: none; font-size: 90px; color: var(--accent-strong); opacity: 0; transform: scale(0.4); }
.heart-fly.pop { animation: heartpop .7s ease forwards; }
@keyframes heartpop { 0% { opacity: 0; transform: scale(0.3); } 25% { opacity: 1; transform: scale(1.1); } 70% { opacity: 1; transform: scale(1); } 100% { opacity: 0; transform: scale(1.15) translateY(-40px); } }
.toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%); background: #23282a; color: #fff; padding: 9px 16px; border-radius: var(--radius-sm); font-size: 13px; opacity: 0; transition: opacity .25s; z-index: 80; pointer-events: none; max-width: 88vw; text-align: center; }
.toast.show { opacity: 1; }

.plan-overlay { position: fixed; inset: 0; z-index: 55; display: none; align-items: center; justify-content: center; padding: 24px; background: var(--bg); }
.plan-overlay.show { display: flex; }
.plan-box { max-width: 420px; text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 28px 24px; box-shadow: 0 4px 18px rgba(25,35,30,0.08); }
.plan-kicker { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--accent-strong); font-weight: 700; margin-bottom: 12px; }
.plan-text { font-size: 19px; line-height: 1.4; margin-bottom: 22px; }
.plan-progress { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--muted); font-size: 13px; }
.spinner { width: 16px; height: 16px; border-radius: 50%; display: inline-block; border: 2px solid var(--border); border-top-color: var(--accent-strong); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
