*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f0f0f;
  --bg-card:   #1a1a1a;
  --bg-input:  #222222;
  --bg-raised: #2a2a2a;
  --border:    rgba(255,255,255,0.08);
  --border-hi: rgba(255,255,255,0.16);
  --text:      #f0ede8;
  --text-2:    #9a9690;
  --text-3:    #5a5753;
  --accent:    #c8b89a;
  --accent-dim:#7a6e5e;
  --green:     #4caf7d;
  --amber:     #e8a838;
  --blue:      #5b9cf6;
  --red:       #e05c5c;
  --radius:    12px;
  --radius-lg: 18px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body { height: 100%; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', sans-serif; font-size: 16px; line-height: 1.5; -webkit-font-smoothing: antialiased; overflow: hidden; }

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea { font-family: inherit; font-size: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }

.hidden { display: none !important; }

/* ── App shell ── */
#app { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }

/* ── Views ── */
.view { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* ── Top bar ── */
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 16px 10px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.topbar-title { font-size: 17px; font-weight: 600; flex: 1; letter-spacing: -0.3px; }
.topbar-sub { font-size: 12px; color: var(--text-2); margin-top: 1px; }
.icon-btn { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; border-radius: 10px; color: var(--text-2); transition: background 0.15s, color 0.15s; flex-shrink: 0; }
.icon-btn:active { background: var(--bg-raised); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ── Home screen ── */
#view-home { background: var(--bg); }
.home-scroll { flex: 1; overflow-y: auto; padding: 16px; padding-bottom: calc(80px + var(--safe-bottom)); }
.home-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; height: 60vh; color: var(--text-3); text-align: center; padding: 24px; }
.home-empty svg { width: 48px; height: 48px; opacity: 0.3; stroke: currentColor; fill: none; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
.home-empty p { font-size: 15px; }
.home-empty span { font-size: 13px; color: var(--text-3); }

.quest-card { background: var(--bg-card); border-radius: var(--radius-lg); border: 1px solid var(--border); padding: 16px; margin-bottom: 12px; transition: border-color 0.15s; }
.quest-card:active { border-color: var(--border-hi); }
.quest-card-top { display: flex; align-items: flex-start; gap: 12px; }
.quest-emoji { font-size: 28px; line-height: 1; flex-shrink: 0; }
.quest-meta { flex: 1; min-width: 0; }
.quest-name { font-size: 16px; font-weight: 600; letter-spacing: -0.2px; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quest-age { font-size: 12px; color: var(--text-3); }
.quest-status { font-size: 13px; color: var(--text-2); margin-top: 10px; line-height: 1.4; }
.quest-pills { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.pill { font-size: 11px; font-weight: 500; padding: 3px 8px; border-radius: 20px; letter-spacing: 0.02em; }
.pill-needs { background: rgba(92,159,246,0.12); color: var(--blue); }
.pill-products { background: rgba(76,175,125,0.12); color: var(--green); }
.pill-pins { background: rgba(232,168,56,0.12); color: var(--amber); }

.fab { position: fixed; bottom: calc(24px + var(--safe-bottom)); right: 20px; width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: var(--bg); display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 20px rgba(200,184,154,0.3); z-index: 10; transition: transform 0.15s; }
.fab:active { transform: scale(0.93); }
.fab svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; }

/* ── Settings modal ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 100; display: flex; flex-direction: column; justify-content: flex-end; }
.modal-sheet { background: var(--bg-card); border-radius: var(--radius-lg) var(--radius-lg) 0 0; padding: 0 0 calc(24px + var(--safe-bottom)); max-height: 85vh; overflow-y: auto; }
.modal-handle { width: 36px; height: 4px; background: var(--border-hi); border-radius: 2px; margin: 12px auto 16px; }
.modal-title { font-size: 16px; font-weight: 600; padding: 0 20px 16px; border-bottom: 1px solid var(--border); }
.settings-row { display: flex; align-items: center; gap: 14px; width: 100%; padding: 15px 20px; font-size: 15px; color: var(--text); border-bottom: 1px solid var(--border); transition: background 0.12s; }
.settings-row:active { background: var(--bg-raised); }
.settings-row svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; color: var(--text-2); flex-shrink: 0; }
.settings-row.danger { color: var(--red); }
.settings-row.danger svg { color: var(--red); }
.settings-credit { font-size: 12px; color: var(--text-3); text-align: center; padding: 20px; }

/* ── Quest view ── */
#view-quest { background: var(--bg); }
.quest-topbar { display: flex; align-items: center; gap: 10px; padding: 12px 16px 0; flex-shrink: 0; }
.quest-topbar-emoji { font-size: 22px; }
.quest-topbar-name { font-size: 16px; font-weight: 600; flex: 1; letter-spacing: -0.2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Tabs ── */
.tabs { display: flex; padding: 10px 16px 0; gap: 4px; flex-shrink: 0; }
.tab { flex: 1; padding: 8px 4px; font-size: 13px; font-weight: 500; color: var(--text-3); border-radius: 8px; text-align: center; transition: color 0.15s, background 0.15s; }
.tab.active { color: var(--accent); background: rgba(200,184,154,0.1); }
.tab-content { display: none; flex: 1; overflow-y: auto; }
.tab-content.active { display: flex; flex-direction: column; }

/* ── Summary card ── */
.summary-card { margin: 12px 16px 0; background: var(--bg-card); border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; flex-shrink: 0; }
.summary-header { display: flex; align-items: center; gap: 10px; padding: 12px 14px; cursor: pointer; }
.summary-header-label { font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); flex: 1; }
.summary-chevron { width: 16px; height: 16px; stroke: var(--text-3); fill: none; stroke-width: 2; stroke-linecap: round; transition: transform 0.2s; }
.summary-card.open .summary-chevron { transform: rotate(180deg); }
.summary-body { display: none; padding: 0 14px 14px; }
.summary-card.open .summary-body { display: block; }
.summary-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: flex-start; }
.summary-row:last-child { margin-bottom: 0; }
.summary-label { font-size: 11px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-3); width: 64px; flex-shrink: 0; padding-top: 2px; }
.summary-val { font-size: 13px; color: var(--text-2); flex: 1; line-height: 1.5; }
.summary-val em { color: var(--text); font-style: normal; }

/* ── Chat tab ── */
#tab-chat { padding-bottom: 0; }
.chat-messages { flex: 1; overflow-y: auto; padding: 12px 16px 8px; display: flex; flex-direction: column; gap: 10px; }
.msg { display: flex; flex-direction: column; gap: 4px; max-width: 88%; }
.msg-user { align-self: flex-end; align-items: flex-end; }
.msg-assistant { align-self: flex-start; align-items: flex-start; }
.msg-bubble { padding: 10px 14px; border-radius: 18px; font-size: 15px; line-height: 1.5; }
.msg-user .msg-bubble { background: var(--accent); color: var(--bg); border-bottom-right-radius: 4px; }
.msg-assistant .msg-bubble { background: var(--bg-card); border: 1px solid var(--border); border-bottom-left-radius: 4px; color: var(--text); }
.msg-time { font-size: 11px; color: var(--text-3); padding: 0 4px; }

/* Rich response blocks inside assistant bubbles */
.r-comparison { margin: 8px 0; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.r-comparison-title { font-size: 12px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-3); padding: 10px 12px 6px; }
.r-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.r-table th { padding: 6px 10px; background: var(--bg-raised); color: var(--text-2); font-weight: 600; text-align: left; font-size: 12px; }
.r-table td { padding: 7px 10px; border-top: 1px solid var(--border); color: var(--text); vertical-align: top; line-height: 1.4; }
.r-table tr:last-child td { border-bottom: none; }
.td-win { color: var(--green); font-weight: 500; }

.r-insight { margin: 8px 0; background: rgba(200,184,154,0.06); border-left: 2px solid var(--accent-dim); border-radius: 0 8px 8px 0; padding: 10px 12px; font-size: 14px; color: var(--text-2); line-height: 1.5; }
.r-recommendation { margin: 8px 0; border-radius: 10px; border: 1px solid rgba(76,175,125,0.3); background: rgba(76,175,125,0.05); padding: 12px; }
.r-recommendation-pick { font-size: 15px; font-weight: 600; color: var(--green); margin-bottom: 6px; }
.r-recommendation-reason { font-size: 14px; color: var(--text-2); line-height: 1.5; }

.pin-btn { display: inline-flex; align-items: center; gap: 5px; margin-top: 8px; font-size: 12px; color: var(--accent-dim); padding: 4px 0; transition: color 0.15s; }
.pin-btn:active { color: var(--accent); }
.pin-btn svg { width: 13px; height: 13px; stroke: currentColor; fill: none; stroke-width: 2; }
.pin-btn.pinned { color: var(--amber); }

.typing-indicator { display: flex; align-items: center; gap: 5px; padding: 12px 14px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 18px; border-bottom-left-radius: 4px; align-self: flex-start; }
.typing-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); animation: bounce 1.2s ease-in-out infinite; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-5px); } }

.chat-input-bar { padding: 10px 12px calc(10px + var(--safe-bottom)); border-top: 1px solid var(--border); display: flex; gap: 10px; align-items: flex-end; background: var(--bg); flex-shrink: 0; }
.chat-input { flex: 1; background: var(--bg-input); border: 1px solid var(--border); border-radius: 22px; padding: 10px 16px; font-size: 15px; color: var(--text); resize: none; max-height: 120px; line-height: 1.4; outline: none; }
.chat-input:focus { border-color: var(--border-hi); }
.chat-input::placeholder { color: var(--text-3); }
.send-btn { width: 40px; height: 40px; border-radius: 50%; background: var(--accent); color: var(--bg); display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: opacity 0.15s, transform 0.1s; }
.send-btn:disabled { opacity: 0.3; }
.send-btn:not(:disabled):active { transform: scale(0.92); }
.send-btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* ── Criteria tab ── */
.tab-inner { padding: 14px 16px; display: flex; flex-direction: column; gap: 16px; }
.criteria-section { }
.criteria-section-title { font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 8px; }
.criteria-section-title.needs { color: var(--blue); }
.criteria-section-title.nice { color: var(--green); }
.criteria-section-title.bonus { color: var(--text-3); }
.criteria-list { display: flex; flex-direction: column; gap: 6px; }
.criteria-item { background: var(--bg-card); border-radius: 10px; padding: 11px 14px; font-size: 14px; color: var(--text); border: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.criteria-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.criteria-dot.needs { background: var(--blue); }
.criteria-dot.nice { background: var(--green); }
.criteria-dot.bonus { background: var(--text-3); }
.criteria-empty { font-size: 13px; color: var(--text-3); padding: 8px 0; }

/* ── Products tab ── */
.product-card { background: var(--bg-card); border-radius: var(--radius); border: 1px solid var(--border); margin-bottom: 10px; overflow: hidden; }
.product-card-header { display: flex; align-items: center; gap: 12px; padding: 14px; cursor: pointer; }
.product-name { font-size: 15px; font-weight: 600; flex: 1; }
.product-score { font-size: 13px; font-weight: 600; color: var(--accent); }
.product-card-body { display: none; padding: 0 14px 14px; border-top: 1px solid var(--border); }
.product-card.open .product-card-body { display: block; }
.product-pros-cons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.pro-con-title { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; margin-bottom: 6px; }
.pro-con-title.pro { color: var(--green); }
.pro-con-title.con { color: var(--red); }
.pro-con-list { list-style: none; display: flex; flex-direction: column; gap: 4px; }
.pro-con-list li { font-size: 13px; color: var(--text-2); line-height: 1.4; }
.product-notes { font-size: 13px; color: var(--text-2); margin-top: 12px; line-height: 1.5; }
.product-url { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--accent-dim); margin-top: 10px; }
.add-product-btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 14px; border: 1px dashed var(--border-hi); border-radius: var(--radius); font-size: 14px; color: var(--text-3); margin-top: 4px; transition: border-color 0.15s, color 0.15s; }
.add-product-btn:active { border-color: var(--accent-dim); color: var(--accent); }

/* ── Pins tab ── */
.pin-card { background: var(--bg-card); border-radius: var(--radius); border: 1px solid var(--border); padding: 14px; margin-bottom: 10px; }
.pin-type-badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; margin-bottom: 8px; }
.pin-type-badge.comparison { color: var(--blue); }
.pin-type-badge.recommendation { color: var(--green); }
.pin-type-badge.insight { color: var(--amber); }
.pin-title { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.pin-content { font-size: 14px; color: var(--text-2); line-height: 1.6; }
.pin-date { font-size: 11px; color: var(--text-3); margin-top: 8px; }
.pins-empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 48px 24px; color: var(--text-3); text-align: center; font-size: 14px; }

/* ── New quest modal ── */
.new-quest-sheet { background: var(--bg-card); border-radius: var(--radius-lg) var(--radius-lg) 0 0; padding: 0 20px calc(24px + var(--safe-bottom)); }
.new-quest-label { font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); margin-bottom: 8px; }
.new-quest-input { width: 100%; background: var(--bg-input); border: 1px solid var(--border); border-radius: 12px; padding: 13px 16px; font-size: 16px; color: var(--text); outline: none; }
.new-quest-input:focus { border-color: var(--accent-dim); }
.emoji-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
.emoji-opt { width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 22px; background: var(--bg-input); border: 2px solid transparent; transition: border-color 0.12s; }
.emoji-opt.selected { border-color: var(--accent); }
.create-btn { width: 100%; padding: 15px; background: var(--accent); color: var(--bg); border-radius: var(--radius); font-size: 16px; font-weight: 600; letter-spacing: -0.2px; transition: opacity 0.15s; }
.create-btn:disabled { opacity: 0.4; }

/* ── API key setup ── */
.setup-view { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 32px 24px calc(32px + var(--safe-bottom)); text-align: center; gap: 20px; }
.setup-icon { font-size: 52px; margin-bottom: 4px; }
.setup-title { font-size: 22px; font-weight: 700; letter-spacing: -0.5px; }
.setup-desc { font-size: 15px; color: var(--text-2); line-height: 1.6; max-width: 320px; }
.setup-input { width: 100%; background: var(--bg-input); border: 1px solid var(--border); border-radius: 12px; padding: 13px 16px; font-size: 15px; color: var(--text); outline: none; text-align: left; }
.setup-input:focus { border-color: var(--accent-dim); }
.setup-btn { width: 100%; padding: 15px; background: var(--accent); color: var(--bg); border-radius: var(--radius); font-size: 16px; font-weight: 600; }
.setup-link { font-size: 13px; color: var(--accent-dim); }

/* ── Add product modal ── */
.product-form-field { margin-bottom: 16px; }
.field-label { font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); margin-bottom: 6px; }
.field-input { width: 100%; background: var(--bg-input); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; font-size: 15px; color: var(--text); outline: none; }
.field-input:focus { border-color: var(--accent-dim); }
.field-input::placeholder { color: var(--text-3); }
textarea.field-input { resize: none; min-height: 80px; line-height: 1.5; }

/* ── Toast ── */
.toast { position: fixed; bottom: calc(20px + var(--safe-bottom)); left: 50%; transform: translateX(-50%) translateY(20px); background: var(--bg-raised); border: 1px solid var(--border-hi); color: var(--text); font-size: 14px; padding: 10px 18px; border-radius: 24px; opacity: 0; transition: opacity 0.2s, transform 0.2s; z-index: 200; white-space: nowrap; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Scrollbars ── */
::-webkit-scrollbar { width: 0; }
