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

:root {
  --bg: #f5f5f5;
  --bg2: #ffffff;
  --text: #1a1a1a;
  --text2: #555555;
  --btn: #2563eb;
  --btn-text: #ffffff;
  --btn-hover: #1d4ed8;
  --border: #d1d5db;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a1a;
    --bg2: #2a2a2a;
    --text: #f0f0f0;
    --text2: #a0a0a0;
    --btn: #2563eb;
    --btn-text: #ffffff;
    --btn-hover: #1d4ed8;
    --border: #3f3f3f;
    --shadow: 0 1px 3px rgba(0,0,0,0.4);
  }
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  min-height: 100vh;
}

/* ── Login ────────────────────────────────────────────────────────── */

.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px 32px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.login-card h1 {
  font-size: 1.4rem;
  font-weight: 600;
  text-align: center;
}

.login-card label {
  font-size: 0.9rem;
  color: var(--text2);
  display: block;
  margin-bottom: 6px;
}

.login-card input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 1.1rem;
  outline: none;
}

.login-card input:focus { border-color: var(--btn); }

.error-msg {
  color: #dc2626;
  font-size: 0.85rem;
  text-align: center;
  min-height: 1.2em;
}

/* ── Buttons ──────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--btn);
  color: var(--btn-text);
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  padding: 12px 20px;
  min-height: 48px;
  transition: background 0.15s, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.btn:hover:not(:disabled) { background: var(--btn-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-full { width: 100%; }

/* ── App layout ───────────────────────────────────────────────────── */

.app-wrap {
  max-width: 800px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.section {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text2);
}

/* ── Device bar ───────────────────────────────────────────────────── */

.device-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.device-bar .label {
  font-size: 0.9rem;
  color: var(--text2);
  white-space: nowrap;
}

.device-btn {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.device-btn.active {
  background: var(--btn);
  color: var(--btn-text);
  border-color: var(--btn);
}

.device-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.device-text { font-size: 0.95rem; }

/* ── Preset grid ──────────────────────────────────────────────────── */

.preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}

.preset-btn {
  min-height: 80px;
  font-size: 0.95rem;
  font-weight: 500;
  padding: 12px;
  text-align: center;
  word-break: break-word;
}

/* ── Search row ───────────────────────────────────────────────────── */

.search-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.search-row input {
  flex: 1;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  min-width: 0;
}

.search-row input:focus { border-color: var(--btn); }

/* ── Playback controls ────────────────────────────────────────────── */

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

.playback-row .btn {
  flex: 1;
  min-width: 72px;
  min-height: 56px;
}

/* ── Admin specific ───────────────────────────────────────────────── */

.state-bar {
  font-size: 0.85rem;
  color: var(--text2);
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
}

.state-bar span { white-space: nowrap; }
.state-val { color: var(--text); font-weight: 500; }

.input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.input-row input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  min-width: 0;
}

.input-row input:focus { border-color: var(--btn); }

.input-row input[type="number"] { width: 88px; flex: none; }
.input-row .btn { padding: 12px 24px; flex: none; }

.queue-list, .history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--text2);
}

.queue-list li:not(.empty-msg), .history-list li:not(.empty-msg) { padding-left: 1.4em; text-indent: -1.4em; }
.queue-list li:not(.empty-msg)::before { content: attr(data-pos) ". "; font-weight: 600; color: var(--text); }
.history-list li:not(.empty-msg)::before { content: "• "; }

.queue-list a, .history-list a {
  color: var(--btn);
  text-decoration: none;
  word-break: break-all;
}

.empty-msg { font-size: 0.85rem; color: var(--text2); }

.active-device-heading {
  font-size: 1.1rem;
  font-weight: 600;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 480px) {
  .two-col { grid-template-columns: 1fr; }
}
