:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #111827;
  --ink-2: #374151;
  --muted: #6b7280;
  --line: #e5e7eb;
  --hover: #f3f4f6;
  --brand: #ea580c;
  --brand-ink: #ffffff;
  --brand-soft: #fff1e8;
  --go: #15803d;
  --go-soft: #e8f6ed;
  --no: #b91c1c;
  --no-soft: #fdecec;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0e1013;
    --card: #171a1f;
    --ink: #f3f4f6;
    --ink-2: #d1d5db;
    --muted: #9ca3af;
    --line: #2a2f37;
    --hover: #1f232a;
    --brand: #f97316;
    --brand-soft: #2b1a10;
    --go: #4ade80;
    --go-soft: #132a1c;
    --no: #f87171;
    --no-soft: #2e1616;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 15px/1.45 "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
#app {
  max-width: 560px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) 16px calc(env(safe-area-inset-bottom) + 88px);
}
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--brand); text-decoration: none; font-weight: 500; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Header */
.top { display: flex; align-items: center; gap: 10px; padding: 6px 0 12px; min-height: 52px; }
.top .title { flex: 1; font-size: 17px; font-weight: 600; }
.brand { display: flex; align-items: center; gap: 8px; flex: 1; font-size: 18px; font-weight: 700; }
.brand img { width: 28px; height: 28px; border-radius: 8px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--card);
  display: grid; place-items: center; cursor: pointer; color: var(--ink-2); padding: 0;
}
.icon-btn:active { background: var(--hover); }
.icon-btn.danger { color: var(--no); }

/* Notices */
.notice {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px 9px 12px; margin-bottom: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  font-size: 13px; color: var(--ink-2);
}
.notice .i { color: var(--brand); }
.notice .grow { flex: 1; }
.notice.demo { background: var(--brand-soft); border-color: transparent; }

/* List */
.section-title {
  font-size: 12px; font-weight: 600; color: var(--muted); margin: 16px 2px 6px;
  display: flex; justify-content: space-between;
}
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row {
  display: flex; gap: 12px; align-items: center; padding: 11px 12px; color: inherit; font-weight: 400;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row:active { background: var(--hover); }
.row.past { opacity: 0.55; }
.date {
  width: 40px; flex: none; text-align: center; line-height: 1.1;
  border: 1px solid var(--line); border-radius: 8px; padding: 4px 0;
}
.date small { display: block; font-size: 10px; font-weight: 600; text-transform: uppercase; color: var(--brand); letter-spacing: 0.04em; }
.date b { display: block; font-size: 16px; font-weight: 700; }
.row-main { flex: 1; min-width: 0; }
.row-main h3 { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta { color: var(--muted); font-size: 13px; }
.row-main .meta { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.badge { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 99px; background: var(--hover); color: var(--muted); white-space: nowrap; }
.badge.go { background: var(--go-soft); color: var(--go); }
.badge.no { background: var(--no-soft); color: var(--no); }
.badge.ask { background: var(--brand); color: var(--brand-ink); }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; font-size: 14px; }
.empty .i { width: 28px; height: 28px; margin-bottom: 6px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; font-weight: 600; cursor: pointer;
  background: var(--card); width: 100%; font-size: 14px; color: var(--ink);
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.small { width: auto; padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: 0.5; }
.fab {
  position: fixed; right: max(16px, calc(50% - 264px)); bottom: calc(env(safe-area-inset-bottom) + 16px);
  width: 52px; height: 52px; padding: 0; border-radius: 16px;
  box-shadow: 0 8px 24px rgba(234, 88, 12, 0.35);
}
.fab .i { width: 24px; height: 24px; }

/* Segmented response */
.segment { display: flex; gap: 8px; margin: 12px 0; }
.segment .btn { flex: 1; }
.segment .btn.on-go { background: var(--go-soft); border-color: var(--go); color: var(--go); }
.segment .btn.on-no { background: var(--no-soft); border-color: var(--no); color: var(--no); }

/* Forms */
label { display: block; font-weight: 500; font-size: 13px; color: var(--ink-2); margin: 12px 0 5px; }
input[type=text], input[type=datetime-local], textarea {
  width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); outline: none; min-height: 42px; font-size: 16px; /* 16px stops iPhone auto-zoom */
  max-width: 100%; min-width: 0;
}
input:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea { resize: vertical; min-height: 64px; }
.input-group { display: flex; gap: 6px; }
.input-group input { flex: 1; min-width: 0; }
.input-group .icon-btn { width: 42px; height: 42px; }
.link-btn {
  background: none; border: 0; padding: 0; color: var(--brand); font-size: 13px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 4px; cursor: pointer;
}
.link-btn .i { width: 14px; height: 14px; }
.hint { font-size: 12px; color: var(--muted); }
.map-head { display: flex; justify-content: space-between; align-items: center; margin: 8px 0 6px; }
.map { height: 170px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); z-index: 0; }
.pin { color: var(--brand); transform: translate(-50%, -100%); }
.pin svg { width: 30px; height: 30px; fill: var(--brand); stroke: #fff; stroke-width: 1.5; }

/* Event detail */
.detail h2 { font-size: 22px; font-weight: 700; margin-bottom: 12px; }
.info { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 10px; }
.info-row { display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
.info-row:last-child { border-bottom: 0; }
.info-row .i { color: var(--muted); margin-top: 1px; }
.info .map { border: 0; border-radius: 0; border-bottom: 1px solid var(--line); }
.notes { font-size: 14px; color: var(--ink-2); white-space: pre-wrap; }
.person { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
.person:last-child { border-bottom: 0; }
.person .name { flex: 1; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 600; color: #fff; flex: none; font-size: 12px;
}

/* Welcome */
.welcome { padding-top: 16vh; }
.welcome img { width: 56px; height: 56px; border-radius: 14px; }
.welcome h1 { font-size: 26px; font-weight: 700; margin: 16px 0 4px; }
.welcome p { color: var(--muted); margin: 0 0 24px; }
.welcome .btn { margin-top: 16px; }

#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 84px); transform: translate(-50%, 12px);
  background: var(--ink); color: var(--bg); padding: 9px 14px; border-radius: 10px; font-size: 13px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: 0.2s; max-width: calc(100% - 32px); z-index: 1000;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Cancelled */
.notice.cancel { background: var(--no-soft); border-color: transparent; color: var(--no); }
.notice.cancel .i { color: var(--no); }
.btn.danger-outline { margin-top: 20px; color: var(--no); border-color: var(--line); background: transparent; }

/* Photos */
.composer { margin-bottom: 10px; }
.composer #draft { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.composer #draft img { width: 100%; max-height: 320px; object-fit: contain; border-radius: 8px; background: var(--hover); display: block; margin-bottom: 8px; }
.composer .segment { margin: 8px 0 0; }
.photo-hint { display: flex; align-items: center; gap: 6px; padding: 4px 2px 8px; }
.photo-hint .i { width: 16px; height: 16px; }
.post { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 10px; }
.post-head { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 12px; font-size: 14px; }
.post-head .grow { flex: 1; min-width: 0; }
.post-head .icon-btn { width: 32px; height: 32px; border: 0; color: var(--muted); }
.post-head .icon-btn .i { width: 16px; height: 16px; }
.post > img { width: 100%; max-height: 420px; object-fit: cover; display: block; cursor: zoom-in; background: var(--hover); }
.post-caption { padding: 8px 12px 10px; font-size: 14px; color: var(--ink-2); white-space: pre-wrap; }
.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.92); display: grid; place-items: center; z-index: 2000; padding: 16px; cursor: zoom-out; }
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }

/* Place suggestions */
.place-wrap { position: relative; }
.suggest {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 1500;
  list-style: none; margin: 0; padding: 4px; max-height: 300px; overflow-y: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
}
.suggest li { display: flex; gap: 10px; align-items: flex-start; padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.suggest li .i { color: var(--muted); margin-top: 2px; width: 16px; height: 16px; }
.suggest li.active, .suggest li:hover { background: var(--hover); }
.suggest .s-main { font-size: 14px; font-weight: 500; }
.suggest .s-sub { font-size: 12px; color: var(--muted); }
.suggest li.suggest-empty { color: var(--muted); font-size: 13px; cursor: default; }
.suggest li.suggest-empty:hover { background: none; }

/* Date & time: whole field is tappable, icon visible in both themes */
input[type=datetime-local] { cursor: pointer; }
input[type=datetime-local]::-webkit-calendar-picker-indicator { cursor: pointer; opacity: 0.7; }

/* Never let anything make the page wider than the phone */
html, body { overflow-x: hidden; }
img, .map, .list, .info, .post { max-width: 100%; }
/* iPhone date field has its own minimum width and centred text */
input[type=datetime-local] { display: block; text-align: left; -webkit-min-logical-width: 0; }
input[type=datetime-local]::-webkit-date-and-time-value { text-align: left; }

/* Dark map: re-colour the OpenStreetMap tiles to match dark mode (pins and labels stay readable) */
@media (prefers-color-scheme: dark) {
  .osm-tiles { filter: invert(1) hue-rotate(180deg) brightness(0.95) contrast(0.9) saturate(0.6); }
}

/* ---------- Bottom menu ---------- */
#app { padding-bottom: calc(env(safe-area-inset-bottom) + 140px); }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 900;
  display: flex; justify-content: center; gap: 4px;
  padding: 6px 16px calc(env(safe-area-inset-bottom) + 6px);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; max-width: 200px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; border-radius: 10px; color: var(--muted); font-size: 11px; font-weight: 600;
}
.tabbar a .i { width: 22px; height: 22px; }
.tabbar a.on { color: var(--brand); }
.fab { bottom: calc(env(safe-area-inset-bottom) + 76px); }
#toast { bottom: calc(env(safe-area-inset-bottom) + 140px); }

/* ---------- Gallery ---------- */
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; border-radius: var(--radius); overflow: hidden; }
.tile { aspect-ratio: 1; padding: 0; border: 0; background: var(--hover); cursor: pointer; display: block; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.upload { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; }
.upload[hidden] { display: none; }
.upload-strip { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.upload-strip img { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; flex: none; }
select {
  width: 100%; min-height: 42px; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font: inherit; font-size: 16px;
}

/* ---------- Full-screen viewer ---------- */
body.no-scroll { overflow: hidden; }
.viewer {
  position: fixed; inset: 0; z-index: 3000; background: #000; color: #fff;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.v-top { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.v-who { flex: 1; display: flex; align-items: center; gap: 10px; font-size: 14px; min-width: 0; }
.v-sub { font-size: 12px; color: rgba(255, 255, 255, 0.6); }
.v-btn { width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, 0.12); color: #fff; display: grid; place-items: center; cursor: pointer; }
.v-stage { flex: 1; position: relative; display: grid; place-items: center; min-height: 0; }
.v-stage img { max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; }
.v-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, 0.45); color: #fff; display: grid; place-items: center; cursor: pointer; }
.v-nav.prev { left: 8px; } .v-nav.next { right: 8px; }
.v-bottom { padding: 10px 16px 14px; display: grid; gap: 10px; }
.v-caption { font-size: 15px; white-space: pre-wrap; }
.v-plan { color: rgba(255, 255, 255, 0.8); font-size: 13px; display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.v-plan .i { width: 15px; height: 15px; }

/* ---------- Lepak stats ---------- */
.chips { display: flex; gap: 6px; margin-bottom: 12px; }
.chip { border: 1px solid var(--line); background: var(--card); color: var(--ink-2); border-radius: 99px; padding: 6px 12px; font-size: 13px; font-weight: 600; cursor: pointer; }
.chip.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.highlights { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.hl { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 8px; text-align: center; }
.hl b { display: block; font-size: 22px; font-weight: 700; }
.hl span { font-size: 12px; color: var(--muted); }
.awards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.award { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; min-width: 0; }
.award.ghost { background: linear-gradient(135deg, var(--card), var(--hover)); border-style: dashed; }
.a-emoji { font-size: 26px; line-height: 1; margin-bottom: 6px; }
.a-title { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.a-name { font-size: 16px; font-weight: 700; margin: 2px 0; overflow-wrap: anywhere; }
.a-note { font-size: 12px; color: var(--muted); }
.person.rank .pos { width: 18px; text-align: center; font-weight: 700; color: var(--muted); font-size: 13px; }
.person.rank .grow { flex: 1; min-width: 0; }
.bar { height: 5px; border-radius: 99px; background: var(--hover); margin-top: 4px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.score { text-align: right; line-height: 1.15; }
.score b { display: block; font-size: 15px; }
.score span { font-size: 11px; color: var(--muted); }

/* ---------- Me & admin ---------- */
.tabbar a { position: relative; }
.tabbar .dot {
  position: absolute; top: 2px; left: calc(50% + 6px); min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 99px; background: var(--no); color: #fff; font-style: normal; font-size: 10px; line-height: 16px; text-align: center;
}
.me-card { display: flex; align-items: center; gap: 12px; padding: 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 4px; }
.me-card .avatar { width: 44px; height: 44px; font-size: 18px; }
.me-card .grow { flex: 1; min-width: 0; }
a.btn { text-decoration: none; }
.btn.danger-text { color: var(--no); }
.person .grow { flex: 1; min-width: 0; }
.person .btn.small { flex: none; }
.person .badge { font-size: 10px; padding: 1px 6px; vertical-align: 2px; }
.switch { position: relative; width: 46px; height: 28px; flex: none; margin: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: var(--line); transition: 0.2s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: 0.2s; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
.sheet { position: fixed; inset: 0; z-index: 2500; background: rgba(0, 0, 0, 0.5); display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-card {
  width: 100%; max-width: 560px; background: var(--bg); border-radius: 18px 18px 0 0;
  padding: 14px 16px calc(env(safe-area-inset-bottom) + 16px);
}
.sheet-actions { display: grid; gap: 8px; margin-top: 14px; }
