/* ==========================================================================
   theme.css — tokens, base styles and the small UI kit shared by every page.

   The interface stays quiet: neutral paper, ink text, one green borrowed from
   a self-healing cutting mat. The cards supply the colour.
   ========================================================================== */

:root,
[data-theme="light"] {
  color-scheme: light;

  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Boska", Georgia, "Times New Roman", serif;

  --color-bg: #f1f1ef;
  --color-surface: #ffffff;
  --color-surface-2: #ffffff;
  --color-surface-offset: #ebebe8;
  --color-border: #dadad6;
  --color-border-strong: #c2c2bd;

  --color-text: #1f2124;
  --color-text-muted: #5d6064;
  --color-text-faint: #8a8d91;

  /* Cutting-mat green: the one accent. */
  --color-primary: #2e5a4c;
  --color-primary-hover: #234639;
  --color-primary-soft: #e1ebe6;
  --color-primary-ink: #234639;
  --color-on-primary: #ffffff;
  --color-accent: #2e5a4c;

  --color-danger: #a3302a;
  --color-danger-soft: #f6e4e2;
  --color-success: #2e6b4a;
  --color-success-soft: #e0efe6;

  --mat: #2f5b4d;
  --mat-line: rgba(255, 255, 255, 0.07);
  --mat-line-strong: rgba(255, 255, 255, 0.14);

  --shadow-pop: 0 8px 24px rgba(20, 22, 25, 0.12), 0 1px 3px rgba(20, 22, 25, 0.08);
  --scrim: rgba(20, 22, 25, 0.45);
}

[data-theme="dark"] {
  color-scheme: dark;

  --color-bg: #1a1b1d;
  --color-surface: #222326;
  --color-surface-2: #26282b;
  --color-surface-offset: #2d2f33;
  --color-border: #36383c;
  --color-border-strong: #4b4e53;

  --color-text: #e6e6e3;
  --color-text-muted: #a4a6aa;
  --color-text-faint: #777a7f;

  --color-primary: #86b8a4;
  --color-primary-hover: #a3cbbb;
  --color-primary-soft: #253a33;
  --color-primary-ink: #a3cbbb;
  --color-on-primary: #10211b;
  --color-accent: #86b8a4;

  --color-danger: #e57f76;
  --color-danger-soft: #3a2220;
  --color-success: #7fbf98;
  --color-success-soft: #1d3127;

  --mat: #1f3c33;
  --mat-line: rgba(255, 255, 255, 0.05);
  --mat-line-strong: rgba(255, 255, 255, 0.1);

  --shadow-pop: 0 10px 28px rgba(0, 0, 0, 0.45), 0 1px 3px rgba(0, 0, 0, 0.3);
  --scrim: rgba(0, 0, 0, 0.6);
}

:root {
  --radius-xs: 3px;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 10px;
  --radius-2xl: 12px;
  --radius-full: 9999px;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-7: 2rem;
  --space-8: 2.5rem;
  --space-10: 3.5rem;

  --text-xs: 0.8125rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.25rem;
  --text-xl: 1.75rem;
  --text-2xl: 2.25rem;

  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --transition: 140ms ease;

  /* Old names some pages still reference. */
  --shadow-xs: none;
  --shadow-sm: none;
  --shadow-md: var(--shadow-pop);
  --shadow-lg: var(--shadow-pop);
  --shadow-glow: none;
  --glass: var(--color-surface);
  --page-gradient: none;
  --color-primary-highlight: var(--color-primary-soft);
}

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

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

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

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

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.2;
  font-weight: 700;
}

p {
  margin: 0;
}

a {
  color: var(--color-primary);
  text-underline-offset: 3px;
}

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

button {
  cursor: pointer;
  border: 0;
  background: none;
  border-radius: var(--radius-md);
  transition: background-color var(--transition), color var(--transition), border-color var(--transition);
}

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

::selection {
  background: var(--color-primary-soft);
}

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

[hidden] {
  display: none !important;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 36px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
}

.btn[disabled],
.btn[aria-disabled="true"] {
  opacity: 0.5;
  pointer-events: none;
}

.btn svg {
  width: 16px;
  height: 16px;
  flex: none;
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-on-primary);
}
.btn-primary:hover {
  background: var(--color-primary-hover);
}

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

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
}
.btn-ghost:hover {
  background: var(--color-surface-offset);
  color: var(--color-text);
}

.btn-danger {
  background: var(--color-danger);
  color: #fff;
}
.btn-danger:hover {
  filter: brightness(0.92);
}

.btn-sm {
  height: 30px;
  padding: 0 10px;
  font-size: var(--text-xs);
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
}
.btn-icon:hover {
  background: var(--color-surface-offset);
  color: var(--color-text);
}
.btn-icon svg {
  width: 18px;
  height: 18px;
}

.btn-block {
  width: 100%;
}

/* --------------------------------------------------------------------------
   Form fields
   -------------------------------------------------------------------------- */
.input,
input[type="text"],
input[type="email"],
input[type="search"],
input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%;
  min-height: 38px;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
}

input::placeholder,
textarea::placeholder {
  color: var(--color-text-faint);
}

.input:focus,
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-soft);
}

select {
  appearance: none;
  padding-right: 2rem;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 16px) 52%, calc(100% - 11px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.field {
  display: grid;
  gap: 6px;
}

.field > .label {
  font-size: var(--text-sm);
  font-weight: 600;
}

.field .hint {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

/* Checkbox row with a title and an explanation (used by the share dialog). */
.check-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px var(--space-3);
  align-items: start;
  cursor: pointer;
}
.check-row input {
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
  accent-color: var(--color-primary);
  cursor: pointer;
}
.check-row b {
  font-weight: 600;
}
.check-row small {
  grid-column: 2;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* Read-only value with a copy button next to it. */
.copy-row {
  display: flex;
  gap: var(--space-2);
}
.copy-row input {
  flex: 1;
  min-width: 0;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* --------------------------------------------------------------------------
   Status labels
   -------------------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}
.badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-border-strong);
}
.badge.public {
  color: var(--color-primary);
}
.badge.public::before {
  background: var(--color-primary);
}

/* --------------------------------------------------------------------------
   Menus
   -------------------------------------------------------------------------- */
.menu-wrap {
  position: relative;
}

.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 1100;
  min-width: 200px;
  padding: 4px;
  display: grid;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
}

.menu button,
.menu a {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  text-align: left;
  padding: 0.45rem 0.65rem;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  color: var(--color-text);
  text-decoration: none;
  background: transparent;
}
.menu button:hover,
.menu a:hover {
  background: var(--color-surface-offset);
}
.menu button.danger {
  color: var(--color-danger);
}
.menu hr {
  border: 0;
  border-top: 1px solid var(--color-border);
  margin: 4px 0;
}
.menu .menu-head {
  padding: 0.4rem 0.65rem;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  word-break: break-word;
}
.menu svg {
  width: 16px;
  height: 16px;
  flex: none;
  color: var(--color-text-muted);
}

/* --------------------------------------------------------------------------
   Dialogs
   -------------------------------------------------------------------------- */
.modal-back {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: var(--space-4);
  background: var(--scrim);
}

.modal {
  position: relative;
  width: 100%;
  max-width: 440px;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  padding: var(--space-6);
  display: grid;
  gap: var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-pop);
}
.modal > * {
  min-width: 0;
}
.modal h2 {
  font-size: var(--text-lg);
  padding-right: var(--space-7);
}
.modal p {
  overflow-wrap: anywhere;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  color: var(--color-text-muted);
  font-size: 1rem;
  line-height: 1;
}
.modal-close:hover {
  background: var(--color-surface-offset);
  color: var(--color-text);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-1);
}

/* --------------------------------------------------------------------------
   Two-way switch (sign in / create account)
   -------------------------------------------------------------------------- */
.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg);
}

.segmented button {
  padding: 0.35rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-muted);
}
.segmented button:hover {
  color: var(--color-text);
}
.segmented button[aria-selected="true"],
.segmented button.active {
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: 0 0 0 1px var(--color-border);
}

/* --------------------------------------------------------------------------
   Toast
   -------------------------------------------------------------------------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 3000;
  transform: translate(-50%, 8px);
  max-width: min(92vw, 440px);
  padding: 0.6rem 1rem;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--color-bg);
  background: var(--color-text);
  box-shadow: var(--shadow-pop);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}
#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
#toast[data-tone="error"] {
  background: var(--color-danger);
  color: #fff;
}

/* --------------------------------------------------------------------------
   Helpers
   -------------------------------------------------------------------------- */
.stack {
  display: grid;
  gap: var(--space-4);
}
.stack > *,
.field > * {
  min-width: 0;
}
.row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.spacer {
  flex: 1;
}
.muted {
  color: var(--color-text-muted);
}
.error-text {
  color: var(--color-danger);
  font-size: var(--text-sm);
}
.error-text:empty {
  display: none;
}

.skeleton {
  background: var(--color-surface-offset);
  border-radius: var(--radius-sm);
}

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