/* ==========================================================================
   Hitaishi — shared design tokens + base layer (U18)
   Plain, professional, high-contrast. No component framework, no build step.
   Downstream pages (login/onboarding/coach) import this single stylesheet.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Design tokens
   -------------------------------------------------------------------------- */

:root {
  /* Surfaces */
  --h-bg: #fafaf9;
  --h-surface: #ffffff;
  --h-surface-2: #f1f1ef;
  --h-border: #d8d8d4;

  /* Text */
  --h-text: #1b1c1e;
  --h-text-muted: #53555a;
  --h-text-faint: #6c6e75;

  /* Accent — one restrained graphite ink */
  --h-accent: #4a4a4a;
  --h-accent-hover: #333333;
  --h-accent-contrast: #ffffff;

  /* Status */
  --h-danger: #b3261e;
  --h-success: #1c6b3c;
  --h-warning: #8a5a00;

  /* Radii */
  --h-radius-sm: 6px;
  --h-radius-md: 10px;
  --h-radius-lg: 16px;

  /* Spacing scale */
  --h-space-1: 4px;
  --h-space-2: 8px;
  --h-space-3: 12px;
  --h-space-4: 16px;
  --h-space-5: 24px;
  --h-space-6: 32px;
  --h-space-7: 48px;
  --h-space-8: 64px;

  /* Type */
  --h-font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --h-font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;

  /* Elevation */
  --h-shadow-sm: 0 1px 2px rgba(20, 22, 25, 0.07);
  --h-shadow-md: 0 4px 16px rgba(20, 22, 25, 0.12);

  /* Layout */
  --h-maxw-prose: 68ch;
  --h-maxw-app: 860px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --h-bg: #141517;
    --h-surface: #1d1f22;
    --h-surface-2: #26282c;
    --h-border: #3a3d42;

    --h-text: #e8e9ea;
    --h-text-muted: #a8abb0;
    --h-text-faint: #90939a;

    --h-accent: #b4b4b4;
    --h-accent-hover: #cfcfcf;
    --h-accent-contrast: #1a1a1a;

    --h-danger: #f2938c;
    --h-success: #7bcf9c;
    --h-warning: #e0b45c;

    --h-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --h-shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);
  }
}

/* --------------------------------------------------------------------------
   2. Reset + base typography
   -------------------------------------------------------------------------- */

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

* {
  margin: 0;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--h-font-sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--h-text);
  background: var(--h-bg);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

img,
svg,
video {
  display: block;
  max-width: 100%;
}

input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
}

p,
h1,
h2,
h3,
h4 {
  overflow-wrap: break-word;
}

h1 {
  font-size: 1.5rem;
  line-height: 1.3;
  font-weight: 650;
}

h2 {
  font-size: 1.25rem;
  line-height: 1.35;
  font-weight: 650;
}

h3 {
  font-size: 1.05rem;
  line-height: 1.4;
  font-weight: 600;
}

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

a:hover {
  color: var(--h-accent-hover);
}

code,
pre {
  font-family: var(--h-font-mono);
  font-size: 0.9em;
}

hr {
  border: 0;
  border-top: 1px solid var(--h-border);
  margin: var(--h-space-5) 0;
}

/* Visible focus on every interactive element */
:focus-visible {
  outline: 2px solid var(--h-accent);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   3. Buttons
   -------------------------------------------------------------------------- */

.h-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--h-space-2);
  min-height: 40px;
  padding: var(--h-space-2) var(--h-space-4);
  border: 1px solid transparent;
  border-radius: var(--h-radius-sm);
  font-weight: 550;
  font-size: 0.9375rem;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  background: var(--h-accent);
  color: var(--h-accent-contrast);
  transition: background-color 120ms ease, border-color 120ms ease,
    color 120ms ease;
  user-select: none;
}

.h-btn:hover {
  background: var(--h-accent-hover);
}

.h-btn:disabled,
.h-btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
}

.h-btn--secondary {
  background: var(--h-surface);
  color: var(--h-text);
  border-color: var(--h-border);
}

.h-btn--secondary:hover {
  background: var(--h-surface-2);
}

.h-btn--ghost {
  background: transparent;
  color: var(--h-accent);
}

.h-btn--ghost:hover {
  background: var(--h-surface-2);
  color: var(--h-accent-hover);
}

.h-btn--danger {
  background: var(--h-danger);
  color: #ffffff;
}

@media (prefers-color-scheme: dark) {
  .h-btn--danger {
    color: #2a0f0d;
  }
}

.h-btn--danger:hover {
  filter: brightness(0.92);
}

/* --------------------------------------------------------------------------
   4. Forms
   -------------------------------------------------------------------------- */

.h-field {
  display: flex;
  flex-direction: column;
  gap: var(--h-space-1);
  margin-bottom: var(--h-space-4);
}

.h-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--h-text);
}

.h-input {
  width: 100%;
  min-height: 40px;
  padding: var(--h-space-2) var(--h-space-3);
  border: 1px solid var(--h-border);
  border-radius: var(--h-radius-sm);
  background: var(--h-surface);
  color: var(--h-text);
  transition: border-color 120ms ease;
}

.h-input::placeholder {
  color: var(--h-text-faint);
}

.h-input:focus {
  border-color: var(--h-accent);
  outline: 2px solid var(--h-accent);
  outline-offset: 0;
}

.h-input[aria-invalid="true"],
.h-input.is-invalid {
  border-color: var(--h-danger);
}

.h-error {
  font-size: 0.8125rem;
  color: var(--h-danger);
  min-height: 1.2em;
}

/* --------------------------------------------------------------------------
   5. Card
   -------------------------------------------------------------------------- */

.h-card {
  background: var(--h-surface);
  border: 1px solid var(--h-border);
  border-radius: var(--h-radius-md);
  padding: var(--h-space-5);
  box-shadow: var(--h-shadow-sm);
}

/* --------------------------------------------------------------------------
   6. Segmented control (Personal | Professional)
   Usage: <div class="h-segmented" role="group">
            <button class="h-segmented__btn is-active" aria-pressed="true">…</button>
            <button class="h-segmented__btn" aria-pressed="false">…</button>
          </div>
   -------------------------------------------------------------------------- */

.h-segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--h-surface-2);
  border: 1px solid var(--h-border);
  border-radius: var(--h-radius-md);
}

.h-segmented__btn {
  min-height: 34px;
  min-width: 40px;
  padding: var(--h-space-1) var(--h-space-4);
  border: 0;
  border-radius: calc(var(--h-radius-md) - 3px);
  background: transparent;
  color: var(--h-text-muted);
  font-weight: 550;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease;
}

.h-segmented__btn:hover {
  color: var(--h-text);
}

.h-segmented__btn.is-active,
.h-segmented__btn[aria-pressed="true"],
.h-segmented__btn[aria-checked="true"] {
  background: var(--h-surface);
  color: var(--h-text);
  box-shadow: var(--h-shadow-sm);
}

/* --------------------------------------------------------------------------
   7. Switch (the Advanced toggle)
   Usage: <label class="h-switch">
            <input type="checkbox">
            <span class="h-switch__track" aria-hidden="true"></span>
            <span>Advanced</span>
          </label>
   -------------------------------------------------------------------------- */

.h-switch {
  display: inline-flex;
  align-items: center;
  gap: var(--h-space-2);
  min-height: 40px;
  cursor: pointer;
  font-size: 0.9375rem;
  user-select: none;
}

.h-switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.h-switch__track {
  flex: none;
  width: 40px;
  height: 22px;
  border-radius: 11px;
  background: var(--h-border);
  position: relative;
  transition: background-color 140ms ease;
}

.h-switch__track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--h-surface);
  box-shadow: var(--h-shadow-sm);
  transition: transform 140ms ease;
}

.h-switch input:checked + .h-switch__track {
  background: var(--h-accent);
}

.h-switch input:checked + .h-switch__track::after {
  transform: translateX(18px);
}

.h-switch input:focus-visible + .h-switch__track {
  outline: 2px solid var(--h-accent);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   8. Chip (suggested-next prompts)
   -------------------------------------------------------------------------- */

.h-chip {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: var(--h-space-2) var(--h-space-4);
  border: 1px solid var(--h-border);
  border-radius: 999px;
  background: var(--h-surface);
  color: var(--h-text);
  font-size: 0.875rem;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease;
}

.h-chip:hover {
  background: var(--h-surface-2);
  border-color: var(--h-text-faint);
}

/* --------------------------------------------------------------------------
   9. Spinner
   -------------------------------------------------------------------------- */

.h-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--h-border);
  border-top-color: var(--h-accent);
  border-radius: 50%;
  animation: h-spin 700ms linear infinite;
}

.h-spinner--lg {
  width: 32px;
  height: 32px;
  border-width: 3px;
}

@keyframes h-spin {
  to {
    transform: rotate(360deg);
  }
}

/* --------------------------------------------------------------------------
   10. Toasts (container + items are created by static/js/toast.js)
   -------------------------------------------------------------------------- */

#h-toasts {
  position: fixed;
  bottom: var(--h-space-5);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: var(--h-space-2);
  z-index: 1000;
  width: max-content;
  max-width: min(92vw, 480px);
}

.h-toast {
  padding: var(--h-space-3) var(--h-space-4);
  border-radius: var(--h-radius-sm);
  border: 1px solid var(--h-border);
  border-left: 3px solid var(--h-text-faint);
  background: var(--h-surface);
  color: var(--h-text);
  box-shadow: var(--h-shadow-md);
  font-size: 0.9375rem;
  cursor: pointer;
  animation: h-toast-in 160ms ease-out;
}

.h-toast--success {
  border-left-color: var(--h-success);
}

.h-toast--error {
  border-left-color: var(--h-danger);
}

.h-toast--warning {
  border-left-color: var(--h-warning);
}

.h-toast--info {
  border-left-color: var(--h-accent);
}

@keyframes h-toast-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* --------------------------------------------------------------------------
   11. Utilities
   -------------------------------------------------------------------------- */

.h-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;
}

.h-stack {
  display: flex;
  flex-direction: column;
  gap: var(--h-space-4);
}

.h-row {
  display: flex;
  align-items: center;
  gap: var(--h-space-3);
}

/* --------------------------------------------------------------------------
   12. Responsive + motion
   -------------------------------------------------------------------------- */

@media (max-width: 720px) {
  .h-row {
    flex-direction: column;
    align-items: stretch;
  }

  .h-card {
    padding: var(--h-space-4);
  }
}

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