/* 01. Theme tokens */
:root {
  color-scheme: light;
  --bg: #f4f8f4;
  --bg-glow-green: rgba(118, 211, 155, .2);
  --bg-glow-yellow: rgba(245, 184, 61, .13);
  --text: #17251e;
  --text-soft: #46574c;
  --muted: #66766c;
  --card: rgba(255, 255, 255, .82);
  --glass: rgba(255, 255, 255, .72);
  --topbar: rgba(246, 249, 246, .82);
  --nav: rgba(255, 255, 255, .82);
  --line: rgba(40, 70, 53, .14);
  --green: #168656;
  --green-bright: #16935f;
  --button-text: #ffffff;
  --green-soft: rgba(31, 169, 113, .13);
  --yellow: #f5b83d;
  --warning-bg: #fff1c9;
  --warning-text: #563e0a;
  --danger: #b42332;
  --shadow: 0 10px 35px rgba(38, 75, 52, .11);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang TC", "Noto Sans TC", sans-serif;
  color: var(--text);
  background: var(--bg);
  font-synthesis: none;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0e1512;
    --bg-glow-green: rgba(44, 126, 83, .12);
    --bg-glow-yellow: rgba(143, 112, 39, .08);
    --text: #edf5ef;
    --text-soft: #d0ded4;
    --muted: #a8b8ad;
    --card: rgba(29, 41, 34, .9);
    --glass: rgba(29, 41, 34, .78);
    --topbar: rgba(14, 21, 18, .86);
    --nav: rgba(25, 37, 30, .92);
    --line: rgba(226, 245, 232, .13);
    --green: #64d69c;
    --green-bright: #46c788;
    --button-text: #082016;
    --green-soft: rgba(70, 199, 136, .17);
    --yellow: #f4c45a;
    --warning-bg: #493b17;
    --warning-text: #ffe7a1;
    --danger: #ff8f98;
    --shadow: 0 10px 35px rgba(0, 0, 0, .34);
  }
}

/* 02. Base and layout */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: radial-gradient(ellipse at 12% 2%, var(--bg-glow-green), transparent 34%),
    radial-gradient(ellipse at 88% 18%, var(--bg-glow-yellow), transparent 32%), var(--bg);
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
button, input, textarea, select { color: inherit; font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .58; }
#app { max-width: 760px; min-height: 100vh; margin: auto; padding-bottom: 110px; }
.content { padding: 12px 18px 30px; }
.topbar {
  position: sticky;
  z-index: 8;
  top: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 18px 10px;
  background: var(--topbar);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(22px) saturate(170%);
  -webkit-backdrop-filter: blur(22px) saturate(170%);
}
.topbar h1 { flex: 1; margin: 0; font-size: 20px; }
.compact-home { position: fixed; top: 0; right: 0; left: 0; max-width: 760px; margin: auto; transform: translateY(-110%); transition: transform .2s ease; }
.compact-home.visible { transform: translateY(0); }
.back { width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--glass); font-size: 24px; }
.hero { padding: 24px 4px 10px; }
.hero h1 { margin: 6px 0; font-size: 34px; line-height: 1.1; letter-spacing: -1.5px; }
.hero p { margin: 8px 0 20px; color: var(--muted); }
.eyebrow { color: var(--green); font-size: 11px; font-weight: 800; letter-spacing: 1.5px; }
.page-title { margin: 10px 2px 22px; font-size: 34px; letter-spacing: -1px; }

/* 03. Glass surfaces and controls */
.glass, .card, .panel, .sheet {
  border: 1px solid var(--line);
  background: var(--glass);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  border-radius: 22px;
}
.panel { padding: 16px; margin: 12px 0; background: var(--card); }
.school-pill, .chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--glass);
  color: var(--text);
}
.school-pill svg { width: 19px; height: 19px; fill: none; stroke: var(--green); stroke-width: 1.8; }
.school-pill span { max-width: 245px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.searchbox { display: flex; align-items: center; gap: 10px; height: 52px; margin: 14px 0 20px; padding: 0 14px; color: var(--muted); }
.searchbox input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; }
.searchbox svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.search-symbol { display: inline-flex; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 22px 2px 12px; }
.section-head h2 { margin: 0; font-size: 19px; }
.section-head button { min-height: 44px; border: 0; background: transparent; color: var(--green); }
.categories { display: flex; gap: 10px; overflow-x: auto; padding: 2px 0 9px; scrollbar-width: none; }
.category { flex: 0 0 78px; min-height: 78px; padding: 10px 4px; border: 1px solid var(--line); border-radius: 20px; background: var(--glass); font-size: 12px; }
.category b { display: block; margin-bottom: 5px; font-size: 25px; }
.button { min-height: 48px; padding: 0 18px; border: 0; border-radius: 16px; background: var(--green-bright); color: var(--button-text); font-weight: 750; }
.button.secondary { background: var(--green-soft); color: var(--green); }
.button.ghost { border: 1px solid var(--line); background: var(--glass); color: var(--text); }
.button.full { width: 100%; }
.row { display: flex; align-items: center; gap: 10px; }
.row > * { flex: 1; }
.field { margin: 14px 0; }
.field label { display: block; margin: 0 0 7px; font-size: 13px; font-weight: 700; }
.field input:not([type=checkbox]):not([type=radio]), .field textarea, .field select, .sort-select, .row input {
  width: 100%; min-height: 46px; padding: 12px; border: 1px solid var(--line); border-radius: 14px; outline-color: var(--green); background: var(--glass);
}
.field textarea { min-height: 100px; resize: vertical; }
.sort-select { width: auto; min-height: 42px; border-radius: 999px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip.selected { border-color: var(--green-bright); background: var(--green-bright); color: var(--button-text); }
.state-options { display: grid; gap: 7px; }
.state-option { padding: 10px; border: 1px solid var(--line); border-radius: 14px; background: var(--glass); text-align: left; }
.state-option.selected { border: 2px solid var(--green-bright); }
.error { min-height: 0; margin-top: 4px; color: var(--danger); font-size: 12px; }
.error:empty { display: none; }

/* 04. Item cards and detail */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.item-card { position: relative; overflow: hidden; cursor: pointer; transition: transform .2s; }
.item-card:active { transform: scale(.98); }
.thumb { position: relative; display: grid; aspect-ratio: 1; place-items: center; background: linear-gradient(140deg, var(--c1, #daf3e3), var(--c2, #f8edcf)); font-size: 76px; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.badge { position: absolute; top: 9px; left: 9px; padding: 5px 9px; border-radius: 99px; background: var(--yellow); color: #49360c; font-size: 11px; font-weight: 800; }
.heart { position: absolute; top: 8px; right: 8px; width: 38px; height: 38px; border: 0; border-radius: 50%; background: rgba(255,255,255,.88); color: #a51c38; font-size: 19px; }
.item-info { padding: 11px; }
.item-title { display: -webkit-box; min-height: 0; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; font-size: 14px; line-height: 1.4; font-weight: 700; }
.price { margin: 6px 0; color: var(--green); font-size: 18px; font-weight: 800; }
.detail-price { font-size: 25px; }
.saving { display: inline-block; padding: 4px 7px; border-radius: 8px; background: var(--green-soft); font-size: 11px; vertical-align: middle; }
.state { display: inline-block; margin-top: 4px; padding: 4px 8px; border-radius: 99px; background: var(--green-soft); color: var(--green); font-size: 11px; }
.meta, .muted { color: var(--muted); }
.meta { font-size: 11px; line-height: 1.6; }
.carousel { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; border-radius: 22px; }
.carousel-slide { flex: 0 0 100%; aspect-ratio: 1; overflow: hidden; scroll-snap-align: center; background: var(--glass); }
.carousel-slide > img, .carousel-slide .thumb { width: 100%; height: 100%; object-fit: cover; border-radius: 22px; }
.dots { display: flex; justify-content: center; gap: 7px; margin: 10px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); opacity: .45; }
.dots i.active { width: 18px; border-radius: 9px; background: var(--green-bright); opacity: 1; }
.profile { display: flex; align-items: center; gap: 14px; }
.profile h2 { margin: 0; }
.avatar { display: grid; flex: none; width: 58px; height: 58px; place-items: center; border-radius: 50%; background: linear-gradient(135deg,#78d49f,#f5d684); color: #174b32; font-size: 24px; font-weight: 800; }
.divider { height: 1px; margin: 14px 0; background: var(--line); }

/* 05. Navigation, sheet and toast */
.bottom-nav { position: fixed; z-index: 15; bottom: calc(10px + env(safe-area-inset-bottom)); left: 50%; display: flex; align-items: center; justify-content: space-around; width: min(94%, 520px); height: 72px; padding: 5px 8px; transform: translateX(-50%); border: 1px solid var(--line); border-radius: 28px; background: var(--nav); box-shadow: var(--shadow); backdrop-filter: blur(26px) saturate(180%); -webkit-backdrop-filter: blur(26px) saturate(180%); }
.tab { position: relative; display: flex; min-width: 54px; min-height: 56px; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border: 0; background: transparent; color: var(--muted); font-size: 11px; }
.tab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.tab.active { color: var(--green); font-weight: 800; }
.tab-post { width: 54px; height: 54px; min-width: 54px; border-radius: 20px; background: var(--green-bright); color: var(--button-text); box-shadow: 0 6px 15px rgba(31,169,113,.35); }
.tab-post svg { width: 28px; height: 28px; stroke-width: 2.2; }
.dot { position: absolute; top: 6px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: #e23d4f; }
.sheet-backdrop { position: fixed; z-index: 30; inset: 0; display: flex; align-items: flex-end; justify-content: center; background: rgba(0,0,0,.48); }
.sheet { width: min(100%, 680px); max-height: 88vh; overflow: auto; padding: 12px 18px calc(24px + env(safe-area-inset-bottom)); border-radius: 28px 28px 0 0; background: var(--glass); animation: rise .25s ease; }
.grab { width: 40px; height: 4px; margin: 0 auto 16px; border-radius: 9px; background: var(--muted); opacity: .7; }
.sheet h2 { margin: 4px 0 16px; }
.school-list, .place-group { display: grid; gap: 8px; margin: 12px 0; }
.school-list .chip { justify-content: flex-start; }
.school-list svg { width: 18px; height: 18px; fill: none; stroke: var(--green); }
.place-card { min-height: 60px; flex-direction: column; align-items: flex-start; justify-content: center; border-radius: 16px; }
.place-card small { color: var(--muted); font-size: 11px; }
.place-card.selected small { color: var(--button-text); opacity: .78; }
#toast { position: fixed; z-index: 60; bottom: calc(98px + env(safe-area-inset-bottom)); left: 50%; max-width: 90%; padding: 12px 18px; transform: translate(-50%,12px); border-radius: 99px; background: var(--text); color: var(--bg); opacity: 0; pointer-events: none; text-align: center; transition: .2s; }
#toast.show { transform: translate(-50%,0); opacity: 1; }

/* 06. Chat, form and safety */
.chat-list { display: flex; align-items: center; gap: 12px; padding: 12px; cursor: pointer; }
.chat-list .thumb { flex: none; width: 56px; height: 56px; border-radius: 14px; font-size: 28px; }
.chat-list .thumb img { border-radius: 14px; }
.chat-preview { flex: 1; min-width: 0; }
.chat-preview .meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-page { position: fixed; inset: calc(62px + env(safe-area-inset-top)) 0 0; display: flex; max-width: 760px; flex-direction: column; margin: auto; padding: 8px 18px calc(72px + env(safe-area-inset-bottom)); }
.chat-product { display: flex; flex: none; align-items: center; gap: 12px; padding: 10px; margin: 0 0 8px; }
.chat-product-link { display: flex; flex: 1; align-items: center; gap: 12px; min-width: 0; cursor: pointer; }
.chat-product > span { font-size: 30px; }
.chat-product > div { flex: 1; }
.chat-product .price { margin: 2px 0 0; font-size: 14px; }
.meetup-launch { flex: none; }
.messages { flex: 1; overflow-y: auto; padding: 8px 0 16px; overscroll-behavior: contain; }
.bubble { max-width: 80%; margin: 8px 0; padding: 11px 14px; border-radius: 19px; background: var(--glass); box-shadow: 0 3px 12px rgba(0,0,0,.08); line-height: 1.5; overflow-wrap: anywhere; }
.bubble.mine { margin-left: auto; border-bottom-right-radius: 5px; background: var(--green-bright); color: var(--button-text); }
.bubble.theirs { border-bottom-left-radius: 5px; }
.warning { margin: 6px 0 10px; padding: 9px; border-radius: 12px; background: var(--warning-bg); color: var(--warning-text); font-size: 12px; }
.chat-compose { position: fixed; z-index: 12; right: 0; bottom: 0; left: 0; display: flex; gap: 8px; max-width: 760px; margin: auto; padding: 9px 18px calc(10px + env(safe-area-inset-bottom)); background: var(--topbar); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); }
.chat-compose input { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 99px; padding: 12px 16px; background: var(--glass); }
.meet-card { margin: 10px 0; padding: 13px; border: 1px solid var(--green-bright); border-radius: 17px; background: var(--green-soft); }
.meet-card p { line-height: 1.5; }
.calendar-btn { min-height: 40px; }
.photo-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.photo-tile { position: relative; aspect-ratio: 1; }
.photo-tile img { width: 100%; height: 100%; border-radius: 12px; object-fit: cover; }
.photo-tile button { position: absolute; top: 3px; right: 3px; width: 26px; height: 26px; border: 0; border-radius: 50%; background: rgba(15,20,16,.8); color: #fff; font-size: 19px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; clip-path: inset(50%); }
.stats { display: flex; justify-content: space-between; text-align: center; }
.settings .button { margin: 4px 0; }
.empty { padding: 40px 16px; color: var(--muted); text-align: center; }
.empty b { display: block; margin-bottom: 10px; font-size: 42px; }
@keyframes rise { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (max-width: 380px) { .content { padding-right: 14px; padding-left: 14px; } .school-pill span { max-width: 205px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; } }
