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

:root {
  --bg: #0d0d0d;
  --surface: #1a1a1a;
  --surface2: #282828;
  --primary: #1db954;
  --primary-hover: #1ed760;
  --primary-disabled: #535353;
  --text: #ffffff;
  --text-muted: #a0a0a0;
  --text-dim: #999999;
  --danger: #e74c3c;
  --border: #333;
  --border2: #444;
  --scanner-bg: #000;
}

[data-theme="light"] {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --surface2: #efefef;
  --text: #111111;
  --text-muted: #666666;
  --text-dim: #767676;
  --border: #ddd;
  --border2: #ccc;
  --scanner-bg: #222;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  transition: background 0.3s, color 0.3s;
}

/* Screen topbar (Login, Ready, Playlist) */
.screen-topbar {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 540px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
}

.back-link {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  line-height: 1;
  margin: 0;
}
.back-link:hover { color: var(--text); }
.back-link svg { flex-shrink: 0; }

/* Theme toggle button */
.btn-theme {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--text-muted);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.5;
  transition: opacity 0.2s;
}

.btn-theme:hover,
.btn-theme:active {
  opacity: 1;
}

.btn-theme::after {
  content: "\263C";
}

[data-theme="light"] .btn-theme::after {
  content: "\263E";
}

#scanner-header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

#app {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Screens */
.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 2rem;
  position: relative;
}

.screen.active {
  display: flex;
}

/* Login / Ready Screen */
#screen-login h1,
#screen-ready h1 {
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 0.25rem;
}

.subtitle {
  color: var(--text-muted);
  font-size: 1.05rem;
  margin-bottom: 1.5rem;
}

/* Feature list */
.feature-list {
  width: 100%;
  max-width: 360px;
  margin-bottom: 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.feature-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

.feature-icon {
  font-size: 1.1rem;
  line-height: 1.4;
  flex-shrink: 0;
  width: 1.5rem;
  text-align: center;
  color: var(--primary);
}

.feature-item div {
  display: flex;
  flex-direction: column;
}

.feature-item strong {
  font-size: 0.9rem;
  color: var(--text);
}

.feature-item span {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Link card (playlist) */
.link-card {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  margin-top: 1.25rem;
  text-decoration: none;
  transition: border-color 0.2s;
}

.link-card:hover {
  border-color: var(--primary);
}

.link-card strong {
  font-size: 0.9rem;
  color: var(--primary);
}

.link-card span {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Small hint text */
.hint {
  margin-top: 1.25rem;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.info-box {
  background: var(--surface);
  border-radius: 12px;
  padding: 1.5rem;
  width: 100%;
  max-width: 360px;
  margin-bottom: 2rem;
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.info-box p {
  margin-bottom: 0.5rem;
  color: var(--text);
  font-weight: 500;
}

.btn-primary {
  background: var(--primary);
  color: var(--bg);
  border: none;
  padding: 1rem 3rem;
  border-radius: 50px;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s;
  width: 100%;
  max-width: 360px;
}

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

.btn-primary:disabled {
  background: var(--primary-disabled);
  cursor: not-allowed;
}

/* Scanner Screen */
#screen-scanner {
  justify-content: flex-start;
  padding: 0;
}

#scanner-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  width: 100%;
  max-width: 540px;
  margin: 0 auto;
}

#scanner-header h2 {
  font-size: 1.3rem;
  font-weight: 700;
}

#status-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

#status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

#status-dot.playing {
  background: var(--primary);
  box-shadow: 0 0 8px var(--primary);
  animation: pulse 1.5s infinite;
}

#status-dot.error {
  background: var(--danger);
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

#scanner-container {
  position: relative;
  width: 100%;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--scanner-bg);
}

#reader {
  width: 100%;
  height: 100%;
}

#reader video {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
}

/* Hide the built-in scan region styling */
#reader__scan_region {
  min-height: 0 !important;
}

#reader__scan_region img,
#reader__dashboard_section,
#reader__dashboard_section_csr,
#reader__dashboard_section_swaplink,
#reader__header_message,
#reader img[alt="Info icon"] {
  display: none !important;
}

#scanner-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 220px;
  height: 220px;
  pointer-events: none;
}

.corner {
  position: absolute;
  width: 30px;
  height: 30px;
  border-color: var(--primary);
  border-style: solid;
  border-width: 0;
}

.corner.tl {
  top: 0;
  left: 0;
  border-top-width: 3px;
  border-left-width: 3px;
  border-top-left-radius: 8px;
}

.corner.tr {
  top: 0;
  right: 0;
  border-top-width: 3px;
  border-right-width: 3px;
  border-top-right-radius: 8px;
}

.corner.bl {
  bottom: 0;
  left: 0;
  border-bottom-width: 3px;
  border-left-width: 3px;
  border-bottom-left-radius: 8px;
}

.corner.br {
  bottom: 0;
  right: 0;
  border-bottom-width: 3px;
  border-right-width: 3px;
  border-bottom-right-radius: 8px;
}

/* Playback overlay */
#playback-overlay {
  position: absolute;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  z-index: 10;
}

#playback-overlay.hidden {
  display: none;
}

.play-big-wrap {
  position: relative;
  width: 100px;
  height: 100px;
}

.play-big {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: var(--bg);
  font-size: 2.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, background 0.2s;
  position: relative;
  z-index: 2;
}

.play-big:hover {
  transform: scale(1.08);
  background: var(--primary-hover);
}

.play-big.paused {
  background: var(--surface);
  border: 2px solid var(--border);
  color: var(--text);
}

#pulse-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100px;
  height: 100px;
  border-radius: 50%;
  border: 2px solid var(--primary);
  animation: pulse-ring 2s ease-out infinite;
  z-index: 1;
}

#pulse-ring.hidden {
  display: none;
}

@keyframes pulse-ring {
  0% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 0.6;
  }
  100% {
    transform: translate(-50%, -50%) scale(1.8);
    opacity: 0;
  }
}

#playback-label {
  color: var(--text-muted);
  font-size: 0.9rem;
  z-index: 2;
}

/* Controls */
#controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.5rem 1.5rem;
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
}

#controls-row {
  display: flex;
  gap: 0.75rem;
  width: 100%;
}

#controls-row .btn-control {
  flex: 1;
  justify-content: center;
}

/* Scan button */
.btn-scan {
  width: 100%;
  background: var(--surface);
  color: var(--primary);
  border: 1px solid var(--primary);
  padding: 0.8rem 1.8rem;
  border-radius: 50px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-scan:hover {
  background: rgba(29, 185, 84, 0.1);
}

.btn-control {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.8rem 1.8rem;
  border-radius: 50px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.2s;
}

.btn-control:hover:not(:disabled) {
  background: var(--surface2);
  border-color: var(--border2);
}

.btn-control:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-control.active {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-control .icon {
  font-size: 1.1rem;
}

/* Message bar */
#message-bar {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  border-radius: 12px;
  font-size: 0.9rem;
  color: var(--text-muted);
  transition: opacity 0.3s;
  max-width: 90%;
  text-align: center;
  z-index: 100;
}

#message-bar.hidden {
  opacity: 0;
  pointer-events: none;
}

#message-bar.error {
  border-color: var(--danger);
  color: var(--danger);
}

/* Responsive */
@media (min-width: 600px) {
  #scanner-container {
    max-width: 500px;
    margin: 0 auto;
    border-radius: 12px;
  }
}

/* Dev bypass button */
.btn-dev {
  margin-top: 1rem;
  background: transparent;
  border: 1px dashed var(--text-dim);
  color: var(--text-dim);
  padding: 0.6rem 1.5rem;
  border-radius: 50px;
  font-size: 0.8rem;
  cursor: pointer;
  width: 100%;
  max-width: 360px;
}

.btn-dev:hover {
  border-color: var(--text-muted);
  color: var(--text-muted);
}
