/* Swarpeti — design tokens, page layout, buttons and pills. The other files in
 * styles/ follow in the order index.html links them; later ones may override.
 *
 * Every colour comes from a CSS variable written by src/themes.js, so this
 * file never hard-codes a theme. `data-finish` on <html> switches the surface
 * treatment (FINISHES in src/themes.js lists them).
 */

:root {
  /* Fallbacks for the instant before the theme loads (Classic Harmonium). */
  --bg-page: #20120a;
  --case-1: #583723;
  --case-2: #382011;
  --surface: #331d10;
  --well: #25150b;
  --border: #6d4a31;
  --text: #f8f2e7;
  --text-dim: #cdb9a4;
  --accent: #d4a22e;
  --accent-fg: #d4a22e;
  --accent-ink: #1a1410;
  --accent-soft: rgba(212, 162, 46, 0.18);
  --glow: rgba(212, 162, 46, 0.55);
  --key-white-1: #f7efde;
  --key-white-2: #dcd3c0;
  --key-white-edge: #8f8878;
  --key-white-ink: #1a1410;
  --key-white-press: #e7c57a;
  --key-white-press-ink: #1a1410;
  --key-black-1: #4a3f38;
  --key-black-2: #1c120c;
  --key-black-edge: #0a0503;
  --key-black-ink: #f8f2e7;
  --key-black-press: #a8801f;
  --key-black-press-ink: #1a1410;
  --font-display: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

/* Hold the page back until the saved theme is applied, so it never flashes the
   wrong colours. The animation is a safety net if scripts fail to run. */
html:not([data-ready]) body {
  opacity: 0;
  animation: reveal 0s 1.5s forwards;
}

@keyframes reveal {
  to { opacity: 1; }
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(120% 80% at 50% 0%, color-mix(in srgb, var(--case-1) 38%, var(--bg-page)), var(--bg-page) 70%);
  background-color: var(--bg-page);
  color: var(--text);
  font: 15px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p, ol, ul {
  margin: 0;
}

button {
  font: inherit;
  color: inherit;
}

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

kbd {
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--well);
  font: 0.8em var(--font-ui);
}

.hint {
  font-size: 0.78rem;
  color: var(--text-dim);
}

/* ------------------------------------------------------------------ *
 * Layout
 * ------------------------------------------------------------------ */

.app {
  width: min(1180px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-right: auto;
}

.brand h1 {
  font: 600 1.45rem/1 var(--font-display);
  letter-spacing: 0.04em;
}

.brand-mark {
  width: 32px;
  height: 32px;
}
.mark-case { fill: var(--case-1); stroke: var(--border); stroke-width: 1; }
.mark-key { fill: var(--key-white-1); }
.mark-black { fill: var(--key-black-2); }
.mark-knob { fill: var(--accent); }

.topbar-actions {
  display: flex;
  gap: 8px;
}

/* ---- buttons ---- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.btn:hover {
  border-color: var(--accent-fg);
}

.btn svg,
.icon-btn svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn-primary {
  padding: 11px 26px;
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  font-size: 1rem;
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.icon-btn:hover {
  border-color: var(--border);
}

/* ---- status pills ---- */

.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.78rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  opacity: 0.6;
}

.pill[data-state='ready'] .dot,
.pill[data-state='connected'] .dot {
  background: var(--accent);
  opacity: 1;
  box-shadow: 0 0 8px var(--glow);
}

.pill[data-state='loading'] .dot,
.pill[data-state='connecting'] .dot {
  background: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}

.pill[data-state='error'] .dot,
.pill[data-state='offline'] .dot,
.pill[data-state='no-sensor'] .dot {
  background: #e5604d;
  opacity: 1;
}

@keyframes pulse {
  50% { opacity: 0.25; }
}
