@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* Type scale */
:root {
  --fs-xs: 0.75rem;
  --fs-sm: 0.8125rem;
  --fs-base: 0.875rem;
  --fs-input: 1rem;
  --fs-lg: 1.125rem;

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --transition-fast: 120ms ease;
  --transition-normal: 200ms ease;

  --header-h: 54px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: 0px;
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

/* Dark theme (default) */
:root, [data-theme="dark"] {
  --bg-primary: #161616;
  --bg-secondary: #1e1e1e;
  --bg-tertiary: #262626;
  --bg-elevated: #2c2c2c;
  --bg-hover: #333;
  --bg-surface: #1a1a1a;

  --text-primary: #e0e0e0;
  --text-secondary: #999;
  --text-muted: #606060;
  --text-inverse: #161616;

  --accent: #888;
  --accent-hover: #aaa;
  --accent-muted: rgba(150, 150, 150, 0.12);

  --success: #5cb85c;
  --success-muted: rgba(92, 184, 92, 0.15);
  --error: #d9534f;
  --error-muted: rgba(217, 83, 79, 0.12);

  --border: rgba(255, 255, 255, 0.08);
  --border-light: rgba(255, 255, 255, 0.04);
  --border-strong: rgba(255, 255, 255, 0.14);

  --grid-color: rgba(255, 255, 255, 0.015);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.45);

  color-scheme: dark;
}

/* Light theme */
[data-theme="light"] {
  --bg-primary: #f5f5f4;
  --bg-secondary: #fff;
  --bg-tertiary: #ebebeb;
  --bg-elevated: #fff;
  --bg-hover: #e5e5e5;
  --bg-surface: #fafaf9;

  --text-primary: #1a1a1a;
  --text-secondary: #666;
  --text-muted: #999;
  --text-inverse: #fff;

  --accent: #555;
  --accent-hover: #333;
  --accent-muted: rgba(0, 0, 0, 0.06);

  --success: #3d8b3d;
  --success-muted: rgba(61, 139, 61, 0.1);
  --error: #c9302c;
  --error-muted: rgba(201, 48, 44, 0.08);

  --border: rgba(0, 0, 0, 0.08);
  --border-light: rgba(0, 0, 0, 0.04);
  --border-strong: rgba(0, 0, 0, 0.14);

  --grid-color: rgba(0, 0, 0, 0.025);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.1);

  color-scheme: light;
}

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

html {
  height: 100%;
  overflow: hidden;
  width: 100%;
  touch-action: pan-x pan-y;
}

body {
  height: 100%;
  overflow: hidden;
  position: fixed;
  width: 100%;
  font-family: var(--font);
  font-size: var(--fs-base);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
  user-select: none;
  transition: background 0.2s ease, color 0.2s ease;
}

input, textarea, select, button {
  user-select: auto;
}

.message-content {
  user-select: text;
}

a {
  color: var(--text-primary);
  text-decoration: underline;
  text-decoration-color: var(--border-strong);
  text-underline-offset: 2px;
}

a:hover {
  text-decoration-color: var(--text-secondary);
}

::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 2px;
}

::selection {
  background: var(--accent-muted);
  color: var(--text-primary);
}

/* ─── Tablet (iPad portrait+) ─── */
@media (min-width: 768px) {
  :root {
    --fs-xs: 0.8125rem;
    --fs-sm: 0.875rem;
    --fs-base: 1rem;
    --fs-input: 1.0625rem;
    --fs-lg: 1.35rem;
    --header-h: 60px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
  }
}

/* ─── Desktop ─── */
@media (min-width: 1024px) {
  :root {
    --fs-xs: 0.75rem;
    --fs-sm: 0.8125rem;
    --fs-base: 0.875rem;
    --fs-input: 0.9375rem;
    --fs-lg: 1.125rem;
    --header-h: 56px;
  }
}
