/* ===================== Media Remote — dark theme ===================== */
:root {
  --bg: #0b0d10;
  --surface: #151a20;
  --surface-2: #1c232c;
  --border: #283039;
  --text: #e8edf2;
  --dim: #8b96a3;
  --faint: #5b6570;
  --accent: #3d9bff;
  --accent-ink: #062a4d;
  --danger: #ff5c6a;
  --danger-ink: #3a0a10;
  --warn: #ffb340;
  --ok: #39d98a;
  --radius: 16px;
  --hit: 56px;
  --hit-lg: 72px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --tab-h: 64px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  height: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body {
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

button, input { font: inherit; color: inherit; }

.hidden { display: none !important; }

/* ===================== icons ===================== */
.icon { width: 24px; height: 24px; display: block; flex: none; }
.icon-lg { width: 34px; height: 34px; }
.icon-sm { width: 18px; height: 18px; }

/* ===================== buttons ===================== */
.btn {
  -webkit-appearance: none;
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 14px;
  min-height: var(--hit);
  min-width: var(--hit);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: background-color 80ms linear, transform 80ms linear, border-color 80ms linear;
}
.btn:active { background: #28323e; transform: scale(0.96); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: 0.35; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn-primary:active { background: #2f86e0; }

.btn-block { width: 100%; min-height: var(--hit); }

.btn-sub { font-size: 12px; font-weight: 600; line-height: 1; opacity: 0.9; }

.chip { border-radius: 14px; }
.chip.small { min-height: 44px; min-width: 44px; border-radius: 12px; }
.chip.main { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.danger { color: var(--danger); border-color: #5a2730; }

.pill { border-radius: 999px; min-height: 48px; padding: 8px 18px; }
.pill.accent { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.pill.ghost { background: transparent; }
.pill.danger-ghost { color: var(--danger); border-color: #5a2730; background: transparent; }
.pill.danger { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }

/* ===================== gate (lock / setup) ===================== */
.gate {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 60;
}
.gate-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.gate-logo { align-self: center; border-radius: 22px; }
.gate-title {
  font-size: 24px;
  font-weight: 700;
  margin: 4px 0 8px;
  text-align: center;
  letter-spacing: -0.01em;
}
.gate-label { font-size: 13px; color: var(--dim); margin-top: 6px; }
.gate-card input {
  width: 100%;
  min-height: 52px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 14px;
  padding: 0 16px;
  font-size: 18px;
  letter-spacing: 0.06em;
}
.gate-card input:focus { outline: none; border-color: var(--accent); }
.gate-error { color: var(--danger); font-size: 14px; min-height: 20px; margin: 2px 0 0; }
.gate-hint { color: var(--dim); font-size: 13px; margin: -4px 0 0; }
.gate-hint.ok { color: var(--ok); }

/* ===================== app shell ===================== */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100vh;
}
.views {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(var(--safe-t) + 12px) 14px 14px;
}
.view { animation: viewin 140ms ease; }
@keyframes viewin { from { opacity: 0.4; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* offline greying */
#app.offline .views .card,
#app.offline .primary-row,
#app.offline .secondary-row,
#app.offline .pad-surface,
#app.offline .dpad,
#app.offline .folder-row,
#app.offline .app-list {
  opacity: 0.45;
  filter: grayscale(0.5);
}
#app.offline .status .dot { background: var(--danger); box-shadow: 0 0 0 0 transparent; }

/* ===================== status strip ===================== */
.status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px 14px;
  font-size: 14px;
}
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 0 rgba(57,217,138,0);
  animation: pulse 2s infinite;
  flex: none;
}
.dot.on { background: var(--ok); }
.dot.off { background: var(--danger); animation: none; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(57,217,138,0.5); }
  70% { box-shadow: 0 0 0 6px rgba(57,217,138,0); }
  100% { box-shadow: 0 0 0 0 rgba(57,217,138,0); }
}
.status-name { font-weight: 600; }
.status-ip { color: var(--dim); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-clock { color: var(--dim); font-variant-numeric: tabular-nums; }

/* ===================== cards ===================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}
.card-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--dim); font-weight: 600; }
.card-label.dim { color: var(--faint); }
.card-value { font-size: 14px; color: var(--text); font-variant-numeric: tabular-nums; }

/* ===================== now playing ===================== */
.now-playing { position: relative; }
.np-tag {
  position: absolute; top: 12px; right: 12px;
  font-size: 10px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--warn); border: 1px solid #4a3a17; background: #221c0c;
  padding: 3px 7px; border-radius: 6px;
}
.np-title { font-size: 17px; font-weight: 650; line-height: 1.3; margin-bottom: 3px; padding-right: 56px; }
.np-subrow { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.np-sub { font-size: 13px; color: var(--dim); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.np-rate { font-size: 12px; font-weight: 600; color: var(--accent); background: var(--surface-2); padding: 2px 8px; border-radius: 6px; flex: none; }
.progress {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 22px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  position: relative;
  touch-action: manipulation;
}
.progress::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: 6px; transform: translateY(-50%);
  background: var(--surface-2);
  border-radius: 3px;
}
.progress-fill {
  position: absolute;
  left: 0; top: 50%;
  height: 6px; transform: translateY(-50%);
  width: 0;
  background: var(--accent);
  border-radius: 3px;
  pointer-events: none;
}
.np-times {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
  margin-top: -4px;
}

/* ===================== primary / secondary rows ===================== */
.primary-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin: 4px 0 18px;
}
.big-btn {
  width: var(--hit-lg);
  height: var(--hit-lg);
  border-radius: 50%;
  flex-direction: column;
  gap: 0;
  padding: 0;
}
.big-btn.main {
  width: 84px;
  height: 84px;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 6px 22px rgba(61,155,255,0.35);
}
.big-btn.main:active { background: #2f86e0; }

.secondary-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.secondary-row .chip { width: 100%; }

/* ===================== sliders ===================== */
.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 34px;
  background: transparent;
  margin: 4px 0;
  cursor: pointer;
  touch-action: none;
}
.slider::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 4px;
  background: var(--surface-2);
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  margin-top: -9px;
  box-shadow: 0 1px 5px rgba(0,0,0,0.4);
}
.slider::-moz-range-track { height: 8px; border-radius: 4px; background: var(--surface-2); }
.slider::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); border: 2px solid #fff;
}
.slider:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

.slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.slider-row .slider { flex: 1; }

.toggle-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 14px;
  min-height: 44px;
  padding: 8px 0;
  cursor: pointer;
  text-align: left;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}
.toggle-row .icon { color: var(--dim); transition: transform 120ms linear; }
.toggle-row[aria-expanded="true"] .icon { transform: rotate(180deg); }

.collapsed { display: none; }
.collapsed.open { display: block; }

/* ===================== rows / grids ===================== */
.row { display: flex; align-items: center; gap: 8px; }
.row-between { justify-content: space-between; }
.slider-head { margin-top: 12px; }
.btn-row { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.btn-row .pill { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.tile {
  flex-direction: column;
  gap: 6px;
  min-height: 74px;
  font-size: 13px;
  width: 100%;
}

/* ===================== search ===================== */
.search-row { display: flex; gap: 10px; margin-top: 10px; align-items: center; }
.text-input {
  flex: 1;
  min-height: 52px;
  min-width: 0;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 14px;
  padding: 0 16px;
  font-size: 16px;
  color: var(--text);
}
.text-input:focus { outline: none; border-color: var(--accent); }
.search-row .pill { flex: none; }

/* ===================== view titles ===================== */
.view-title { font-size: 20px; font-weight: 700; margin: 6px 0 2px; }
.view-hint { font-size: 13px; color: var(--dim); margin: 2px 0 14px; }

/* ===================== sites grid ===================== */
.site-group { margin-bottom: 18px; }
.site-group h3 {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--dim); margin: 0 0 10px; font-weight: 600;
}
.site-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.site-tile {
  -webkit-appearance: none;
  appearance: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  min-height: 84px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text);
  cursor: pointer;
  padding: 8px 4px;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.site-tile .site-glyph {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
}
.site-tile .site-name { font-size: 12px; color: var(--text); line-height: 1.15; text-align: center; }
.site-tile:active { background: #28323e; transform: scale(0.95); }
.site-tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ===================== movies ===================== */
.folder-row { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 12px; scrollbar-width: none; }
.folder-row::-webkit-scrollbar { display: none; }
.folder-chip {
  flex: none;
  min-height: 44px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 0 18px;
  cursor: pointer;
  font-size: 14px;
  touch-action: manipulation;
}
.folder-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

.movie-list { display: flex; flex-direction: column; gap: 10px; }
.movie-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  color: var(--text);
  touch-action: manipulation;
}
.movie-item:active { background: var(--surface-2); }
.movie-item .file-icon { color: var(--accent); flex: none; }
.movie-item .m-name { font-size: 14px; font-weight: 550; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.movie-item .m-meta { font-size: 12px; color: var(--dim); flex: none; }

.mpv { border-color: #4a3a17; }
.mpv-title { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.mpv-info .np-times { margin-top: 2px; }
.mpv .secondary-row { margin: 12px 0 0; }
.mpv .btn-row { margin-top: 12px; }

/* ===================== pad ===================== */
.pad-surface {
  position: relative;
  height: 42vh;
  min-height: 220px;
  max-height: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
  touch-action: none;
  overflow: hidden;
  cursor: crosshair;
}
.pad-hint {
  position: absolute;
  bottom: 10px; left: 0; right: 0;
  text-align: center;
  font-size: 12px;
  color: var(--faint);
  pointer-events: none;
}
.pad-surface.dragging { border-color: var(--accent); background: var(--surface-2); }
.pad-surface.scrolling { border-color: var(--warn); }

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 8px;
  width: 210px;
  margin: 10px auto 4px;
}
.dpad-btn { border-radius: 12px; min-height: 56px; }
.dpad-center { background: var(--surface-2); }
#btnPadUp { grid-column: 2; grid-row: 1; }
#btnPadLeft { grid-column: 1; grid-row: 2; }
#btnPadEnter { grid-column: 2; grid-row: 2; }
#btnPadRight { grid-column: 3; grid-row: 2; }
#btnPadDown { grid-column: 2; grid-row: 3; }
.dpad { grid-template-rows: repeat(3, 1fr); }

.app-list { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.app-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  min-height: 56px;
  padding: 8px 14px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  touch-action: manipulation;
}
.app-item:active { background: #28323e; }
.app-item .app-glyph {
  width: 32px; height: 32px; flex: none;
  border-radius: 8px;
  background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  color: var(--accent); font-weight: 700; font-size: 15px;
}
.app-item .a-name { font-size: 14px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===================== screen ===================== */
.shot-wrap {
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  margin: 12px 0;
  background: #000;
}
.shot { display: block; width: 100%; height: auto; min-height: 120px; background: #000; }

/* ===================== tab bar ===================== */
.tabbar {
  display: flex;
  flex: none;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 4px 4px calc(var(--safe-b) + 4px);
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: var(--tab-h);
  background: none;
  border: none;
  color: var(--dim);
  font-size: 11px;
  cursor: pointer;
  border-radius: 12px;
  touch-action: manipulation;
}
.tab .icon { color: var(--dim); }
.tab[aria-selected="true"] { color: var(--accent); }
.tab[aria-selected="true"] .icon { color: var(--accent); }
.tab:active { background: var(--surface-2); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ===================== toast ===================== */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-h) + var(--safe-b) + 20px);
  transform: translateX(-50%) translateY(20px);
  background: #202731;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease, transform 140ms ease;
  z-index: 80;
  max-width: 88vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===================== sheets & dialogs ===================== */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 70;
}
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--border);
  padding: 16px 16px calc(var(--safe-b) + 16px);
  z-index: 71;
  max-height: 82vh;
  overflow-y: auto;
  animation: sheetin 180ms ease;
}
@keyframes sheetin { from { transform: translateY(40px); opacity: 0.4; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.sheet-title { font-size: 18px; font-weight: 700; margin: 0; }
.sheet-warn { font-size: 13px; color: var(--warn); margin: 4px 0 14px; line-height: 1.4; }
.sheet-list { display: flex; flex-direction: column; gap: 10px; }
.list-item { width: 100%; justify-content: flex-start; font-size: 16px; min-height: 56px; }
.list-item.danger { color: var(--danger); }
.sheet-schedule { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 14px; }
.sink-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; min-height: 56px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px 14px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  font-size: 15px;
  touch-action: manipulation;
}
.sink-item.active { border-color: var(--accent); }
.sink-item .sink-desc { flex: 1; }
.sink-item .sink-check { color: var(--accent); font-weight: 700; }

.confirm {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 72;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.confirm-card {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px;
}
.confirm-text { font-size: 16px; font-weight: 600; margin: 0 0 16px; line-height: 1.4; }

/* ===================== motion ===================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
