/* Apple HIG-inspired theme with Liquid Glass controls.
   - Liquid Glass is used for the control/navigation layer only (nav bar, buttons,
     segmented controls). Content (question cards, text field) sits on solid surfaces.
   - System colors, SF system font, 17px body, 44px touch targets on touch devices.
   - Respects prefers-reduced-transparency, prefers-reduced-motion and dark mode. */
:root {
  /* HIG system colors (light) */
  --bg: #f2f2f7;                       /* systemGroupedBackground */
  --surface: #ffffff;                  /* secondarySystemGroupedBackground */
  --text: #000000;                     /* label */
  --secondary: rgba(60, 60, 67, 0.6);  /* secondaryLabel */
  --tertiary: rgba(60, 60, 67, 0.3);   /* tertiaryLabel */
  --separator: rgba(60, 60, 67, 0.12);
  --fill: rgba(120, 120, 128, 0.12);
  --blue: #007aff;
  --green: #34c759;
  --green-text: #248a3d;
  --red: #ff3b30;
  --purple: #af52de;
  --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.05);
  --radius: 22px;

  /* Liquid Glass material */
  --glass-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.62), rgba(255, 255, 255, 0.34));
  --glass-bg-hover: linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0.46));
  --glass-rim: rgba(255, 255, 255, 0.75);
  --glass-hi: rgba(255, 255, 255, 0.95);
  --glass-glow: rgba(255, 255, 255, 0.45);
  --glass-shadow: 0 6px 20px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.08);
  --glass-blur: blur(14px) saturate(180%);

  --ambient-1: rgba(0, 122, 255, 0.16);
  --ambient-2: rgba(175, 82, 222, 0.12);
  --ambient-3: rgba(52, 199, 89, 0.1);

  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue",
    "Sukhumvit Set", "Noto Sans Thai", "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.014em;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --text: #ffffff;
    --secondary: rgba(235, 235, 245, 0.6);
    --tertiary: rgba(235, 235, 245, 0.3);
    --separator: rgba(84, 84, 88, 0.6);
    --fill: rgba(120, 120, 128, 0.24);
    --blue: #0a84ff;
    --green: #30d158;
    --green-text: #30d158;
    --red: #ff453a;
    --purple: #bf5af2;
    --card-shadow: none;

    --glass-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.06));
    --glass-bg-hover: linear-gradient(180deg, rgba(255, 255, 255, 0.24), rgba(255, 255, 255, 0.1));
    --glass-rim: rgba(255, 255, 255, 0.22);
    --glass-hi: rgba(255, 255, 255, 0.35);
    --glass-glow: rgba(255, 255, 255, 0.06);
    --glass-shadow: 0 6px 20px rgba(0, 0, 0, 0.45), 0 1px 3px rgba(0, 0, 0, 0.4);

    --ambient-1: rgba(10, 132, 255, 0.22);
    --ambient-2: rgba(191, 90, 242, 0.16);
    --ambient-3: rgba(48, 209, 88, 0.08);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-height: 100%; }
body { margin: 0; line-height: 1.47; font-size: 17px; min-height: 100vh; }
/* Soft ambient light behind everything, so the glass has something to refract. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(55% 45% at 12% 0%, var(--ambient-1), transparent 70%),
    radial-gradient(45% 40% at 92% 8%, var(--ambient-2), transparent 70%),
    radial-gradient(60% 45% at 50% 105%, var(--ambient-3), transparent 70%),
    var(--bg);
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Liquid Glass ----------
   Used sparingly: only the floating nav bar, segmented controls (sort, language)
   and the one primary action (Send). Everything inside content uses plain fills. */
.glass,
.seg,
.nav-inner {
  position: relative;
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-rim);
  box-shadow:
    inset 0 1px 0 var(--glass-hi),          /* top specular highlight */
    inset 0 0 10px var(--glass-glow),        /* soft inner glow */
    var(--glass-shadow);
}
/* Subtle specular sheen on the nav bar and the primary button */
.nav-inner::after,
button.primary::after {
  content: "";
  position: absolute;
  inset: 1px 1px 50% 1px;
  border-radius: inherit;
  border-bottom-left-radius: 40% 30%;
  border-bottom-right-radius: 40% 30%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0));
  pointer-events: none;
  opacity: 0.6;
}

/* ---------- Floating glass nav ---------- */
.nav {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 12px 16px 0;
}
.nav-inner {
  max-width: 820px;
  margin: 0 auto;
  min-height: 56px;
  padding: 6px 8px 6px 22px;
  border-radius: 980px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.brand { font-weight: 700; font-size: 1.05rem; letter-spacing: -0.02em; color: var(--text); }
.nav a { font-size: 0.88rem; font-weight: 500; color: var(--text); }
.nav a:hover { text-decoration: none; opacity: 0.7; }

/* ---------- Layout & type (HIG Large Title / Title 3 / Body) ---------- */
main { max-width: 820px; margin: 0 auto; padding: 48px 22px 96px; }
main.narrow { max-width: 640px; }
h1 {
  font-size: clamp(2.125rem, 6vw, 3.5rem);
  line-height: 1.08;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 0 0 10px;
}
.sub { color: var(--secondary); font-size: 1.25rem; line-height: 1.4; margin: 0 0 32px; letter-spacing: -0.015em; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- Buttons ----------
   Default: HIG "gray" capsule (plain fill, no glass). Primary: tinted glass. */
button {
  position: relative;
  font: inherit;
  font-size: 0.94rem;
  font-weight: 500;
  letter-spacing: -0.012em;
  color: var(--text);
  background: var(--fill);
  border: 0;
  border-radius: 980px;
  min-height: 36px;
  padding: 7px 18px;
  cursor: pointer;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.2s, box-shadow 0.2s, filter 0.2s;
}
button:hover { background: color-mix(in srgb, var(--fill) 100%, var(--text) 6%); }
button:active { transform: scale(0.97); }
/* Liquid Glass controls "lift" and brighten under the finger */
button.primary:active, .seg button:active { transform: scale(1.04); filter: brightness(1.06); }
button:disabled { opacity: 0.4; cursor: default; transform: none; filter: none; }
button:focus-visible { outline: 3px solid color-mix(in srgb, var(--blue) 45%, transparent); outline-offset: 2px; }

/* Tinted glass: primary action */
button.primary {
  color: #fff;
  font-weight: 600;
  font-size: 1.06rem;
  min-height: 50px;
  padding: 12px 32px;
  border-color: color-mix(in srgb, var(--blue) 60%, white);
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--blue) 82%, white),
    color-mix(in srgb, var(--blue) 92%, black));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    inset 0 -1px 4px rgba(0, 0, 0, 0.1),
    0 6px 18px color-mix(in srgb, var(--blue) 28%, transparent),
    0 1px 3px rgba(0, 0, 0, 0.1);
}
button.primary:hover { filter: brightness(1.06); }
button.small { font-size: 0.85rem; min-height: 32px; padding: 5px 14px; }
button.danger { color: var(--red); }

/* Glass segmented control with a floating glass thumb */
.seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: 980px;
}
.seg button {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  min-height: 32px;
  padding: 5px 16px;
  font-size: 0.86rem;
  color: var(--secondary);
}
.seg button::after { display: none; }
.seg button:hover { background: transparent; color: var(--text); }
.seg button[aria-pressed="true"] {
  color: var(--text);
  font-weight: 600;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.75));
  border-color: rgba(255, 255, 255, 0.9);
  box-shadow: inset 0 1px 0 #fff, 0 3px 10px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.08);
}
@media (prefers-color-scheme: dark) {
  .seg button[aria-pressed="true"] {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.16));
    border-color: rgba(255, 255, 255, 0.28);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 3px 10px rgba(0, 0, 0, 0.4);
  }
}
.lang-toggle button { padding: 4px 12px; min-height: 30px; font-size: 0.8rem; }

/* ---------- Ask form (content: solid surface) ---------- */
.field {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  border: 1px solid var(--separator);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--blue) 18%, transparent);
}
textarea {
  display: block;
  width: 100%;
  min-height: 170px;
  font: inherit;
  font-size: 1.1rem;
  line-height: 1.45;
  padding: 18px 20px;
  border: 0;
  background: transparent;
  color: var(--text);
  resize: vertical;
  outline: none;
}
textarea::placeholder { color: var(--tertiary); }
.counter { color: var(--tertiary); font-size: 0.8rem; padding: 0 20px 12px; text-align: right; font-variant-numeric: tabular-nums; }
.form-actions { margin-top: 22px; display: flex; align-items: center; gap: 16px; }
.msg { min-height: 1.4em; color: var(--secondary); font-size: 0.95rem; }
.msg.ok { color: var(--green-text); }
.msg.err { color: var(--red); }
@media (max-width: 520px) {
  .form-actions { flex-direction: column-reverse; align-items: stretch; }
  .form-actions button.primary { width: 100%; }
  main { padding-top: 32px; }
}

/* ---------- Questions ---------- */
.toolbar { margin: 0 0 20px; }
.status { color: var(--secondary); font-size: 0.92rem; margin: -20px 0 28px; }
.status .dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--green); margin-right: 8px; vertical-align: 1px;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 25%, transparent);
}
.list { display: flex; flex-direction: column; gap: 12px; }
.q {
  display: flex;
  gap: 18px;
  align-items: flex-start;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  padding: 18px 20px;
  transition: opacity 0.2s;
}
.q.answered { opacity: 0.5; }
/* Concentric: vote capsule radius = card radius - padding */
.vote {
  flex: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 56px; min-height: 60px; padding: 8px 0; gap: 3px;
  border-radius: 16px;
  line-height: 1;
}
.vote .arrow { font-size: 0.72rem; }
.vote .n { font-weight: 700; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.vote.mine { color: #fff; background: var(--blue); }
.vote.mine:hover { background: color-mix(in srgb, var(--blue) 90%, white); }
.body { flex: 1; min-width: 0; padding-top: 2px; }
.text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 1.12rem; line-height: 1.42; }
.meta { color: var(--secondary); font-size: 0.82rem; margin-top: 8px; display: flex; gap: 10px; align-items: center; }
.badge {
  color: var(--green-text); font-weight: 600;
  background: color-mix(in srgb, var(--green) 16%, transparent);
  padding: 2px 9px; border-radius: 980px;
}
.actions { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.empty { text-align: center; padding: 72px 0; }
.empty .big { font-size: 1.5rem; font-weight: 600; letter-spacing: -0.02em; }
.empty .small { color: var(--secondary); margin-top: 6px; }
.hidden-section { margin-top: 36px; text-align: center; }
.hidden-section .list { text-align: left; margin-top: 16px; }

/* ---------- HIG: 44pt touch targets on touch devices ---------- */
@media (pointer: coarse) {
  button, button.small, .seg button { min-height: 44px; }
  .lang-toggle button { min-height: 38px; }
}

/* ---------- Accessibility ---------- */
@media (prefers-reduced-transparency: reduce) {
  .glass, .seg, .nav-inner {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: var(--surface);
  }
  button.primary::after, .nav-inner::after { display: none; }
  body::before { background: var(--bg); }
}
@media (prefers-reduced-motion: reduce) {
  button, button:active { transition: none; transform: none; }
}
