/**
 * Gist /try Page Styles
 *
 * SYNCED WITH: extension/ui/brand.css (the Gist design system source of truth).
 * When brand.css tokens change, update the :root block here to match.
 * /try lives in the backend (Cloudflare Worker SSR), so it can't <link>
 * the extension's brand.css directly — tokens are duplicated by convention.
 *
 * DESIGN SYSTEM:
 * - Font: Inter (loaded via Google Fonts in try.ts SSR shell)
 * - Gradient: #FF6B6B → #FFD93D → #FF8E53 (sunrise — coral → gold → orange)
 * - Ink hierarchy: primary (#1C1C24), secondary, tertiary, faint
 * - Paper hierarchy: paper, wash, surface
 * - Dark mode: warm #1C1C24 family (not generic black)
 * - Radius scale: 8 / 12 / 16 / 999 (no orphan values)
 * - Spacing: 4px grid
 * - Wordmark: canonical proportions from Reader's .gist-identity
 *
 * TYPOGRAPHY:
 * - Inter (primary), system fonts as fallbacks
 * - Weights: 400 (body), 500 (medium), 600 (semibold), 700 (bold), 800 (headline)
 * - Tracking: -0.03em for headlines, normal for body
 */

/* ============================================
   DESIGN TOKENS — Light Mode (Default)
   Synced with extension/ui/brand.css.
   ============================================ */
:root {
  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
  --font-display: 'Inter', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
  /**
   * Marketing headline font — Open Sans at weight 800.
   * Wider, more geometric letterforms than Inter at large uppercase sizes.
   * Used for .try-headline and other commanding display text.
   * Mirrors Font.display in src/ssr/brand.ts.
   */
  --font-headline: 'Open Sans', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;

  /* Text hierarchy */
  --ink: #1C1C24;
  --ink-secondary: #4a4a4a;
  --ink-tertiary: #666666;
  --ink-faint: #b0b0b0;

  /* Background hierarchy */
  --paper: #ffffff;
  --wash: #fafafa;
  --surface: #ffffff;

  /* Borders */
  --border: #e8e8e8;
  --border-light: #f0f0f0;

  /* Brand — Sunrise Gradient */
  --gradient-start: #FF6B6B;
  --gradient-mid: #FFD93D;
  --gradient-end: #FF8E53;
  --gradient: linear-gradient(135deg, var(--gradient-start), var(--gradient-mid), var(--gradient-end));

  /* Semantic */
  --error: #dc2626;
  --error-wash: #fef2f2;
  --success: #059669;
  --success-bg: #ecfdf5;

  /* Focus ring (/try-specific — used by input container + auth inputs) */
  --focus-ring: 0 0 0 3px rgba(255, 107, 107, 0.15);

  /* Border Radius Scale */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 999px;

  /* Spacing — 4px grid */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
}

/* ============================================
   DESIGN TOKENS — Dark Mode
   Warmer palette aligned with brand.css and Welcome page's
   #1C1C24 family (has personality vs generic black).
   ============================================ */
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #F5F5F5;
    --ink-secondary: #A0A0A8;
    --ink-tertiary: #6E6E76;
    --ink-faint: #48484E;

    --paper: #1C1C24;
    --wash: #141418;
    --surface: #24242C;

    --border: #2C2C34;
    --border-light: #24242C;

    --error: #f87171;
    --error-wash: #2d1f1f;

    --success: #34d399;
    --success-bg: #0f2922;
  }
}

/* ============================================
   RESET & BASE
   ============================================ */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  color-scheme: light dark;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--wash);
  color: var(--ink);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============================================
   LAYOUT
   ============================================ */
.try-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ============================================
   HEADER
   ============================================ */
.try-header {
  padding: var(--space-6) var(--space-8);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Wordmark: canonical proportions from Reader's .gist-identity
   and extension's .wordmark (brand.css). Same bolt, same weight,
   same tracking — one mark across every Gist surface. */
.try-logo {
  display: inline-flex;
  align-items: center;
  font-family: var(--font-display), var(--font-sans);
  font-weight: 800;
  font-size: 1.5rem;
  letter-spacing: -0.03em;
  text-decoration: none;
  color: var(--ink);
  transition: opacity 0.2s ease;
}

.try-logo:hover {
  opacity: 0.7;
}

.try-logo:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

.try-logo-bolt {
  width: 0.9em;
  height: 1.5em;
  margin-right: 0.08em;
}

.try-nav {
  display: flex;
  align-items: center;
  gap: var(--space-8);
}

.try-nav-link {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--ink-tertiary);
  text-decoration: none;
  transition: color 0.15s ease;
}

.try-nav-link:hover {
  color: var(--ink);
}

.try-nav-link:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

.try-auth-status {
  font-size: 0.875rem;
  color: var(--ink-secondary);
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: none;
}

.try-auth-status.visible {
  display: inline-block;
}

.try-signin-btn {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--ink-secondary);
  background: transparent;
  border: 1px solid var(--border);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.try-signin-btn:hover {
  background: var(--wash);
  border-color: var(--ink-tertiary);
}

.try-signin-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* ============================================
   MAIN CONTENT
   ============================================ */
.try-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-10) var(--space-6) var(--space-12);
}

/* ============================================
   HERO SECTION
   ============================================ */
.try-hero {
  text-align: center;
  max-width: 720px;
  margin-bottom: var(--space-12);
}

.try-headline {
  font-family: var(--font-headline);
  font-weight: 800;
  font-size: clamp(2.5rem, 7vw, 4rem);
  line-height: 1.1;
  letter-spacing: -0.03em;
  text-transform: uppercase;
  margin-bottom: var(--space-5);
}

.try-headline-line {
  display: block;
}

.try-gradient-text {
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.try-subheadline {
  font-size: 1rem;
  color: var(--ink-secondary);
  line-height: 1.5;
  max-width: 400px;
  margin: 0 auto;
}

/* ============================================
   INPUT CONTAINER
   ============================================ */
.try-input-wrap {
  width: 100%;
  max-width: 680px;
}

.try-input-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.try-input-container:focus-within {
  border-color: var(--gradient-start);
  box-shadow: var(--focus-ring);
}

.try-input-container.drag-over {
  border-color: var(--gradient-mid);
  background: rgba(255, 217, 61, 0.04);
}

.try-textarea {
  width: 100%;
  min-height: 120px;
  max-height: 300px;
  resize: none;
  border: none;
  background: none;
  font-family: inherit;
  font-size: 0.9375rem;
  padding: var(--space-5) var(--space-6);
  color: var(--ink);
  outline: none;
  line-height: 1.5;
}

.try-textarea::placeholder {
  color: var(--ink-faint);
}

.try-textarea[readonly] {
  cursor: not-allowed;
}

/* ============================================
   FILE PREVIEW
   ============================================ */
.try-file-preview {
  display: none;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  margin: 0 var(--space-4) var(--space-3);
  background: var(--wash);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  color: var(--ink-secondary);
}

.try-file-preview.visible {
  display: flex;
}

.try-file-icon {
  width: 18px;
  height: 18px;
  color: var(--gradient-start);
  flex-shrink: 0;
}

.try-file-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.try-file-remove {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  color: var(--ink-faint);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}

.try-file-remove:hover {
  background: var(--border);
  color: var(--ink);
}

.try-file-remove:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* ============================================
   CONTROLS ROW
   ============================================ */
.try-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-light);
  background: var(--wash);
}

.try-controls-left {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.try-controls-right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* ============================================
   ICON BUTTON
   ============================================ */
.try-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: none;
  background: none;
  border-radius: var(--radius-md);
  color: var(--ink-tertiary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.try-icon-btn:hover {
  background: var(--surface);
  color: var(--ink);
}

.try-icon-btn svg {
  width: 20px;
  height: 20px;
}

.try-icon-btn.is-locked,
.try-icon-btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
}

.try-icon-btn.is-locked:hover,
.try-icon-btn[aria-disabled="true"]:hover {
  background: none;
  color: var(--ink-tertiary);
}

.try-icon-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.try-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ============================================
   LANGUAGE SELECTOR
   ============================================ */
.try-lang-selector {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.try-lang-trigger {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: none;
  background: none;
  border-radius: var(--radius-md);
  color: var(--ink-tertiary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.try-lang-trigger:hover {
  background: var(--surface);
  color: var(--ink);
}

.try-lang-trigger:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.try-lang-trigger svg {
  width: 20px;
  height: 20px;
}

.try-lang-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink-secondary);
  display: none;
}

.try-lang-label.visible {
  display: block;
}

.try-lang-dropdown {
  position: absolute;
  bottom: calc(100% + var(--space-2));
  right: 0;
  width: 200px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  padding: var(--space-2);
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: all 0.15s ease;
  z-index: 100;
}

.try-lang-selector.open .try-lang-dropdown {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* A-034: Viewport-aware flip — open downward when insufficient space above. */
.try-lang-dropdown.flip-down {
  bottom: auto;
  top: calc(100% + var(--space-2));
}

.try-lang-section-title {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-tertiary);
  padding: var(--space-2) var(--space-3);
  margin-top: var(--space-2);
}

.try-lang-section-title:first-child {
  margin-top: 0;
}

.try-lang-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: none;
  background: none;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.1s ease;
}

.try-lang-option:hover {
  background: var(--wash);
}

.try-lang-option:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.try-lang-option.selected {
  color: var(--gradient-start);
}

.try-lang-check {
  width: 14px;
  height: 14px;
  opacity: 0;
}

.try-lang-option.selected .try-lang-check {
  opacity: 1;
}

/* ============================================
   SUBMIT BUTTON
   ============================================ */
.try-submit-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  background: var(--gradient);
  border: none;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  /* Always dark text on gradient background (like options.css threshold-option.always) */
  color: #1C1C24;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.try-submit-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(255, 107, 107, 0.35);
}

.try-submit-btn:active:not(:disabled) {
  transform: translateY(0);
}

.try-submit-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.try-submit-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.5), var(--focus-ring);
}

.try-submit-icon {
  width: 14px;
  height: 24px;
}

/* ============================================
   HELPER TEXT
   ============================================ */
.try-helper {
  text-align: center;
  margin-top: var(--space-4);
  font-size: 0.8125rem;
  color: var(--ink-faint);
}

.try-helper.is-speculating {
  color: var(--ink-secondary);
}

/* ============================================
   STATUS MESSAGE
   ============================================ */
.try-status {
  text-align: center;
  margin-top: var(--space-4);
  font-size: 0.875rem;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  display: none;
}

.try-status.visible {
  display: block;
}

.try-status.loading {
  color: var(--ink-secondary);
  background: var(--wash);
}

.try-status.success {
  color: var(--success);
  background: var(--success-bg);
}

.try-status.error {
  color: var(--error);
  background: var(--error-wash);
}

/* ============================================
   INLINE TOAST
   ============================================ */
.try-toast {
  text-align: center;
  margin-top: var(--space-3);
  font-size: 0.8125rem;
  color: var(--ink-secondary);
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  min-height: 1.25em;
}

.try-toast.visible {
  opacity: 1;
  transform: translateY(0);
}

/* A-043: Dark mode success colors now use --success/--success-bg tokens in :root. */

/* ============================================
   AUTH MODAL
   ============================================ */
.try-auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 1000;
}

.try-auth-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.try-auth-modal {
  position: relative;
  width: min(420px, 92vw);
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-8);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

.try-auth-close {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  background: transparent;
  border: none;
  color: var(--ink-tertiary);
  cursor: pointer;
  padding: var(--space-2);
  border-radius: var(--radius-sm);
}

.try-auth-close:hover {
  background: var(--wash);
  color: var(--ink);
}

.try-auth-close:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.try-auth-close svg {
  width: 18px;
  height: 18px;
}

.try-auth-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: var(--space-2);
}

.try-auth-subtitle {
  font-size: 0.95rem;
  color: var(--ink-secondary);
  margin-bottom: var(--space-6);
}

.try-auth-error {
  display: none;
  color: var(--error);
  background: var(--error-wash);
  border: 1px solid rgba(220, 38, 38, 0.2);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  margin-bottom: var(--space-4);
}

.try-auth-error.visible {
  display: block;
}

.try-auth-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.try-auth-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-secondary);
}

.try-auth-input {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-size: 0.95rem;
  color: var(--ink);
}

.try-auth-input:focus {
  outline: none;
  border-color: var(--gradient-start);
  box-shadow: var(--focus-ring);
}

.try-auth-submit {
  margin-top: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: none;
  background: var(--gradient);
  color: #1C1C24;
  font-weight: 700;
  cursor: pointer;
}

.try-auth-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.try-auth-submit:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.5), var(--focus-ring);
}

.try-auth-divider {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--ink-faint);
  font-size: 0.85rem;
  margin: var(--space-5) 0;
}

.try-auth-divider::before,
.try-auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-light);
}

/* Google sign-in button: aligned with .auth-button--google from brand.css.
   "Continue with Google" copy + Google G icon + radius-sm + brand font treatment. */
.try-auth-google {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.try-auth-google svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.try-auth-google:hover:not(:disabled) {
  background: var(--wash);
  border-color: var(--ink-tertiary);
}

.try-auth-google:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.try-auth-google:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* ============================================
   FOOTER
   ============================================ */
.try-footer {
  padding: var(--space-6) var(--space-8);
  display: flex;
  justify-content: center;
  gap: var(--space-8);
  border-top: 1px solid var(--border-light);
}

.try-footer-link {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink-faint);
  text-decoration: none;
  transition: color 0.15s ease;
}

.try-footer-link:hover {
  color: var(--ink-secondary);
}

.try-footer-link:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
  .try-header {
    padding: var(--space-5) var(--space-5);
  }

  .try-nav {
    gap: var(--space-4);
  }

  .try-nav-link {
    display: none;
  }

  .try-auth-status {
    display: none !important;
  }

  .try-main {
    padding: var(--space-6) var(--space-4) var(--space-10);
  }

  .try-hero {
    margin-bottom: var(--space-8);
  }

  .try-subheadline {
    font-size: 1rem;
  }

  .try-textarea {
    min-height: 100px;
    padding: var(--space-4) var(--space-5);
    font-size: 0.9375rem;
  }

  .try-controls {
    padding: var(--space-3);
  }

  .try-submit-btn {
    padding: var(--space-3) var(--space-4);
    font-size: 0.875rem;
  }

  /* A-033: Show compact label on mobile instead of hiding entirely. */
  .try-lang-label.visible {
    display: block;
    max-width: 3ch;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .try-footer {
    padding: var(--space-5);
    gap: var(--space-6);
  }
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* A-042: CSS class for spinner so prefers-reduced-motion rule applies. */
.try-spinner {
  animation: spin 0.6s linear infinite;
}

/* ============================================
   REDUCED MOTION
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}
