/* Tokens, reset, and shared components (buttons, inputs, menus, toasts). */

:root {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --surface-2: #f6f6f9;
  --text: #1c1c1e;
  --muted: #6c6c72;
  --line: #dedee3;
  --accent: #7a4cf0;
  --accent-ink: #ffffff;
  --accent-soft: #efe9fe;
  --danger: #d70015;
  --danger-soft: #fdecee;
  --ok: #1f8a3a;
  --warn-bg: #fff6e0;
  --warn-ink: #6b4a00;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(0, 0, 0, 0.06);
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --text: #f2f2f7;
    --muted: #9b9ba1;
    --line: #38383c;
    --accent: #a487ff;
    --accent-ink: #12002e;
    --accent-soft: #2a2140;
    --danger: #ff6961;
    --danger-soft: #3a1a1a;
    --ok: #30d158;
    --warn-bg: #3a2e10;
    --warn-ink: #ffd98a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #000000;
  --surface: #1c1c1e;
  --surface-2: #2c2c2e;
  --text: #f2f2f7;
  --muted: #9b9ba1;
  --line: #38383c;
  --accent: #a487ff;
  --accent-ink: #12002e;
  --accent-soft: #2a2140;
  --danger: #ff6961;
  --danger-soft: #3a1a1a;
  --ok: #30d158;
  --warn-bg: #3a2e10;
  --warn-ink: #ffd98a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* Standby fills the screen: no scrolling, black behind everything (also during overscroll). */
html.in-standby,
html.in-standby body {
  background: #000;
  overflow: hidden;
  overscroll-behavior: none;
  height: 100%;
}

[hidden] {
  display: none !important;
}

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

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

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

h1,
h2,
h3 {
  line-height: 1.2;
  margin: 0 0 0.5em;
}

p {
  margin: 0 0 0.75em;
}

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

.boot {
  position: fixed;
  inset: 0;
  background: #000;
}

.boot-error {
  max-width: 560px;
  margin: 15vh auto;
  padding: 24px;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
}
.center {
  text-align: center;
}
.row {
  display: flex;
  align-items: center;
}
.gap {
  gap: 10px;
}
.wrap {
  flex-wrap: wrap;
}
.row.center {
  justify-content: center;
}
.error-text {
  color: var(--danger);
}

.note {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  background: var(--warn-bg);
  color: var(--warn-ink);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}
.note .icon {
  flex: none;
  margin-top: 2px;
}

kbd {
  font: 600 0.8rem/1 ui-monospace, Menlo, monospace;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 3px 7px;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:hover {
  background: var(--surface-2);
}
.btn:active {
  transform: scale(0.98);
}
.btn:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none;
}
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover {
  background: var(--accent);
  filter: brightness(1.08);
}
.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn-danger:hover {
  background: var(--danger);
  filter: brightness(1.08);
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
}
.btn-ghost:hover {
  background: var(--surface-2);
}
.btn-text {
  background: none;
  border: 0;
  color: var(--accent);
  font-weight: 700;
  cursor: pointer;
  padding: 6px 8px;
  min-height: 36px;
}
.btn-sm {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 0.875rem;
}
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: inherit;
  cursor: pointer;
}
.icon-btn:hover {
  background: var(--surface-2);
}
.icon-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

/* ---- Inputs ---- */
.input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 16px; /* 16px or iOS zooms in on focus */
}
select.input {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 36px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}
.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}
.field .label {
  font-weight: 600;
  font-size: 0.9rem;
}
.field-error {
  color: var(--danger);
  font-size: 0.9rem;
  min-height: 1.2em;
  margin: 0;
}

.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 3px;
  gap: 2px;
  max-width: 100%;
}
.segmented button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 6px 14px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--muted);
}
.segmented button.on {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

/* On/off switch: the checkbox stays in the page (for keyboards and screen readers), drawn as a switch. */
.switch-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  cursor: pointer;
  position: relative;
}
.switch-text {
  flex: 1;
  display: grid;
  gap: 2px;
}
.switch-input {
  position: absolute;
  opacity: 0;
  width: 51px;
  height: 31px;
  right: 0;
  margin: 0;
  cursor: pointer;
}
.switch {
  flex: none;
  width: 51px;
  height: 31px;
  border-radius: 999px;
  background: var(--line);
  position: relative;
  transition: background 0.2s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s;
}
.switch-input:checked + .switch {
  background: #34c759;
}
.switch-input:checked + .switch::after {
  transform: translateX(20px);
}
.switch-input:focus-visible + .switch {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.chip.on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.swatches,
.pn-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid rgba(128, 128, 128, 0.35);
  background: var(--sw, #fff);
  cursor: pointer;
  padding: 0;
  overflow: hidden;
  position: relative;
}
.swatch canvas {
  width: 100%;
  height: 100%;
}
.swatch.on {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.progress {
  width: 100%;
  height: 10px;
  accent-color: var(--accent);
}

.empty {
  text-align: center;
  padding: 48px 16px;
  color: var(--muted);
}
.empty .icon {
  margin: 0 auto 12px;
}
.empty h3 {
  color: var(--text);
}

/* ---- Toasts and menus (in the top layer; see ui.js) ---- */
.toasts {
  position: fixed;
  inset: auto 0 calc(16px + var(--safe-bottom)) 0;
  margin: 0 auto;
  width: min(560px, calc(100% - 32px));
  display: grid;
  gap: 8px;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: visible;
  z-index: 1000;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: 14px;
  background: rgba(30, 30, 32, 0.94);
  color: #fff;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
  pointer-events: auto;
  font-size: 0.95rem;
  animation: toast-in 0.2s ease-out;
  transition: opacity 0.3s, transform 0.3s;
}
.toast span {
  flex: 1;
}
.toast .btn-text {
  color: #c8b6ff;
}
.toast-error {
  background: #8a1a1a;
}
.toast-success {
  background: #1d4d2a;
}
.toast.out {
  opacity: 0;
  transform: translateY(8px);
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

.menu {
  position: fixed;
  margin: 0;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
  overflow: auto;
  z-index: 1001;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 0;
  border-radius: 9px;
  background: none;
  text-align: left;
  cursor: pointer;
}
.menu-item:hover,
.menu-item:focus-visible {
  background: var(--surface-2);
  outline: none;
}
.menu-item.danger {
  color: var(--danger);
}
.menu-item:disabled {
  opacity: 0.4;
}
.menu-label {
  flex: 1;
  display: grid;
}
.menu-sub {
  color: var(--muted);
  font-size: 0.8rem;
}
.menu-sep {
  height: 1px;
  background: var(--line);
  margin: 4px 6px;
}
.menu-heading {
  padding: 6px 10px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.keep-awake-video {
  position: fixed;
  width: 1px;
  height: 1px;
  opacity: 0.01;
  pointer-events: none;
  left: 0;
  top: 0;
}

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