/*
 * hasit.in — canonical design tokens.
 *
 * This is the single source of truth for colour, typography, radius, shadow
 * and motion across every hasit.in app. App stylesheets load this first and
 * then add only their own layout rules.
 *
 * Theme is resolved in three steps, later wins:
 *   1. :root                                   — light default
 *   2. @media (prefers-color-scheme: dark)     — OS preference, no-JS fallback
 *   3. html.dark-theme / html.light-theme      — explicit choice from localStorage
 *
 * The inline bootstrap in each document's <head> adds class 3 before first
 * paint; public/theme.js keeps it in sync after that.
 */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  color-scheme: light;

  /* Surfaces */
  --bg:               #FBFAF7;
  --surface:          #FFFFFF;
  --surface-hover:    #F4F2EC;
  --surface-glass:    rgba(255, 255, 255, 0.88);
  --nav-bg:           rgba(251, 250, 247, 0.8);

  /* Lines */
  --border:           #E6E2D8;
  --border-strong:    #CFC8B8;

  /* Text */
  --text-primary:     #1F1E1A;
  --text-secondary:   #5C5A52;
  --text-tertiary:    #6F6C63;

  /* Accent */
  --accent:           #5B5BD6;
  --accent-hover:     #4949C2;
  --accent-pressed:   #3D3DA8;
  --accent-subtle:    rgba(91, 91, 214, 0.12);
  --accent-violet:    #7C7CE6;

  /* Status */
  --success:          #2E9E5B;
  --success-subtle:   rgba(46, 158, 91, 0.12);
  --warning:          #D9A441;
  --warning-subtle:   rgba(217, 164, 65, 0.12);
  --danger:           #D14B4B;
  --danger-subtle:    rgba(209, 75, 75, 0.12);

  /* Typography */
  --font-ui:          'Inter', -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono:        'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Radius */
  --radius-ui:        8px;
  --radius:           12px;
  --radius-badge:     999px;

  /* Elevation */
  --shadow-sm:        0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md:        0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg:        0 10px 30px rgba(0, 0, 0, 0.12);

  /* Motion */
  --spring:           cubic-bezier(0.22, 1, 0.36, 1);
  --transition-fast:  0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition:       0.4s var(--spring);

  /* Layout */
  --max-width:        1080px;
  --content-width:    720px;

  /* Legacy aliases — the trx stylesheet predates the canonical names.
     Kept so existing rules keep working; new code should use the names above. */
  --bg-canvas:        var(--bg);
  --bg-elevated:      var(--surface);
  --bg-subtle:        var(--surface-hover);
  --bg-glass:         var(--surface-glass);
  --accent-dim:       var(--accent-subtle);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --bg:               #14130F;
    --surface:          #1C1B17;
    --surface-hover:    #25241E;
    --surface-glass:    rgba(28, 27, 23, 0.88);
    --nav-bg:           rgba(20, 19, 15, 0.8);

    --border:           #34322B;
    --border-strong:    #4A473D;

    --text-primary:     #ECE9DF;
    --text-secondary:   #B4B0A3;
    --text-tertiary:    #8F8C82;

    --accent:           #7C7CE6;
    --accent-hover:     #9494EC;
    --accent-pressed:   #6666CC;
    --accent-subtle:    rgba(124, 124, 230, 0.16);
    --accent-violet:    #9494EC;

    --success:          #3DBE73;
    --success-subtle:   rgba(61, 190, 115, 0.16);
    --warning:          #E6BB66;
    --warning-subtle:   rgba(230, 187, 102, 0.16);
    --danger:           #E26C6C;
    --danger-subtle:    rgba(226, 108, 108, 0.16);
  }
}

html.dark-theme {
  color-scheme: dark;

  --bg:               #14130F;
  --surface:          #1C1B17;
  --surface-hover:    #25241E;
  --surface-glass:    rgba(28, 27, 23, 0.88);
  --nav-bg:           rgba(20, 19, 15, 0.8);

  --border:           #34322B;
  --border-strong:    #4A473D;

  --text-primary:     #ECE9DF;
  --text-secondary:   #B4B0A3;
  --text-tertiary:    #8F8C82;

  --accent:           #7C7CE6;
  --accent-hover:     #9494EC;
  --accent-pressed:   #6666CC;
  --accent-subtle:    rgba(124, 124, 230, 0.16);
  --accent-violet:    #9494EC;

  --success:          #3DBE73;
  --success-subtle:   rgba(61, 190, 115, 0.16);
  --warning:          #E6BB66;
  --warning-subtle:   rgba(230, 187, 102, 0.16);
  --danger:           #E26C6C;
  --danger-subtle:    rgba(226, 108, 108, 0.16);
}

html.light-theme {
  color-scheme: light;

  --bg:               #FBFAF7;
  --surface:          #FFFFFF;
  --surface-hover:    #F4F2EC;
  --surface-glass:    rgba(255, 255, 255, 0.88);
  --nav-bg:           rgba(251, 250, 247, 0.8);

  --border:           #E6E2D8;
  --border-strong:    #CFC8B8;

  --text-primary:     #1F1E1A;
  --text-secondary:   #5C5A52;
  --text-tertiary:    #6F6C63;

  --accent:           #5B5BD6;
  --accent-hover:     #4949C2;
  --accent-pressed:   #3D3DA8;
  --accent-subtle:    rgba(91, 91, 214, 0.12);
  --accent-violet:    #7C7CE6;

  --success:          #2E9E5B;
  --success-subtle:   rgba(46, 158, 91, 0.12);
  --warning:          #D9A441;
  --warning-subtle:   rgba(217, 164, 65, 0.12);
  --danger:           #D14B4B;
  --danger-subtle:    rgba(209, 75, 75, 0.12);
}

/* Shared theme-toggle button. Apps only supply the markup. */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-ui);
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color var(--transition-fast), background-color var(--transition-fast), border-color var(--transition-fast);
}

.theme-toggle:hover {
  color: var(--text-primary);
  background-color: var(--surface-hover);
  border-color: var(--border);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
  display: none;
}

html.dark-theme .theme-toggle .icon-sun,
html.light-theme .theme-toggle .icon-moon {
  display: block;
}

/* No explicit choice yet: mirror the OS preference. */
@media (prefers-color-scheme: dark) {
  html:not(.light-theme) .theme-toggle .icon-sun { display: block; }
  html:not(.light-theme) .theme-toggle .icon-moon { display: none; }
}

@media (prefers-color-scheme: light) {
  html:not(.dark-theme) .theme-toggle .icon-sun { display: none; }
  html:not(.dark-theme) .theme-toggle .icon-moon { display: block; }
}
