/* ── Design tokens ─────────────────────────────────────────────────────── */
/* Colours: Radix Sand (neutrals) + Radix Brown (accent)                   */
:root {
  --bg: #fdfdfc; /* sand-1  */
  --surface: #f1f0ef; /* sand-3  */
  --border: #dad9d6; /* sand-6  */
  --text: #21201c; /* sand-12 */
  --muted: #63635e; /* sand-11 */
  --accent: #ad7f58; /* brown-9 */
  --accent-dim: #f6eee7; /* brown-3 */
  --accent-fg: #ffffff;
  --danger: #dc2626;
  --success: #16a34a;
  --r: 14px;
  --r-sm: 8px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111110; /* sand-1  dark */
    --surface: #222221; /* sand-3  dark */
    --border: #3b3a37; /* sand-6  dark */
    --text: #eeeeec; /* sand-12 dark */
    --muted: #b5b3ad; /* sand-11 dark */
    --accent: #ad7f58; /* brown-9 (same in light/dark) */
    --accent-dim: #322922; /* brown-4 dark */
    --accent-fg: #ffffff;
    --danger: #f87171;
    --success: #4ade80;
  }
}

/* Explicit theme overrides (beat the media query via attribute specificity) */
:root[data-theme="light"] {
  --bg: #fdfdfc;
  --surface: #f1f0ef;
  --border: #dad9d6;
  --text: #21201c;
  --muted: #63635e;
  --accent: #ad7f58;
  --accent-dim: #f6eee7;
  --accent-fg: #ffffff;
  --danger: #dc2626;
  --success: #16a34a;
}

:root[data-theme="dark"] {
  --bg: #111110;
  --surface: #222221;
  --border: #3b3a37;
  --text: #eeeeec;
  --muted: #b5b3ad;
  --accent: #ad7f58;
  --accent-dim: #322922;
  --accent-fg: #ffffff;
  --danger: #f87171;
  --success: #4ade80;
}

/* ── Reset & base ──────────────────────────────────────────────────────── */
* {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  transition:
    background-color 0.15s ease,
    color 0.15s ease,
    transform 0.1s ease;
}

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

html {
  height: 100%;
  user-select: none;
  touch-action: manipulation;
}

body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ────────────────────────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
}

/* ── Footer ────────────────────────────────────────────────────────────── */
footer {
  padding: 12px 20px calc(12px + var(--safe-b));
  display: flex;
  justify-content: center;
}

.footer-link {
  background: none;
  border: none;
  padding: 4px 8px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  border-radius: 6px;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.footer-link:hover {
  color: var(--text);
}

/* ── Header ────────────────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + var(--safe-t)) 20px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.logo {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.logo-mark {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
}

.settings-btn {
  width: 40px;
  height: 40px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.05rem;
  color: var(--muted);
  transition:
    background 0.15s,
    color 0.15s;
  position: relative;
  -webkit-tap-highlight-color: transparent;
}

.settings-btn:active {
  background: var(--border);
}

/* Red dot when credentials missing */
.settings-btn.needs-setup::after {
  content: "";
  position: absolute;
  top: -3px;
  right: -3px;
  width: 10px;
  height: 10px;
  background: var(--danger);
  border-radius: 50%;
  border: 2px solid var(--bg);
}

/* ── Main content ──────────────────────────────────────────────────────── */
main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* ── Emoji picker ──────────────────────────────────────────────────────── */
.emoji-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  position: relative;
}

.emoji-display {
  width: 92px;
  height: 92px;
  border-radius: 26px;
  background: var(--surface);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3.25rem;
  cursor: pointer;
  user-select: none;
  transition:
    transform 0.12s,
    border-color 0.15s,
    background 0.15s;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.emoji-display:active {
  transform: scale(0.94);
}
.emoji-display:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
}

emoji-picker {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  width: min(340px, calc(100vw - 40px));
  border-radius: var(--r);
  --background: var(--surface);
  --border-color: var(--border);
  --indicator-color: var(--accent);
  --input-border-color: var(--border);
  --input-font-color: var(--text);
  --input-placeholder-color: var(--muted);
  --outline-color: var(--accent);
}

.emoji-section.picking emoji-picker {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* ── Form fields ───────────────────────────────────────────────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.toggle-row {
  padding-block: 2px;
}
.toggle-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 400;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
  user-select: none;
}
.toggle-label input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

textarea,
input[type="url"],
input[type="text"],
input[type="password"] {
  user-select: text;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  padding: 13px 15px;
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
  appearance: none;
  -webkit-appearance: none;
}

textarea:focus,
input[type="url"]:focus,
input[type="text"]:focus,
input[type="password"]:focus {
  border-color: var(--accent);
}

textarea {
  resize: none;
  min-height: 116px;
  line-height: 1.6;
}

textarea::placeholder,
input::placeholder {
  color: var(--muted);
}

.char-count {
  font-size: 0.78rem;
  color: var(--muted);
  text-align: right;
  transition: color 0.15s;
}

.char-count.warn {
  color: var(--danger);
}

/* ── Post button ───────────────────────────────────────────────────────── */
.post-btn {
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  border-radius: var(--r);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  padding: 16px;
  width: 100%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition:
    opacity 0.15s,
    transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.post-btn:active:not(:disabled) {
  transform: scale(0.98);
}
.post-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255, 255, 255, 0.35);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  display: none;
  flex-shrink: 0;
}

.post-btn.loading .spinner {
  display: block;
}
.post-btn.loading .btn-label {
  display: none;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Toast ─────────────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: calc(24px + var(--safe-b));
  left: 50%;
  transform: translateX(-50%) translateY(calc(100% + var(--safe-b) + 30px));
  background: var(--text);
  color: var(--bg);
  padding: 11px 22px;
  border-radius: 40px;
  font-size: 0.9rem;
  font-weight: 500;
  max-width: calc(100% - 40px);
  text-align: center;
  box-shadow: 0 6px 28px rgba(0, 0, 0, 0.22);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 200;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#toast.show {
  transform: translateX(-50%) translateY(0);
}
#toast.success {
  background: var(--success);
  color: #fff;
}
#toast.error {
  background: var(--danger);
  color: #fff;
}
#toast.show.clickable {
  pointer-events: auto;
  cursor: pointer;
}

#toast.show.clickable:hover {
  filter: brightness(1.1);
}

/* ── Settings modal ────────────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.48);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--bg);
  border-radius: 22px;
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.95) translateY(8px);
  opacity: 0;
  transition:
    transform 0.25s cubic-bezier(0.34, 1.2, 0.64, 1),
    opacity 0.2s;
}

.overlay.open .modal {
  transform: scale(1) translateY(0);
  opacity: 1;
}

.modal-grip {
  display: none;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 0;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.close-btn {
  width: 32px;
  height: 32px;
  background: var(--surface);
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--muted);
  -webkit-tap-highlight-color: transparent;
}

.close-btn:active {
  background: var(--border);
}

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Privacy notice */
.polite-notice {
  background: var(--accent-dim);
  border: 1.5px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: var(--r);
  padding: 14px 16px;
  display: flex;
  gap: 11px;
  align-items: flex-start;
  font-size: 0.875rem;
  color: var(--text);
  line-height: 1.6;
}

.privacy-icon {
  font-size: 1.1rem;
  flex-shrink: 0;
  margin-top: 2px;
}

.modal-body a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}

.modal-body a:hover {
  text-decoration-thickness: 2px;
}

/* API key with eye toggle */
.input-wrap {
  position: relative;
  display: flex;
}

.input-wrap input {
  padding-right: 48px;
}

.eye-btn {
  position: absolute;
  right: 13px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 1rem;
  padding: 4px;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}

.save-btn {
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  border-radius: var(--r);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  padding: 14px;
  width: 100%;
  cursor: pointer;
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.save-btn:active {
  opacity: 0.8;
}

/* ── Install banner ────────────────────────────────────────────────────── */
.install-banner {
  display: none;
  gap: 10px;
  align-items: flex-start;
  background: var(--accent-dim);
  border: 1.5px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: var(--r);
  padding: 12px 14px;
  font-size: 0.875rem;
  color: var(--text);
  line-height: 1.5;
}

.install-banner.visible {
  display: flex;
}

.install-banner-icon {
  font-size: 1.1rem;
  flex-shrink: 0;
  margin-top: 1px;
}

.install-banner-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 2px 0 0;
  margin-left: auto;
  flex-shrink: 0;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}

/* ── Theme segmented control ───────────────────────────────────────────── */
.theme-toggle {
  display: flex;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r);
  padding: 3px;
  gap: 3px;
}

.theme-btn {
  flex: 1;
  padding: 8px 10px;
  border: none;
  border-radius: calc(var(--r) - 5px);
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition:
    background 0.15s,
    color 0.15s,
    box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.theme-btn.active {
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}
