/* ----------------------
   Theme tokens (CSS Vars)
   ---------------------- */
:root {
  /* Light defaults */
  --bg: #ffffff;
  --fg: #1f2937;   /* gray-800 */
  --muted: #6b7280; /* gray-500 */
  --border: #e5e7eb; /* gray-200 */
  --focus: #9ca3af;  /* gray-400 */
  --link: #4b5563;   /* gray-600 */
  --link-hover: #374151; /* gray-700 */
  --link-visited: #6b7280; /* gray-500 */

  /* Docking layout tokens */
  --edge-gap: 12px;   /* matches footer/theme offsets */
  --ui-stack: 48px;   /* reserved vertical space for footer/theme */
  --dock-gap: 16px;   /* breathing room above footer/theme */
}

/* Respect system dark when there is NO explicit override */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --bg: #0b0f14;
    --fg: #e5e7eb;
    --muted: #9ca3af;
    --border: #1f2937;
    --focus: #9ca3af;
    --link: #9ca3af;   /* gray-400 */
    --link-hover: #d1d5db; /* gray-300 */
    --link-visited: #6b7280; /* gray-500 */
  }
}

/* Explicit overrides */
:root[data-theme="light"] {
  --bg: #ffffff;
  --fg: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --focus: #9ca3af;
  --link: #4b5563;
  --link-hover: #374151;
  --link-visited: #6b7280;
}
:root[data-theme="dark"] {
  --bg: #0b0f14;
  --fg: #e5e7eb;
  --muted: #9ca3af;
  --border: #1f2937;
  --focus: #9ca3af;
  --link: #9ca3af;
  --link-hover: #d1d5db;
  --link-visited: #6b7280;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background-color: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  display: grid;
  place-items: center;
  place-content: center;
  padding: 20px;
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  color-scheme: light dark; /* JS will set a single scheme when an explicit theme is chosen */
}

/* Link styles for better visibility in both themes */
a {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color 0.2s ease;
}

a:hover {
  color: var(--link-hover);
  text-decoration-thickness: 2px;
}

a:visited {
  color: var(--link-visited);
}

a:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
  border-radius: 2px;
}

/* When docked, allow normal scrolling */
body.sent,
body[data-sent] {
  display: block;
  place-items: initial;
  place-content: initial;
}

.container {
  width: min(760px, 100%);
  margin-inline: auto;
  padding-top: 2rem;
}

.greeting {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem; /* 16px */
  margin-bottom: 2rem; /* increased from 1.25rem */
  text-align: center;
}

.greeting > div {
  display: flex;
  align-items: center;
  gap: 1rem; /* 16px */
}

.greeting .intro {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
  max-width: 520px;
  margin: 0;
  opacity: 0.85;
}

#icon-canvas {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  /* No background/shadow for theme consistency */
  flex-shrink: 0;
}

h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0;
  line-height: 1.2;
  letter-spacing: -0.025em;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

form {
  display: block;
  width: 100%;
}

/* Prompt buttons container */
.prompt-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-top: 8px;
  margin-bottom: 8px;
  border-top: 1px solid var(--border);
  max-height: 64px; /* ~2 rows */
  overflow-y: auto;
  scrollbar-width: thin;
}

.prompt-button {
  padding: 4px 12px;
  font-size: 13px;
  font-family: inherit;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 9999px;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 28px;
  white-space: nowrap;
}

.prompt-button:hover {
  border-color: var(--muted);
  background: var(--border);
}

.prompt-button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.prompt-button:active {
  transform: translateY(1px);
}

.input-wrapper {
  position: relative;
  width: 100%;
}

input[type="text"] {
  width: 100%;
  padding: 16px 20px;
  font-size: 16px;
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 9999px; /* true pill */
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
  box-sizing: border-box;
}

input[type="text"]::placeholder {
  color: var(--muted);
  opacity: 1; /* ensure consistent placeholder contrast */
}

input[type="text"]:focus-visible {
  border-color: var(--focus);
  /* Fallback per code_design.md */
  box-shadow: 0 0 0 3px rgba(156, 163, 175, 0.35);
}

@supports (color: color-mix(in oklab, black, white)) {
  input[type="text"]:focus-visible {
    box-shadow: 0 0 0 3px color-mix(in oklab, var(--focus) 35%, transparent);
  }
}

.hint {
  margin-top: 0.75rem;
  font-size: 0.875rem;
  color: var(--muted);
}

/* Minimal scrollbar theming */
:root {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* Output region */
#output {
  display: block;
  margin-top: 1.25rem;
  font-size: 0.95rem;
  min-height: 1.2em; /* keeps layout stable before first output */
}

/* ---- Docking via fixed portal (after first send) ---- */
#dock-portal {
  position: fixed;
  left: 50%;
  bottom: calc(var(--edge-gap) + var(--ui-stack) + var(--dock-gap) + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(760px, calc(100vw - 24px));
  max-width: calc(100vw - 24px);
  z-index: 102; /* Above backdrop and footer/theme */
}
#dock-portal #ask-form { width: 100%; }
@media (prefers-reduced-motion: reduce) {
  #dock-portal #ask-form { transition: none !important; }
}

/* ---- Backdrop for docked input (prevents content overflow) ---- */
#dock-backdrop {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(to bottom, 
    transparent 0px, 
    var(--bg) 32px,
    var(--bg) 100%);
  z-index: 50; /* behind all bottom UI elements */
  pointer-events: none; /* allow clicks to pass through if needed */
}

/* Center the submitted text in the main content area */
/* Support both historical `.sent` class and new `[data-sent]` attribute */
body.sent .greeting,
body[data-sent] .greeting { display: none; }

body.sent .container,
body[data-sent] .container {
  /* Remove grid centering to allow normal scrolling */
  width: min(760px, 100%);
  margin-inline: auto;
  padding-top: 1rem; /* reduced padding when sent */
}

body.sent #output,
body[data-sent] #output {
  margin-top: 1.25rem; /* Keep consistent margin */
  text-align: left; /* Left align for better readability */
  font-size: 1.05rem;
}

/* ---------- Footer ---------- */
.footer {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  white-space: nowrap;
  z-index: 101; /* Above backdrop (50) and dock-portal (100) */
  max-width: calc(100vw - 160px); /* Account for theme button on left */
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Home button in prompt buttons section */
.prompt-button.home-button svg {
  width: 12px;
  height: 12px;
  opacity: 0.7;
}

/* ---------- Theme toggle button ---------- */
.theme-switch {
  position: fixed;
  left: 12px;
  bottom: 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 9999px;
  background: color-mix(in oklab, var(--bg) 80%, transparent);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0,0,0,.12);
  user-select: none;
  z-index: 101; /* Above backdrop (50) and dock-portal (100) */
}
.theme-switch:hover { border-color: var(--focus); }
.theme-switch:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--focus) 35%, transparent);
}
.theme-dot {
  width: 10px;
  height: 10px;
  border-radius: 9999px;
  background: currentColor;
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--bg) 50%, transparent);
}

/* ---------- Rendered Blocks ---------- */
#output .block {
  display: block;
  width: 100%;
  text-align: left; /* override centered text after 'sent' */
  margin: 12px 0;
}

#output .block-md {
  position: relative;
}

#output .block-md .md {
  line-height: 1.6;
}
#output .block-md h1,
#output .block-md h2,
#output .block-md h3 {
  margin: 0.5em 0 0.35em;
  line-height: 1.25;
}
#output .block-md p {
  margin: 0.5em 0;
}
#output .block-md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.9em;
  padding: 0.1em 0.35em;
  border: 1px solid var(--border);
  border-radius: 6px;
}

/* Copy button for markdown blocks */
#output .block-md .copy-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  padding: 6px 10px;
  font-size: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s ease, background-color 0.2s ease;
  z-index: 100;
  user-select: none;
}

#output .block-md:hover .copy-btn {
  opacity: 1;
}

/* Always show on focus for keyboard accessibility */
#output .block-md .copy-btn:focus {
  opacity: 1;
}


#output .block-md .copy-btn:hover {
  background: color-mix(in oklab, var(--bg) 90%, var(--fg));
  color: var(--fg);
}

#output .block-md .copy-btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
  box-shadow: 0 0 0 2px color-mix(in oklab, var(--focus) 35%, transparent);
}

#output .block-md .copy-btn.copied {
  background: #374151;
  color: white;
  border-color: #374151;
}

/* Table styling for markdown content */
#output table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5em 0;
}

#output table th,
#output table td {
  padding: 10px 12px;
  text-align: left;
}

#output table tr:hover {
  background: color-mix(in oklab, var(--fg) 3%, var(--bg));
}

/* Example card style for the HTML block */
#output .card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}
@supports (color: color-mix(in oklab, black, white)) {
  #output .card {
    background: color-mix(in oklab, var(--bg) 90%, var(--fg));
  }
}

  