/*
  InkOS Studio — Atmospheric Literary Workbench
  Fonts: Instrument Serif (Headings/Literary), DM Sans (UI), JetBrains Mono (Data)
*/
@import url('https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=DM+Sans:ital,wght@0,400;0,500;0,600;0,700;1,400&family=JetBrains+Mono:wght@400;500&display=swap');

@import "tailwindcss";

@import "tw-animate-css";
@import "shadcn/tailwind.css";

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

@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);

  --radius-sm: calc(var(--radius) - 4px);
  --radius-md: calc(var(--radius) - 2px);
  --radius-lg: var(--radius);
  --radius-xl: calc(var(--radius) + 4px);

  --font-serif: 'Instrument Serif', Georgia, serif;
  --font-sans: 'DM Sans', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-soft: 0 2px 15px -3px oklch(0 0 0 / 0.07), 0 4px 6px -4px oklch(0 0 0 / 0.05);
  --shadow-3d: 0 10px 30px -10px oklch(0 0 0 / 0.15), 0 4px 10px -5px oklch(0 0 0 / 0.1);
  --shadow-3d-hover: 0 20px 40px -15px oklch(0 0 0 / 0.2), 0 8px 16px -8px oklch(0 0 0 / 0.15);
}

/* ── Light Mode: Warm Parchment & Ink ── */
:root {
  --radius: 0.6rem;

  /* Background: Warm, aged paper with subtle radial light */
  --background: oklch(0.985 0.005 80);
  --background-radial: radial-gradient(circle at 50% 0%, oklch(0.995 0.002 85) 0%, oklch(0.985 0.005 80) 100%);
  --foreground: oklch(0.13 0.02 60);

  /* Cards: Crisp sheets on paper */
  --card: oklch(1 0 0);
  --card-foreground: oklch(0.15 0.015 60);

  --popover: oklch(1 0 0);
  --popover-foreground: oklch(0.15 0.015 60);

  /* Primary: Deep Oxblood / Ink */
  --primary: oklch(0.45 0.12 25);
  --primary-foreground: oklch(0.98 0.006 76);

  /* Secondary: Soft paper shadow */
  --secondary: oklch(0.94 0.01 76);
  --secondary-foreground: oklch(0.25 0.015 60);

  /* Muted: Faded ink */
  --muted: oklch(0.94 0.008 76);
  --muted-foreground: oklch(0.38 0.02 60);

  /* Accent: Subtle gold leaf */
  --accent: oklch(0.92 0.02 85);
  --accent-foreground: oklch(0.25 0.05 60);

  --destructive: oklch(0.55 0.18 25);
  --destructive-foreground: oklch(0.98 0 0);

  --border: oklch(0.84 0.01 76);
  --input: oklch(0.92 0.005 76);
  --ring: oklch(0.45 0.12 25);
}

/* ── Dark Mode: Obsidian & Candlelight ── */
.dark {
  /* Background: Deep obsidian with soft top glow */
  --background: oklch(0.12 0.01 250);
  --background-radial: radial-gradient(circle at 50% 0%, oklch(0.16 0.015 250) 0%, oklch(0.12 0.01 250) 100%);
  --foreground: oklch(0.97 0.005 250);

  /* Cards: Floating graphite */
  --card: oklch(0.18 0.015 250);
  --card-foreground: oklch(0.95 0.005 250);

  --popover: oklch(0.18 0.015 250);
  --popover-foreground: oklch(0.95 0.005 250);

  /* Primary: Warm Amber / Candlelight */
  --primary: oklch(0.78 0.14 85);
  --primary-foreground: oklch(0.12 0.01 250);

  /* Secondary: Dark slate */
  --secondary: oklch(0.22 0.02 250);
  --secondary-foreground: oklch(0.92 0.005 250);

  /* Muted: Dimmed graphite */
  --muted: oklch(0.22 0.015 250);
  --muted-foreground: oklch(0.78 0.005 250);

  /* Accent: Muted gold */
  --accent: oklch(0.28 0.04 85);
  --accent-foreground: oklch(0.95 0.06 85);

  --destructive: oklch(0.55 0.2 25);
  --destructive-foreground: oklch(0.98 0 0);

  --border: oklch(0.30 0.02 250);
  --input: oklch(0.25 0.02 250);
  --ring: oklch(0.78 0.14 85);
}

body {
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 450;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: var(--background-radial);
  background-attachment: fixed;
  color: var(--foreground);
  transition: background 0.5s ease, color 0.5s ease;
}

/* ── Cursor interaction rules ── */
button, [role="button"], a, select, label[for], summary { cursor: pointer; }
button:disabled, [aria-disabled="true"] { cursor: not-allowed; }
input[type="text"], input[type="number"], input[type="email"], input[type="password"], textarea { cursor: text; }
input[type="checkbox"], input[type="radio"] { cursor: pointer; }

/* Button hover micro-feedback */
button:not(:disabled):active {
  transform: scale(0.97);
  transition: transform 0.1s ease;
}

/* Subtle grain texture for physical feel */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
}

/* Serif headings with literary character */
h1, h2, h3, h4 {
  font-family: var(--font-serif);
  letter-spacing: -0.02em;
  font-weight: 500;
}

h1 { font-size: 2.25rem; font-style: italic; }
h2 { font-size: 1.75rem; }
h3 { font-size: 1.25rem; }

/* Focus indicator */
:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

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

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

::-webkit-scrollbar-thumb:hover {
  background: var(--muted-foreground);
}

/* ── Animation Classes ── */
.fade-in {
  animation: fadeIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.stagger-1 { animation-delay: 0.05s; opacity: 0; }
.stagger-2 { animation-delay: 0.1s; opacity: 0; }
.stagger-3 { animation-delay: 0.15s; opacity: 0; }
.stagger-4 { animation-delay: 0.2s; opacity: 0; }
.stagger-5 { animation-delay: 0.25s; opacity: 0; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Premium Layout Utilities ── */
.glass-panel {
  backdrop-blur: 16px;
  background-color: color-mix(in oklch, var(--card) 70%, transparent);
  border: 1px solid color-mix(in oklch, var(--border) 50%, transparent);
  box-shadow: var(--shadow-3d);
}

.paper-sheet {
  background-color: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  transition: box-shadow 0.3s cubic-bezier(0.16, 1, 0.3, 1),
              border-color 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.paper-sheet:hover {
  box-shadow: var(--shadow-3d-hover);
  border-color: var(--primary);
}

/* ── ChatPanel Animations ── */

/* Header sparkle glow pulse */
@keyframes iconGlow {
  0%, 100% { filter: drop-shadow(0 0 0px transparent); }
  50% { filter: drop-shadow(0 0 6px oklch(0.78 0.14 85 / 0.4)); }
}
.chat-icon-glow { animation: iconGlow 2s ease-in-out infinite; }

/* Writing pen gentle bobbing */
@keyframes iconWrite {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-1px) rotate(-3deg); }
  75% { transform: translateY(1px) rotate(3deg); }
}
.chat-icon-write { animation: iconWrite 1.2s ease-in-out infinite; }

/* Slow spin for revision/wrench */
@keyframes spinSlow {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
.chat-icon-spin-slow { animation: spinSlow 3s linear infinite; }

/* Pop-in for success checkmark */
@keyframes iconPop {
  0% { transform: scale(0); opacity: 0; }
  60% { transform: scale(1.2); }
  100% { transform: scale(1); opacity: 1; }
}
.chat-icon-pop { animation: iconPop 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards; }

/* Shake for trash icon hover */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-2px) rotate(-5deg); }
  75% { transform: translateX(2px) rotate(5deg); }
}

/* Message slide-in from right (user) */
@keyframes msgSlideRight {
  from { opacity: 0; transform: translateX(12px); }
  to { opacity: 1; transform: translateX(0); }
}
.chat-msg-user { animation: msgSlideRight 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards; }

/* Message slide-in from left (assistant) */
@keyframes msgSlideLeft {
  from { opacity: 0; transform: translateX(-12px); }
  to { opacity: 1; transform: translateX(0); }
}
.chat-msg-assistant { animation: msgSlideLeft 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards; }

/* Thinking breathing glow */
@keyframes thinkGlow {
  0%, 100% { box-shadow: 0 0 0 0 oklch(0.78 0.14 85 / 0); }
  50% { box-shadow: 0 0 12px 2px oklch(0.78 0.14 85 / 0.15); }
}
.chat-thinking-glow { animation: thinkGlow 2s ease-in-out infinite; }

/* Typing wave for dots */
@keyframes typingWave {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}
.chat-typing-dot { animation: typingWave 1.4s ease-in-out infinite; }
.chat-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.3s; }

/* Panel slide transition */
.chat-panel-enter {
  transition: width 300ms cubic-bezier(0.16, 1, 0.3, 1),
              opacity 200ms ease-out;
}

/* ── Streamdown overrides ── */
[data-streamdown="table-wrapper"] {
  border: none;
  background: transparent;
  padding: 0;
}
[data-streamdown="table-wrapper"] > .flex.items-center.justify-end {
  display: none;
}
