/* Shared tokens and primitives for every surface: the static builder at /, the
   managed CRUD at /manage, and the public list at /l/:slug. Both stylesheets
   import this file so buttons, cards, and inputs cannot drift apart again. */

:root {
  /* raw palettes - each value appears once, the pointers below select one */
  --paper-bg: #faf9f7;
  --paper-surface: #ffffff;
  --paper-surface-2: #f3f0eb;
  --paper-border: #e5e1db;
  --paper-border-strong: #d5cfc6;
  --paper-text: #1a1815;
  --paper-muted: #6b645c;
  --paper-accent: #c2410c;
  --paper-accent-fg: #ffffff;
  --paper-accent-text: #9a3412;
  --paper-accent-soft: #fdf1ea;
  --paper-danger-text: #b3261e;
  --paper-success-text: #1f6a3f;
  --paper-ring: rgba(194, 65, 12, 0.32);

  --ink-bg: #121110;
  --ink-surface: #1c1a19;
  --ink-surface-2: #262322;
  --ink-border: #302c2a;
  --ink-border-strong: #453f3b;
  --ink-text: #f2efea;
  --ink-muted: #a8a099;
  --ink-accent: #f97316;
  --ink-accent-fg: #1a0f04;
  --ink-accent-text: #fdba74;
  --ink-accent-soft: #2a1b10;
  --ink-danger-text: #fca5a5;
  --ink-success-text: #86d3a5;
  --ink-ring: rgba(249, 115, 22, 0.4);

  color-scheme: light;
  --bg: var(--paper-bg);
  --surface: var(--paper-surface);
  --surface-2: var(--paper-surface-2);
  --border: var(--paper-border);
  --border-strong: var(--paper-border-strong);
  --text: var(--paper-text);
  --muted: var(--paper-muted);
  --accent: var(--paper-accent);
  --accent-fg: var(--paper-accent-fg);
  --accent-text: var(--paper-accent-text);
  --accent-soft: var(--paper-accent-soft);
  --danger-text: var(--paper-danger-text);
  --success-text: var(--paper-success-text);
  --ring: var(--paper-ring);

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 48px;

  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-md: 1.0625rem;
  --text-lg: 1.25rem;
  --text-xl: 1.5rem;
  --display: clamp(1.9rem, 5vw, 2.5rem);

  --shadow-sm: 0 1px 2px rgba(26, 24, 21, 0.06);
  --shadow: 0 6px 20px -8px rgba(26, 24, 21, 0.16);

  --font-sans:
    ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  --font-fa: Vazirmatn, "Segoe UI", Tahoma, sans-serif;
}

/* theme.js resolves the system preference into an explicit data-theme, so the
   media query below only covers the no-JS case */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: var(--ink-bg);
    --surface: var(--ink-surface);
    --surface-2: var(--ink-surface-2);
    --border: var(--ink-border);
    --border-strong: var(--ink-border-strong);
    --text: var(--ink-text);
    --muted: var(--ink-muted);
    --accent: var(--ink-accent);
    --accent-fg: var(--ink-accent-fg);
    --accent-text: var(--ink-accent-text);
    --accent-soft: var(--ink-accent-soft);
    --danger-text: var(--ink-danger-text);
    --success-text: var(--ink-success-text);
    --ring: var(--ink-ring);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: var(--ink-bg);
  --surface: var(--ink-surface);
  --surface-2: var(--ink-surface-2);
  --border: var(--ink-border);
  --border-strong: var(--ink-border-strong);
  --text: var(--ink-text);
  --muted: var(--ink-muted);
  --accent: var(--ink-accent);
  --accent-fg: var(--ink-accent-fg);
  --accent-text: var(--ink-accent-text);
  --accent-soft: var(--ink-accent-soft);
  --danger-text: var(--ink-danger-text);
  --success-text: var(--ink-success-text);
  --ring: var(--ink-ring);
}

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

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

:lang(fa) {
  font-family: var(--font-fa);
  line-height: 1.75;
}

h1,
h2,
h3 {
  margin: 0 0 var(--space-2);
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

h1 {
  font-size: var(--display);
  letter-spacing: -0.03em;
}

h2 {
  font-size: var(--text-lg);
}

h3 {
  font-size: var(--text-base);
}

p {
  margin: 0 0 var(--space-4);
  color: var(--muted);
}

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

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

/* surfaces */

.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

/* buttons */

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-4);
  background: var(--accent);
  color: var(--accent-fg);
  font: inherit;
  font-size: var(--text-base);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background 140ms ease,
    border-color 140ms ease,
    color 140ms ease;
}

.button.secondary {
  border-color: var(--border-strong);
  background: var(--surface);
  color: var(--text);
}

.button.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text);
}

.button.danger {
  border-color: var(--border-strong);
  background: var(--surface);
  color: var(--danger-text);
}

.button.small {
  min-height: 34px;
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-sm);
}

@media (hover: hover) {
  .button:hover {
    background: color-mix(in srgb, var(--accent) 86%, black);
  }

  .button.secondary:hover,
  .button.ghost:hover {
    border-color: var(--border-strong);
    background: var(--surface-2);
  }

  .button.danger:hover {
    border-color: var(--danger-text);
    background: var(--surface-2);
  }
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.text-button {
  border: 0;
  border-radius: var(--radius-sm);
  padding: var(--space-2);
  background: transparent;
  color: var(--accent-text);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
}

.text-button.danger {
  color: var(--danger-text);
}

.text-button:hover {
  text-decoration: underline;
}

.icon-button {
  display: inline-flex;
  width: 34px;
  height: 34px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  line-height: 1;
  cursor: pointer;
}

.icon-button:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
}

.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

/* form controls */

label span,
.output-label {
  display: block;
  margin-bottom: var(--space-1);
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 500;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: var(--text-base);
}

input::placeholder {
  color: var(--muted);
  opacity: 0.7;
}

input:focus-visible,
select:focus-visible {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--ring);
}

input[aria-invalid="true"] {
  border-color: var(--danger-text);
}

fieldset {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  background: var(--surface);
}

legend {
  padding: 0 var(--space-1);
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 600;
}

/* link card - the one component every surface renders */

.link-card {
  position: relative;
  display: block;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding-block: var(--space-4);
  padding-inline: var(--space-4) var(--space-8);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  color: inherit;
  text-align: start;
  text-decoration: none;
  transition:
    border-color 140ms ease,
    background 140ms ease,
    box-shadow 140ms ease;
}

/* chevron drawn from borders so it mirrors in rtl and stays out of the
   accessibility tree, unlike a ">" text glyph */
.link-card::after {
  content: "";
  position: absolute;
  top: 50%;
  inset-inline-end: var(--space-5);
  width: 8px;
  height: 8px;
  border-top: 2px solid var(--muted);
  border-right: 2px solid var(--muted);
  transform: translateY(-50%) rotate(45deg);
  transition: border-color 140ms ease;
}

[dir="rtl"] .link-card::after {
  transform: translateY(-50%) rotate(-135deg);
}

.link-card:focus-visible,
.link-card:hover {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.link-card:hover::after,
.link-card:focus-visible::after {
  border-color: var(--accent-text);
}

.link-title {
  display: block;
  overflow-wrap: anywhere;
  font-size: var(--text-md);
  font-weight: 650;
  letter-spacing: -0.01em;
}

.link-description {
  display: block;
  margin-top: var(--space-1);
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: var(--text-sm);
}

/* status messages */

.status {
  min-height: 24px;
  margin: var(--space-4) 0;
  color: var(--muted);
  font-size: var(--text-sm);
}

.status:empty {
  margin: 0;
  min-height: 0;
}

.status.success {
  color: var(--success-text);
  font-weight: 600;
}

.status.error {
  color: var(--danger-text);
  font-weight: 600;
}

/* theme toggle - quiet utility, not a primary control */

.theme-toggle {
  display: inline-flex;
  min-height: 28px;
  min-width: 28px;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--radius-sm, 6px);
  padding: var(--space-1);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: var(--text-sm);
  opacity: 0.55;
  cursor: pointer;
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
  opacity: 0.9;
  color: var(--text);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 1ms !important;
    animation-duration: 1ms !important;
  }
}
