:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --panel: #14171c;
  --border: #262b33;
  --text: #e7e9ec;
  --muted: #8a9099;
  --accent: #4da3ff;
  --busy: #ff6b6b;
  --free: #3ddc84;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.75rem;
  letter-spacing: -0.02em;
}

.hint {
  margin: 0 0 1.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.state {
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 1.5rem;
}

.state[data-state="connected"] { color: var(--free); }
.state[data-state="streaming"] { color: var(--accent); }
.state[data-state="error"],
.state[data-state="disconnected"] { color: var(--busy); }

#key-form {
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
}

#key-form h2 {
  font-size: 1rem;
  color: var(--text);
  margin: 0 0 0.25rem;
}

#key-form .note {
  margin-top: 0;
  margin-bottom: 0.75rem;
}

#key-form-el {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

#key-input {
  flex: 1 1 12rem;
  min-width: 0;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
}

#key-input:focus {
  outline: none;
  border-color: var(--accent);
}

#key-save-btn {
  background: var(--accent);
  color: #04101d;
  border: none;
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

#stats h2 {
  font-size: 1rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 0.5rem;
}

#code-form {
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
}

#code-form h2 {
  font-size: 1rem;
  color: var(--text);
  margin: 0 0 0.75rem;
}

#code-form-el {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

#code-input {
  flex: 1 1 10rem;
  min-width: 0;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: 0.3em;
  text-align: center;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}

#code-input:focus {
  outline: none;
  border-color: var(--accent);
}

#connect-btn {
  background: var(--accent);
  color: #04101d;
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1.1rem;
  font-weight: 600;
  cursor: pointer;
}

#connect-btn:disabled {
  background: var(--border);
  color: var(--muted);
  cursor: not-allowed;
}

.note.error {
  color: var(--busy);
}

#code-form.shake {
  animation: code-form-shake 0.3s;
}

@keyframes code-form-shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}

#casting-header {
  margin-bottom: 1.5rem;
  padding: 0.75rem 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
}

#casting-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text);
}

#casting-tv-name {
  font-weight: 700;
  color: var(--accent);
}

#controls {
  margin-bottom: 1.5rem;
}

#stop-btn {
  background: var(--busy);
  color: #200606;
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1.1rem;
  font-weight: 600;
  cursor: pointer;
}

.note {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0.5rem 0 0;
}

#stats dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  margin: 0;
  font-variant-numeric: tabular-nums;
}

#stats dt {
  color: var(--muted);
}

#stats dd {
  margin: 0;
}
