@import "tailwindcss";
@import "highlight.js/styles/github.min.css";
@plugin "@tailwindcss/typography";

@custom-variant dark (&:is(.dark *));

:root {
  --background: oklch(1 0 0);
  --foreground: oklch(0.208 0.042 265.755);
  --card: oklch(1 0 0);
  --card-foreground: oklch(0.208 0.042 265.755);
  --popover: oklch(1 0 0);
  --popover-foreground: oklch(0.208 0.042 265.755);
  --primary: oklch(0.511 0.262 276.966);
  --primary-foreground: oklch(0.985 0.002 247);
  --secondary: oklch(0.935 0.015 264.542);
  --secondary-foreground: oklch(0.208 0.042 265.755);
  --muted: oklch(0.968 0.007 264.542);
  --muted-foreground: oklch(0.49 0.05 257.417);
  --accent: oklch(0.932 0.032 272.788);
  --accent-foreground: oklch(0.257 0.09 281.288);
  --destructive: oklch(0.577 0.245 27.325);
  --destructive-foreground: oklch(0.98 0.02 25);
  --border: oklch(0.885 0.02 255.508);
  --input: oklch(0.885 0.02 255.508);
  --ring: oklch(0.511 0.262 276.966);
  --radius: 0.625rem;
  --sidebar: oklch(0.984 0.003 247.858);
  --sidebar-foreground: oklch(0.208 0.042 265.755);
  --sidebar-primary: oklch(0.511 0.262 276.966);
  --sidebar-primary-foreground: oklch(0.985 0.002 247);
  --sidebar-accent: oklch(0.962 0.018 272.314);
  --sidebar-accent-foreground: oklch(0.511 0.262 276.966);
  --sidebar-border: oklch(0.885 0.02 255.508);
  --sidebar-ring: oklch(0.511 0.262 276.966);
  --success: oklch(0.55 0.2 145);
  --success-foreground: oklch(0.98 0 0);
  --warning: oklch(0.75 0.18 75);
  --warning-foreground: oklch(0.25 0.05 75);
  --chart-1: oklch(0.585 0.233 277.117);
  --chart-2: oklch(0.696 0.17 162.48);
  --chart-3: oklch(0.769 0.188 70.08);
  --chart-4: oklch(0.685 0.169 237.323);
  --chart-5: oklch(0.627 0.265 303.9);
}

.dark {
  --background: oklch(0.129 0.042 264.695);
  --foreground: oklch(0.984 0.003 247.858);
  --card: oklch(0.168 0.042 264.695);
  --card-foreground: oklch(0.984 0.003 247.858);
  --popover: oklch(0.168 0.042 264.695);
  --popover-foreground: oklch(0.984 0.003 247.858);
  --primary: oklch(0.585 0.233 277.117);
  --primary-foreground: oklch(0.985 0.002 247);
  --secondary: oklch(0.240 0.035 260);
  --secondary-foreground: oklch(0.984 0.003 247.858);
  --muted: oklch(0.220 0.030 260);
  --muted-foreground: oklch(0.650 0.030 256);
  --accent: oklch(0.300 0.055 270);
  --accent-foreground: oklch(0.984 0.003 247.858);
  --destructive: oklch(0.65 0.23 25);
  --destructive-foreground: oklch(0.98 0.02 25);
  --border: oklch(0.320 0.025 260);
  --input: oklch(0.250 0.035 260);
  --ring: oklch(0.585 0.233 277.117);
  --success: oklch(0.45 0.15 145);
  --success-foreground: oklch(0.85 0.1 145);
  --warning: oklch(0.55 0.15 75);
  --warning-foreground: oklch(0.85 0.1 75);
  --sidebar: oklch(0.168 0.042 264.695);
  --sidebar-foreground: oklch(0.984 0.003 247.858);
  --sidebar-primary: oklch(0.585 0.233 277.117);
  --sidebar-primary-foreground: oklch(0.985 0.002 247);
  --sidebar-accent: oklch(0.300 0.055 270);
  --sidebar-accent-foreground: oklch(0.984 0.003 247.858);
  --sidebar-border: oklch(0.320 0.025 260);
  --sidebar-ring: oklch(0.585 0.233 277.117);
  --chart-1: oklch(0.673 0.182 276.935);
  --chart-2: oklch(0.696 0.17 162.48);
  --chart-3: oklch(0.769 0.188 70.08);
  --chart-4: oklch(0.685 0.169 237.323);
  --chart-5: oklch(0.627 0.265 303.9);
}

@theme inline {
  --color-background: var(--background);
  --color-foreground: var(--foreground);
  --color-card: var(--card);
  --color-card-foreground: var(--card-foreground);
  --color-popover: var(--popover);
  --color-popover-foreground: var(--popover-foreground);
  --color-primary: var(--primary);
  --color-primary-foreground: var(--primary-foreground);
  --color-secondary: var(--secondary);
  --color-secondary-foreground: var(--secondary-foreground);
  --color-muted: var(--muted);
  --color-muted-foreground: var(--muted-foreground);
  --color-accent: var(--accent);
  --color-accent-foreground: var(--accent-foreground);
  --color-destructive: var(--destructive);
  --color-destructive-foreground: var(--destructive-foreground);
  --color-border: var(--border);
  --color-input: var(--input);
  --color-ring: var(--ring);
  --color-sidebar: var(--sidebar);
  --color-sidebar-foreground: var(--sidebar-foreground);
  --color-sidebar-primary: var(--sidebar-primary);
  --color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
  --color-sidebar-accent: var(--sidebar-accent);
  --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
  --color-sidebar-border: var(--sidebar-border);
  --color-sidebar-ring: var(--sidebar-ring);
  --color-chart-1: var(--chart-1);
  --color-chart-2: var(--chart-2);
  --color-chart-3: var(--chart-3);
  --color-chart-4: var(--chart-4);
  --color-success: var(--success);
  --color-success-foreground: var(--success-foreground);
  --color-warning: var(--warning);
  --color-warning-foreground: var(--warning-foreground);
  --color-chart-5: var(--chart-5);
  --radius-sm: calc(var(--radius) - 4px);
  --radius-md: calc(var(--radius) - 2px);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) + 4px);
}

@layer base {
  * {
    @apply border-border;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
  }
  body {
    @apply bg-background text-foreground;
    font-family: system-ui, -apple-system, sans-serif;
  }
}

/* ── Mobile UX utilities ── */

/* Safe area padding for notched devices (requires viewport-fit=cover) */
@utility safe-top { padding-top: env(safe-area-inset-top); }
@utility safe-bottom { padding-bottom: env(safe-area-inset-bottom); }
@utility safe-left { padding-left: env(safe-area-inset-left); }
@utility safe-right { padding-right: env(safe-area-inset-right); }

/* Allow word breaks anywhere for long URLs/text on narrow screens */
@utility break-anywhere { overflow-wrap: anywhere; }

/* Expand touch targets on coarse pointer (touch) devices for small icon buttons */
@media (pointer: coarse) {
  [data-slot="button"][data-size="icon"],
  [data-slot="button"][data-size="icon-sm"],
  [data-slot="button"][data-size="icon-xs"] {
    position: relative;
  }
  [data-slot="button"][data-size="icon"]::after,
  [data-slot="button"][data-size="icon-sm"]::after,
  [data-slot="button"][data-size="icon-xs"]::after {
    content: "";
    position: absolute;
    inset: -6px;
  }
}

/* Landscape compact mode for phones */
@media (orientation: landscape) and (max-height: 500px) {
  .landscape-compact { padding-block: 0.25rem; }
}

/* highlight.js: transparent bg, container handles it */
.hljs { background: transparent !important; }

/* ── Markdown renderer — VS Code / GitHub-inspired typography ── */

.md-render {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
}

/* Headings */
.md-render :where(h1, h2, h3, h4, h5, h6):not(:where([class~="not-prose"],[class~="not-prose"] *)) {
  font-weight: 600;
  line-height: 1.25;
  color: var(--foreground);
}
.md-render :where(h1):not(:where([class~="not-prose"],[class~="not-prose"] *)) {
  font-size: 2em;
  margin: 24px 0 16px;
  padding-bottom: 0.3em;
  border-bottom: 1px solid var(--border);
}
.md-render :where(h2):not(:where([class~="not-prose"],[class~="not-prose"] *)) {
  font-size: 1.5em;
  margin: 24px 0 16px;
  padding-bottom: 0.3em;
  border-bottom: 1px solid var(--border);
}
.md-render :where(h3):not(:where([class~="not-prose"],[class~="not-prose"] *)) {
  font-size: 1.25em;
  margin: 24px 0 16px;
}
.md-render :where(h4):not(:where([class~="not-prose"],[class~="not-prose"] *)) {
  font-size: 1em;
  margin: 24px 0 16px;
}

/* First heading: no top margin */
.md-render :where(> :first-child) {
  margin-top: 0 !important;
}

/* Paragraphs */
.md-render :where(p):not(:where([class~="not-prose"],[class~="not-prose"] *)) {
  margin: 0 0 16px;
}

/* Blockquotes */
.md-render :where(blockquote):not(:where([class~="not-prose"],[class~="not-prose"] *)) {
  border-left: 4px solid var(--muted-foreground);
  margin: 0 0 16px;
  padding: 12px 16px;
  background: var(--muted);
  border-radius: 0 6px 6px 0;
  color: var(--muted-foreground);
  font-style: normal;
}

/* Horizontal rule */
.md-render :where(hr):not(:where([class~="not-prose"],[class~="not-prose"] *)) {
  border: none;
  height: 2px;
  background: var(--border);
  margin: 24px 0;
}

/* Lists */
.md-render :where(ul, ol):not(:where([class~="not-prose"],[class~="not-prose"] *)) {
  margin: 0 0 16px;
  padding-left: 2em;
}
.md-render :where(ul):not(:where([class~="not-prose"],[class~="not-prose"] *)) {
  list-style-type: disc;
}
.md-render :where(ul ul):not(:where([class~="not-prose"],[class~="not-prose"] *)) {
  list-style-type: circle;
}
.md-render :where(li):not(:where([class~="not-prose"],[class~="not-prose"] *)) {
  margin: 4px 0;
}
.md-render li::marker {
  color: var(--foreground) !important;
}
.md-render :where(li > p):not(:where([class~="not-prose"],[class~="not-prose"] *)) {
  margin: 0;
}

/* Inline code */
.md-render :where(code):not(:where(pre code, [class~="not-prose"],[class~="not-prose"] *)) {
  font-family: 'JetBrains Mono', 'Fira Code', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.85em;
  background: var(--muted);
  border-radius: 4px;
  padding: 0.2em 0.4em;
  color: var(--primary);
  font-weight: 500;
}
.md-render :where(code):not(:where(pre code, [class~="not-prose"],[class~="not-prose"] *))::before,
.md-render :where(code):not(:where(pre code, [class~="not-prose"],[class~="not-prose"] *))::after {
  content: none;
}

/* Links */
.md-render :where(a):not(:where([class~="not-prose"],[class~="not-prose"] *)) {
  color: oklch(0.55 0.2 250);
  text-decoration: underline;
  text-decoration-color: oklch(0.55 0.2 250 / 0.4);
  text-underline-offset: 2px;
}
.md-render :where(a):not(:where([class~="not-prose"],[class~="not-prose"] *)):hover {
  color: oklch(0.48 0.22 250);
  text-decoration-color: oklch(0.48 0.22 250 / 0.8);
}
:is(.dark) .md-render :where(a):not(:where([class~="not-prose"],[class~="not-prose"] *)) {
  color: oklch(0.72 0.18 250);
  text-decoration-color: oklch(0.72 0.18 250 / 0.4);
}
:is(.dark) .md-render :where(a):not(:where([class~="not-prose"],[class~="not-prose"] *)):hover {
  color: oklch(0.80 0.16 250);
  text-decoration-color: oklch(0.80 0.16 250 / 0.8);
}

/* Strong & emphasis */
.md-render :where(strong):not(:where([class~="not-prose"],[class~="not-prose"] *)) {
  font-weight: 600;
}

/* Images */
.md-render :where(img):not(:where([class~="not-prose"],[class~="not-prose"] *)) {
  max-width: 100%;
}

/* Table (fallback for non-custom-component tables) */
.md-render :where(table):not(:where([class~="not-prose"],[class~="not-prose"] *)) {
  border-collapse: collapse;
  width: 100%;
  margin: 0 0 16px;
  font-size: 13px;
}
.md-render :where(th):not(:where([class~="not-prose"],[class~="not-prose"] *)) {
  font-weight: 600;
  background: var(--muted);
  border: 1px solid var(--border);
  padding: 6px 13px;
  text-align: left;
}
.md-render :where(td):not(:where([class~="not-prose"],[class~="not-prose"] *)) {
  border: 1px solid var(--border);
  padding: 6px 13px;
}
.md-render :where(tr:nth-child(even) td):not(:where([class~="not-prose"],[class~="not-prose"] *)) {
  background: color-mix(in oklch, var(--muted) 40%, transparent);
}

/* Dark mode syntax colors (github-dark palette) */
.dark .hljs { color: #e6edf3; }
.dark .hljs-comment,
.dark .hljs-quote { color: #8b949e; }
.dark .hljs-keyword,
.dark .hljs-selector-tag,
.dark .hljs-type { color: #ff7b72; }
.dark .hljs-string,
.dark .hljs-addition { color: #a5d6ff; }
.dark .hljs-number,
.dark .hljs-literal { color: #79c0ff; }
.dark .hljs-title,
.dark .hljs-section,
.dark .hljs-attr { color: #d2a8ff; }
.dark .hljs-name,
.dark .hljs-tag { color: #7ee787; }
.dark .hljs-built_in,
.dark .hljs-symbol { color: #ffa657; }
.dark .hljs-variable,
.dark .hljs-template-variable { color: #ffa657; }
.dark .hljs-deletion { color: #ffa198; background: rgba(255,129,130,0.15); }
.dark .hljs-addition { background: rgba(63,185,80,0.15); }
