/* ── Reset & base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #0d0d0f;
  --surface:  #18181c;
  --card:     #22222a;
  --border:   #2e2e3a;
  --text:     #f0f0f5;
  --muted:    #888899;
  --cyan:     #00d4ff;
  --magenta:  #e91e8c;
  --gold:     #f5c842;
  --green:    #34c759;
  --amber:    #ff9f0a;
  --red:      #ff453a;
  --radius:   10px;
}

html, body {
  width: 100%; height: 100%;
  background: #000;
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ── Screens ───────────────────────────────────────────────────────────────── */
.screen {
  position: fixed; inset: 0;
  display: none;
}
.screen.active { display: flex; flex-direction: column; }

/* ── Mode select ───────────────────────────────────────────────────────────── */
#screen-mode-select {
  background: var(--bg);
  align-items: center;
  justify-content: center;
  overflow-y: auto;
}

.mode-select-wrap {
  display: flex; flex-direction: column;
  align-items: center; text-align: center;
  padding: 40px 24px;
  max-width: 600px;
  width: 100%;
}

.mode-logo { width: 660px; height: 384px; max-width: 90vw; object-fit: contain; margin-bottom: 32px; }

.mode-title {
  font-size: 36px; font-weight: 900; color: var(--text); margin-bottom: 6px;
}
.mode-title span { color: var(--cyan); }

.mode-tagline {
  font-size: 14px; color: var(--muted); margin-bottom: 36px;
}

.mode-cards {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
  width: 100%; margin-bottom: 20px;
}

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

.mode-card {
  background: var(--card); border: 1.5px solid var(--border);
  border-radius: var(--radius); padding: 24px 16px;
  cursor: pointer; transition: border-color .15s, background .15s;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  color: var(--text);
}
.mode-card:hover { border-color: var(--cyan); background: rgba(0,212,255,.06); }

.mode-icon { font-size: 40px; }
.mode-card-title { font-size: 16px; font-weight: 700; }
.mode-card-desc { font-size: 12px; color: var(--muted); line-height: 1.5; }

.mode-note { font-size: 11px; color: var(--muted); }

/* ── Frame mode / slideshow ─────────────────────────────────────────────────── */
#screen-frame { background: #000; }

#slideshow-container {
  position: relative; width: 100%; height: 100%;
  background: #000; overflow: hidden;
}

.slide {
  position: absolute; inset: 0;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  transition: opacity .8s ease;
}
.slide.hidden { opacity: 0; pointer-events: none; }

#slide-video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain;
}
#slide-video.hidden { display: none; }

#frame-overlay {
  position: absolute; inset: 0;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  pointer-events: none; z-index: 10;
}
#frame-overlay.hidden { display: none; }

/* Empty state */
#empty-state {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px; z-index: 5;
}
.empty-icon { font-size: 64px; opacity: .3; }
.empty-title { font-size: 20px; color: var(--muted); }
.empty-sub { font-size: 13px; color: var(--muted); opacity: .7; text-align: center; line-height: 1.6; max-width: 300px; }

/* HUD */
#hud {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  justify-content: space-between;
  pointer-events: none; z-index: 20;
  opacity: 0; transition: opacity .25s;
}
#hud.visible { opacity: 1; }

#hud-top, #hud-bottom {
  display: flex; align-items: center;
  padding: 14px 16px;
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(4px);
}
#hud-top { justify-content: space-between; gap: 10px; }
#hud-bottom { justify-content: center; font-size: 11px; color: rgba(255,255,255,.5); }

#hud-name { font-size: 14px; color: #fff; flex: 1; }
#hud-paused {
  font-size: 11px; font-weight: 700; color: #000;
  background: #fff; padding: 2px 8px; border-radius: 4px;
}
#hud-paused.hidden { display: none; }
#hud-index { font-size: 12px; color: rgba(255,255,255,.6); }

/* Settings gear */
#btn-open-settings {
  position: absolute; bottom: 16px; right: 16px;
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(0,0,0,.5); border: 1px solid rgba(255,255,255,.2);
  color: rgba(255,255,255,.7); font-size: 20px;
  cursor: pointer; z-index: 25;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
#btn-open-settings:hover { background: rgba(0,0,0,.8); }

/* ── Settings panel ─────────────────────────────────────────────────────────── */
.panel {
  position: fixed; inset: 0;
  background: var(--bg); z-index: 100;
  display: flex; flex-direction: column;
  transform: translateY(100%);
  transition: transform .28s cubic-bezier(.32,0,.67,0);
}
.panel.visible { transform: translateY(0); }
.panel.hidden { display: none; }

.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 0;
  background: var(--surface);
  border-bottom: .5px solid var(--border);
  padding-bottom: 12px;
}
.panel-title { font-size: 16px; font-weight: 600; }
.panel-close {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--card); border: .5px solid var(--border);
  color: var(--muted); cursor: pointer; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}

.panel-tabs {
  display: flex; overflow-x: auto; gap: 2px;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: .5px solid var(--border);
  scrollbar-width: none;
}
.panel-tabs::-webkit-scrollbar { display: none; }

.ptab {
  flex-shrink: 0; padding: 6px 12px;
  border-radius: 7px; border: none;
  background: transparent; color: var(--muted);
  cursor: pointer; font-size: 13px; white-space: nowrap;
  transition: all .15s;
}
.ptab.active { background: var(--card); color: var(--text); border: .5px solid var(--border); }

.panel-body { flex: 1; overflow-y: auto; padding: 16px; }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Settings controls ──────────────────────────────────────────────────────── */
.setting-section {
  font-size: 11px; color: var(--muted); letter-spacing: .08em;
  text-transform: uppercase; margin: 16px 0 8px;
}
.setting-section:first-child { margin-top: 0; }

.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 0;
  border-bottom: .5px solid var(--border);
}
.setting-row:last-child { border-bottom: none; }

.setting-label { font-size: 14px; color: var(--text); flex: 1; }
.setting-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

.setting-note {
  font-size: 11px; color: var(--amber);
  background: rgba(255,159,10,.08);
  border: .5px solid rgba(255,159,10,.2);
  border-radius: 7px; padding: 8px 10px; margin: 8px 0;
}

select, .time-input {
  background: var(--card); border: .5px solid var(--border);
  border-radius: 7px; color: var(--text); padding: 6px 10px;
  font-size: 13px; font-family: inherit; cursor: pointer;
}

input[type="range"] {
  flex: 1; accent-color: var(--cyan); cursor: pointer;
}

.text-input {
  background: var(--card); border: .5px solid var(--border);
  border-radius: 7px; color: var(--text); padding: 8px 10px;
  font-size: 13px; font-family: inherit; flex: 1;
  outline: none;
}
.text-input:focus { border-color: var(--cyan); }

/* Toggle switch */
.toggle { position: relative; width: 40px; height: 22px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle span {
  position: absolute; inset: 0; border-radius: 11px;
  background: var(--border); cursor: pointer;
  transition: background .2s;
}
.toggle span::after {
  content: ''; position: absolute;
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff; top: 2px; left: 2px;
  transition: left .2s;
}
.toggle input:checked + span { background: var(--cyan); }
.toggle input:checked + span::after { left: 20px; }

/* Buttons */
.btn-sm {
  padding: 7px 13px; border-radius: 7px; font-size: 12px;
  border: .5px solid var(--border); background: var(--card);
  color: var(--text); cursor: pointer; font-family: inherit;
  transition: all .15s; flex-shrink: 0;
}
.btn-sm:hover { border-color: var(--cyan); }
.btn-sm.btn-primary { background: var(--cyan); color: #000; border-color: var(--cyan); font-weight: 600; }
.btn-sm.btn-danger { border-color: var(--red); color: var(--red); }
.btn-full {
  width: 100%; padding: 10px; border-radius: 8px;
  border: .5px solid var(--border); background: var(--card);
  color: var(--text); cursor: pointer; font-size: 13px; font-family: inherit;
  text-align: left;
}

/* ── Photo sources ──────────────────────────────────────────────────────────── */
.photo-sources {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 8px; margin-bottom: 10px;
}
.source-btn {
  padding: 12px 8px; text-align: center;
  background: var(--card); border: .5px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  cursor: pointer; font-size: 13px; display: block;
  transition: border-color .15s;
}
.source-btn:hover { border-color: var(--cyan); }

/* ── Photo grid ─────────────────────────────────────────────────────────────── */
.photo-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 6px; margin-bottom: 10px;
}
.companion-grid { grid-template-columns: repeat(3, 1fr); }

@media (max-width: 400px) {
  .photo-grid { grid-template-columns: repeat(3, 1fr); }
  .companion-grid { grid-template-columns: repeat(2, 1fr); }
}

.photo-thumb {
  aspect-ratio: 1; border-radius: 7px;
  background: var(--card); border: 1.5px solid var(--border);
  cursor: pointer; position: relative; overflow: hidden;
  transition: border-color .12s;
}
.photo-thumb img {
  width: 100%; height: 100%; object-fit: cover;
  display: block;
}
.photo-thumb.excluded { opacity: .4; }
.photo-thumb.selected { border-color: var(--cyan); }
.photo-thumb .check {
  position: absolute; bottom: 3px; right: 3px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--cyan); color: #000;
  font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.photo-thumb .del-btn {
  position: absolute; top: 3px; right: 3px;
  width: 20px; height: 20px; border-radius: 50%;
  background: rgba(0,0,0,.6); border: none; color: #fff;
  font-size: 12px; cursor: pointer; display: none;
  align-items: center; justify-content: center;
}
.photo-thumb:hover .del-btn { display: flex; }

.photo-grid-actions { display: flex; gap: 8px; margin-bottom: 12px; }

/* ── Progress bar ───────────────────────────────────────────────────────────── */
.progress-bar {
  height: 6px; background: var(--border); border-radius: 3px;
  margin-bottom: 6px; overflow: hidden;
}
.progress-bar div {
  height: 100%; background: var(--cyan); border-radius: 3px;
  width: 0%; transition: width .3s;
}

/* ── Frame picker ───────────────────────────────────────────────────────────── */
.frame-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;
}
.frame-item {
  border: 1.5px solid var(--border); border-radius: var(--radius);
  padding: 10px; cursor: pointer; text-align: center;
  background: var(--card); transition: border-color .15s; position: relative;
}
.frame-item:hover { border-color: var(--cyan); }
.frame-item.active { border-color: var(--cyan); background: rgba(0,212,255,.07); }
.frame-item.active::after {
  content: '✓'; position: absolute; top: 5px; right: 8px;
  color: var(--cyan); font-size: 12px; font-weight: 700;
}
.frame-preview {
  height: 50px; border-radius: 6px; margin-bottom: 6px;
  background-size: contain; background-repeat: no-repeat; background-position: center;
}
.frame-item-name { font-size: 11px; color: var(--text); }

/* ── Transition picker ──────────────────────────────────────────────────────── */
.transition-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}
.trans-btn {
  padding: 10px; border-radius: 8px;
  border: 1.5px solid var(--border); background: var(--card);
  color: var(--muted); cursor: pointer; font-size: 12px;
  transition: all .15s;
}
.trans-btn.active { border-color: var(--cyan); color: var(--text); }

/* ── About ──────────────────────────────────────────────────────────────────── */
.about-logo-row {
  display: flex; align-items: center; gap: 12px; margin-bottom: 14px;
}
.about-aa-logo { width: 40px; height: 40px; object-fit: contain; }
.about-app-name { font-size: 15px; font-weight: 600; }
.about-tagline { font-size: 11px; color: var(--muted); }
.about-blurb { font-size: 13px; color: var(--muted); line-height: 1.65; margin-bottom: 12px; }
.about-link { color: var(--cyan); font-size: 13px; display: block; margin-bottom: 8px; }
.tos-box { font-size: 12px; color: var(--muted); line-height: 1.6; }
.tos-box p { margin-bottom: 8px; }
.tos-box strong { color: var(--text); }
.tos-box a { color: var(--cyan); }
.about-version { font-size: 11px; color: var(--muted); margin-top: 16px; }

/* ── Overlays ───────────────────────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0; background: var(--bg); z-index: 200;
  display: flex; flex-direction: column;
}
.overlay.hidden { display: none; }

.overlay-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  background: var(--surface); border-bottom: .5px solid var(--border);
  font-size: 14px; font-weight: 500;
}
.overlay-back {
  background: none; border: none; color: var(--cyan);
  font-size: 18px; cursor: pointer; padding: 0 4px;
}
.overlay-body { flex: 1; overflow-y: auto; padding: 20px 16px; }

/* ── Companion mode ─────────────────────────────────────────────────────────── */
#screen-companion {
  background: var(--bg); overflow: hidden;
}

#companion-frame-list, #companion-frame-detail {
  display: flex; flex-direction: column;
  height: 100%; overflow-y: auto;
}
#companion-frame-detail.hidden { display: none; }
#companion-frame-list.hidden { display: none; }

.companion-header {
  display: flex; align-items: center; gap: 12px;
  padding: 16px;
  background: var(--surface); border-bottom: .5px solid var(--border);
  flex-shrink: 0;
}
.companion-title { font-size: 18px; font-weight: 700; }
.companion-title span { color: var(--cyan); }
.companion-sub { font-size: 12px; color: var(--muted); }

.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--card); border: .5px solid var(--border);
  color: var(--text); cursor: pointer; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
}

.discovery-status {
  font-size: 12px; color: var(--muted);
  padding: 10px 16px;
}

/* Frame card */
.frame-card {
  background: var(--card); border: .5px solid var(--border);
  border-radius: var(--radius); margin: 8px 16px;
  padding: 14px 16px;
}
.frame-card-header {
  display: flex; align-items: center; gap: 12px; margin-bottom: 10px;
}
.frame-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--green); flex-shrink: 0;
}
.frame-dot.offline { background: var(--amber); }
.frame-card-name { font-size: 15px; font-weight: 600; flex: 1; }
.frame-card-sub { font-size: 11px; color: var(--muted); }
.frame-card-actions { display: flex; gap: 8px; }

/* Offline frame card */
.frame-card.offline-card { border-color: rgba(255,159,10,.3); }
.offline-badge {
  font-size: 10px; font-weight: 700; color: var(--cyan);
  background: rgba(0,212,255,.1); padding: 2px 7px;
  border-radius: 4px; border: .5px solid rgba(0,212,255,.3);
}

.companion-footer {
  padding: 16px; border-top: .5px solid var(--border);
  display: flex; justify-content: center; flex-shrink: 0;
}

.detail-actions {
  display: flex; gap: 8px; padding: 12px 16px;
  border-top: .5px solid var(--border); flex-shrink: 0;
}

/* ── Hang guide content ─────────────────────────────────────────────────────── */
.hang-step {
  display: flex; gap: 14px; margin-bottom: 18px;
}
.hang-num {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  background: rgba(0,212,255,.15); color: var(--cyan);
  font-size: 13px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.hang-content h4 { font-size: 14px; margin-bottom: 4px; }
.hang-content p { font-size: 12px; color: var(--muted); line-height: 1.6; }
.hang-content a { color: var(--cyan); }

/* ── Scrollbar ──────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Utility ────────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
