/* ============================================================
   Shell Polish — Design System
   https://shellpolish.tools
   ============================================================ */

/* ── CSS Variables ────────────────────────────────────────── */
:root {
  /* Brand palette */
  --accent:        #0d6f66;
  --accent-dark:   #064c46;
  --accent-light:  #e6f4f3;
  --rose:          #bd3f56;

  /* Neutrals — light (app content) */
  --paper:         #fbfaf6;
  --ink:           #1a1917;
  --muted:         #6b6560;
  --line:          #ddd8ce;
  --surface:       #fffefb;
  --surface-alt:   #f4f0e7;

  /* Site shell — dark */
  --site-bg:       #0e0e0e;
  --site-surface:  #161616;
  --site-border:   #272727;
  --site-text:     #e8e4dc;
  --site-muted:    #9a948e;   /* 4.95:1 contrast on --site-bg (was 7a7470, ~4.0:1) */
  --focus-ring:    #2dd4bf;

  /* Terminal */
  --term-bg:       #171715;
  --term-text:     #f0ebe0;
  --term-muted:    rgba(240,235,224,0.45);

  /* Typography */
  --mono:   "SFMono-Regular", "Cascadia Code", "Consolas", "Liberation Mono", monospace;
  --serif:  Georgia, "Times New Roman", serif;
  --sans:   "Inter", "Avenir Next", system-ui, -apple-system, sans-serif;

  /* Spacing */
  --gap:    14px;
  --radius: 4px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.12);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.16);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.22);

  /* Splitter */
  --input-size:  1;
  --output-size: 1;
}

/* ── Reset ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  background: var(--site-bg);
  color: var(--site-text);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; border: 0; cursor: pointer; }
textarea { font: inherit; }
img, svg { display: block; }

/* Skip link — visible on focus only */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  z-index: 1000;
  padding: 8px 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  border-radius: var(--radius);
}
.skip-link:focus,
.skip-link:focus-visible {
  left: 8px;
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Global focus ring */
:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}
button:focus-visible,
a:focus-visible,
.toggle-chip:focus-within {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}
textarea:focus-visible,
.formatted-output:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: -2px;
}
.splitter:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: -2px;
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Site Layout ──────────────────────────────────────────── */
.site-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Site Header ──────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: 52px;
  display: flex;
  align-items: center;
  padding: 0 20px;
  background: rgba(22, 22, 22, 0.85);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--site-border);
  gap: 24px;
  transition: box-shadow 0.25s ease, border-color 0.25s ease;
}
.site-header.is-stuck {
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  border-bottom-color: transparent;
}

.site-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--serif);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--site-text);
  letter-spacing: -0.01em;
  white-space: nowrap;
  flex-shrink: 0;
}

.site-logo .logo-badge {
  font-family: var(--mono);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 6px;
  background: var(--accent);
  color: #fff;
  border-radius: 2px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
}

.site-nav a {
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  color: var(--site-muted);
  transition: color 0.15s, background 0.15s;
}

.site-nav a:hover,
.site-nav a.active {
  color: var(--site-text);
  background: var(--site-border);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.lang-btn {
  min-width: 40px;
  height: 28px;
  padding: 0 10px;
  background: transparent;
  border: 1px solid var(--site-border);
  border-radius: var(--radius);
  color: var(--site-muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  transition: color 0.15s, border-color 0.15s;
}

.lang-btn:hover {
  color: var(--site-text);
  border-color: var(--site-muted);
}

/* Header back-to-tool link (used on content pages) */
.header-back {
  height: 28px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border-radius: var(--radius);
  border: 1px solid var(--site-border);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--site-muted);
  transition: color 0.15s, border-color 0.15s;
}
.header-back:hover {
  color: var(--site-text);
  border-color: var(--site-muted);
}

/* Code block sample on About page */
.code-sample {
  background: var(--site-surface);
  border: 1px solid var(--site-border);
  border-radius: var(--radius);
  padding: 16px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--site-text);
  line-height: 1.6;
  margin: 0 0 1em;
}
.code-sample .c { color: var(--site-muted); }

/* Last-updated note */
.last-updated {
  margin-top: 40px;
  font-size: 0.85rem;
  color: var(--site-muted);
}

/* ── App Container ────────────────────────────────────────── */
.app-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: var(--gap);
  gap: var(--gap);
  background: var(--site-bg);
}

/* ── App Toolbar ──────────────────────────────────────────── */
.app-toolbar {
  position: sticky;
  top: 52px;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: rgba(22, 22, 22, 0.85);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border: 1px solid var(--site-border);
  border-radius: var(--radius);
  flex-wrap: wrap;
  row-gap: 6px;
  transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 0.25s ease,
              opacity 0.25s ease;
  will-change: transform;
}
/* When the toolbar becomes stuck (scrolled past its in-flow position),
   a soft shadow + accent border-bottom appear to lift it off the content. */
.app-toolbar.is-stuck {
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.55);
  border-color: rgba(13, 111, 102, 0.35);
}

.toolbar-divider {
  width: 1px;
  height: 22px;
  background: var(--site-border);
  flex-shrink: 0;
  margin: 0 2px;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.toolbar-group.toggles {
  flex: 1;
  gap: 4px;
}

.toolbar-group.end {
  margin-left: auto;
}

/* Toolbar buttons */
.tb-btn {
  height: 30px;
  padding: 0 12px;
  border-radius: var(--radius);
  font-size: 0.8rem;
  font-weight: 600;
  background: transparent;
  border: 1px solid var(--site-border);
  color: var(--site-muted);
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.tb-btn:hover {
  color: var(--site-text);
  border-color: var(--site-muted);
  background: rgba(255,255,255,0.04);
}

.tb-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.tb-btn.primary:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.tb-btn.icon {
  width: 30px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 1rem;
}

.tb-btn.active {
  color: var(--site-text);
  border-color: var(--site-muted);
  background: rgba(255,255,255,0.06);
}

/* Compact toggle chips */
.toggle-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 9px;
  border-radius: 14px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--site-border);
  cursor: pointer;
  font-size: 0.78rem;
  color: var(--site-muted);
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  white-space: nowrap;
  user-select: none;
}

.toggle-chip input[type="checkbox"] {
  width: 13px;
  height: 13px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.toggle-chip:has(input:checked) {
  color: var(--site-text);
  border-color: var(--accent);
  background: rgba(13, 111, 102, 0.12);
}

.toggle-chip:hover {
  color: var(--site-text);
  border-color: var(--site-muted);
}

/* ── Workspace ────────────────────────────────────────────── */
/* CSS Grid for the two panes + splitter: fr units distribute space
   predictably in both vertical (columns) and horizontal (rows) layouts,
   without relying on the flex height chain. */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 5px 1fr;
  grid-template-rows: 1fr;
  min-height: 0;
  border: 1px solid var(--site-border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--site-surface);
}

.workspace.layout-horizontal {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr 5px 1fr;
}

/* ── Panes ────────────────────────────────────────────────── */
.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.input-pane {
  min-width: 180px;
  border-right: 1px solid var(--site-border);
}

.workspace.layout-horizontal .input-pane {
  border-right: none;
  border-bottom: 1px solid var(--site-border);
}

.output-pane {
  min-width: 180px;
}

/* Pane header */
.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  background: var(--site-surface);
  border-bottom: 1px solid var(--site-border);
  flex-shrink: 0;
}

.pane-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--site-muted);
}

.pane-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── Textarea (input) ─────────────────────────────────────── */
textarea {
  flex: 1;
  width: 100%;
  min-height: 0;
  resize: none;
  border: 0;
  outline: 0;
  padding: 16px;
  background: var(--term-bg);
  color: var(--term-text);
  font-family: var(--mono);
  font-size: 0.88rem;
  line-height: 1.65;
}

textarea::placeholder {
  color: var(--term-muted);
}

/* ── Formatted output ─────────────────────────────────────── */
.formatted-output-wrap {
  flex: 1;
  overflow: auto;
  background: var(--surface);
}

.formatted-output {
  min-height: 100%;
  padding: 24px 28px;
  font-family: var(--serif);
  font-size: 1.04rem;
  line-height: 1.72;
  color: var(--ink);
}

/* Boxed reading mode */
.output-pane.boxed .formatted-output {
  max-width: 700px;
  margin: 0 auto;
}

.formatted-output:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.95rem;
}

/* Output typography */
.formatted-output .sp-title {
  margin: 0 0 22px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--ink);
  font-family: var(--serif);
  font-size: clamp(1.35rem, 2.5vw, 2rem);
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.formatted-output p  { margin: 0 0 1em; }
.formatted-output br { margin: 0; }
.formatted-output p:last-child { margin-bottom: 0; }

.formatted-output ol,
.formatted-output ul {
  margin: 0 0 1em;
  padding-left: 1.5em;
}

.formatted-output li { margin: 0.25em 0; }

.formatted-output hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 1.5em 0;
}

.formatted-output .sp-json {
  background: var(--surface-alt);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  overflow: auto;
  margin: 0;
}

.formatted-output .sp-json code {
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.55;
  color: var(--ink);
}

/* Markdown tables */
.sp-table-wrap {
  max-width: 100%;
  margin: 0 0 1.1em;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.formatted-output table {
  width: 100%;
  min-width: 400px;
  border-collapse: collapse;
  font-family: var(--sans);
  font-size: 0.87rem;
  line-height: 1.4;
}

.formatted-output th,
.formatted-output td {
  padding: 9px 13px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

.formatted-output th:last-child,
.formatted-output td:last-child { border-right: none; }

.formatted-output tbody tr:last-child td { border-bottom: none; }

.formatted-output thead th {
  background: var(--ink);
  color: var(--paper);
  font-weight: 700;
}

.formatted-output tbody tr:nth-child(even) {
  background: var(--surface-alt);
}

/* ── Splitter ─────────────────────────────────────────────── */
.splitter {
  flex-shrink: 0;
  width: 5px;
  cursor: col-resize;
  background: var(--site-border);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  touch-action: none;
}

/* Invisible hit zone enlarges grabbable area without changing layout */
.splitter::before {
  content: '';
  position: absolute;
  inset: 0 -5px;
  cursor: inherit;
}
.workspace.layout-horizontal .splitter::before {
  inset: -5px 0;
}

.splitter::after {
  content: '';
  width: 2px;
  height: 32px;
  background: var(--site-muted);
  border-radius: 1px;
  opacity: 0.5;
  pointer-events: none;
}

.splitter:hover,
.splitter.dragging {
  background: var(--accent);
}

.splitter:hover::after,
.splitter.dragging::after {
  opacity: 1;
  background: rgba(255,255,255,0.6);
}

/* Horizontal layout splitter */
.workspace.layout-horizontal .splitter {
  width: 100%;
  height: 5px;
  cursor: row-resize;
}

.workspace.layout-horizontal .splitter::after {
  width: 32px;
  height: 2px;
}

/* ── Status bar ───────────────────────────────────────────── */
.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 10px;
  height: 32px;
  background: var(--site-surface);
  border: 1px solid var(--site-border);
  border-radius: var(--radius);
  font-size: 0.8rem;
  color: var(--site-muted);
  flex-shrink: 0;
}

.statusbar-stats {
  display: flex;
  align-items: center;
  gap: 16px;
}

.statusbar-stats span {
  display: flex;
  align-items: center;
  gap: 5px;
}

.statusbar-stats strong {
  color: var(--site-text);
  font-variant-numeric: tabular-nums;
}

/* ── Site Footer ──────────────────────────────────────────── */
.site-footer {
  background: var(--site-surface);
  border-top: 1px solid var(--site-border);
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--site-muted);
}

.footer-links {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.footer-links a {
  color: var(--site-muted);
  transition: color 0.15s;
}

.footer-links a:hover {
  color: var(--site-text);
}

/* ── Content pages (about, faq, legal) ───────────────────── */
.content-shell {
  background: var(--site-bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.content-main {
  flex: 1;
  max-width: 740px;
  margin: 0 auto;
  padding: 48px 24px 80px;
  width: 100%;
  color: var(--site-text);
}

.content-main h1 {
  font-family: var(--serif);
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin: 0 0 10px;
  color: #fff;
}

.content-eyebrow {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 16px;
}

.content-lead {
  font-size: 1.15rem;
  line-height: 1.65;
  color: var(--site-text);
  margin: 0 0 40px;
  border-bottom: 1px solid var(--site-border);
  padding-bottom: 32px;
}

.content-main h2 {
  font-family: var(--serif);
  font-size: 1.4rem;
  color: #fff;
  margin: 2em 0 0.6em;
  letter-spacing: -0.01em;
}

.content-main h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--site-text);
  margin: 1.6em 0 0.4em;
}

.content-main p {
  line-height: 1.75;
  color: #b8b2aa;
  margin: 0 0 1em;
}

.content-main a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.content-main a:hover { color: #fff; }

.content-main ul,
.content-main ol {
  padding-left: 1.5em;
  color: #b8b2aa;
  line-height: 1.75;
}

.content-main li { margin: 0.3em 0; }

/* FAQ accordion */
.faq-item {
  border-bottom: 1px solid var(--site-border);
}

.faq-question {
  width: 100%;
  background: transparent;
  border: none;
  text-align: left;
  padding: 18px 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--site-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  transition: color 0.15s;
}

.faq-question:hover { color: #fff; }

.faq-chevron {
  flex-shrink: 0;
  font-size: 0.8rem;
  color: var(--site-muted);
  transition: transform 0.2s;
}

.faq-item.open .faq-chevron { transform: rotate(180deg); }

.faq-answer {
  display: none;
  padding: 0 0 20px;
  color: #b8b2aa;
  line-height: 1.75;
}

.faq-item.open .faq-answer { display: block; }

/* Download card */
.download-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: var(--site-surface);
  border: 1px solid var(--site-border);
  border-radius: var(--radius);
  margin: 32px 0;
}

.download-card-icon {
  font-size: 1.8rem;
  flex-shrink: 0;
}

.download-card-body { flex: 1; }
.download-card-body strong { display: block; color: var(--site-text); margin-bottom: 4px; }
.download-card-body span { font-size: 0.85rem; color: var(--site-muted); }

.download-card-btn,
.content-main a.download-card-btn {
  padding: 8px 16px;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s;
}

.download-card-btn:hover,
.content-main a.download-card-btn:hover { background: var(--accent-dark); color: #fff; }

/* Inline code in content pages */
.content-main code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--site-border);
  color: var(--site-text);
  padding: 1px 6px;
  border-radius: 3px;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 900px) {
  .toolbar-group.toggles {
    order: 10;
    width: 100%;
  }

  .app-toolbar {
    row-gap: 8px;
  }
}

@media (max-width: 680px) {
  .site-header { padding: 0 12px; }
  .site-nav { display: none; }
  .app-container { padding: 8px; gap: 8px; }

  .workspace {
    flex-direction: column;
  }

  .input-pane {
    border-right: none;
    border-bottom: 1px solid var(--site-border);
    min-height: 200px;
  }

  .splitter { display: none; }

  .content-main { padding: 32px 16px 60px; }
}

/* ── Drag overlay (prevents iframe interference) ──────────── */
.drag-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
}

.drag-overlay.active {
  display: block;
  cursor: col-resize;
}

.drag-overlay.row-resize {
  cursor: row-resize;
}
