:root {
    color-scheme: dark;
    --bg: #050816;
    --card: rgba(17, 24, 39, .92);
    --muted: #9ca3af;
    --text: #f9fafb;
    --line: rgba(255, 255, 255, .12)
}

* {
    box-sizing: border-box
}

body {
    margin: 0;
    min-height: 100svh;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: radial-gradient(circle at top, #1f2937, var(--bg));
    color: var(--text)
}

.app-shell {
    min-height: 100svh;
    display: grid;
    place-items: center;
    padding: max(18px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom))
}

.card {
    width: min(100%, 620px);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 26px;
    padding: 18px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, .35)
}

.top-row {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 12px
}

h1 {
    margin: 0 0 6px;
    font-size: 25px;
    letter-spacing: -.04em
}

.muted {
    margin: 0 0 16px;
    color: var(--muted);
    line-height: 1.35;
    font-size: 14px
}

.badge {
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: #d1d5db;
    font-size: 12px;
    font-weight: 800
}

.camera-wrap {
    position: relative;
    width: 100%;
    overflow: hidden;
    border-radius: 20px;
    background: #000;
    border: 1px solid var(--line);
    aspect-ratio: 3/4
}

video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block
}

.placeholder {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: var(--muted);
    background: linear-gradient(145deg, #111827, #030712)
}

.controls,
.fallback {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-top: 12px
}

.fallback {
    grid-template-columns: 1fr
}

button {
    border: 0;
    border-radius: 15px;
    padding: 14px 10px;
    color: white;
    background: #374151;
    font-weight: 800;
    font-size: 14px;
    touch-action: manipulation
}

button:active {
    transform: translateY(1px)
}

.primary {
    background: #2563eb
}

.danger {
    background: #dc2626
}

.status {
    margin-top: 12px;
    padding: 12px;
    border-radius: 14px;
    background: rgba(255, 255, 255, .06);
    border: 1px solid var(--line);
    color: #d1d5db;
    line-height: 1.35;
    font-size: 14px;
    display:none;
}

.remote-sink {
    position: fixed;
    left: -9999px;
    top: -9999px;
    width: 1px;
    height: 1px;
    opacity: 0
}

.upload-card {
    margin-top: 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 16px;
    display: grid;
    gap: 8px
}

.upload-card a {
    color: #93c5fd
}

.upload-card img {
    width: 100%;
    border-radius: 12px
}

.hidden {
    display: none !important
}

.upload-list {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.upload-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 7px 10px;
  border-radius: 8px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  font-size: 13px;
}

.upload-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.upload-status {
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
}

.upload-status.queued {
  color: #facc15;
}

.upload-status.uploading {
  color: #38bdf8;
}

.upload-status.uploaded {
  color: #22c55e;
}

.upload-status.failed {
  color: #ef4444;
}

@media(max-width:430px) {
    .controls {
        grid-template-columns: 1fr
    }

    .camera-wrap {
        aspect-ratio: 9/13
    }
}

.controls,
.upload-controls {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.controls {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.upload-controls {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.controls button,
.upload-controls button {
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.primary {
  background: #2563eb;
  color: white;
}

.danger {
  background: #dc2626;
  color: white;
}

.controls button:not(.primary):not(.danger),
.upload-controls button {
  background: #1f2937;
  color: white;
}

.controls button:active,
.upload-controls button:active {
  transform: scale(0.98);
}

@media (max-width: 650px) {
  .controls,
  .upload-controls {
    grid-template-columns: 1fr;
  }
}

.card.app-layout {
  width: 100%;
  max-width: 100dvh;
  height: calc(100dvh - 24px);
  margin: 12px auto;
  padding: 12px;
  box-sizing: border-box;

  display: grid;
  grid-template-columns: 40% 30% 1fr;
  grid-template-rows: 1fr auto;
  gap: 12px;

  background: rgba(15, 23, 42, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 22px;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.camera-panel,
.button-panel,
.log-panel {
  min-width: 0;
  min-height: 0;
}

.camera-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 175px;
  overflow: hidden;

  background: #020617;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

#video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #020617;
}

.placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;

  color: rgba(255, 255, 255, 0.7);
  font-size: 15px;
  font-weight: 700;
  text-align: center;
  padding: 20px;
  background: radial-gradient(circle at top, rgba(37, 99, 235, 0.22), rgba(2, 6, 23, 0.95));
}

.hidden {
  display: none !important;
}

.button-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}

.button-panel button {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 14px;
  padding: 11px 14px;

  font-size: 15px;
  font-weight: 800;
  line-height: 1.1;

  color: white;
  background: rgba(30, 41, 59, 0.95);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 8px 20px rgba(0, 0, 0, 0.22);

  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.button-panel button:active {
  transform: scale(0.98);
}

.button-panel .primary {
  background: linear-gradient(180deg, #3b82f6, #1d4ed8);
}

.button-panel .danger {
  background: linear-gradient(180deg, #ef4444, #b91c1c);
}

.button-separator {
  height: 1px;
  margin: 2px 0;
  background: rgba(255, 255, 255, 0.12);
}

.log-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;

  background: rgba(2, 6, 23, 0.42);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 18px;
}

.log-title {
  flex: 0 0 auto;
  padding: 10px 12px;

  color: rgba(255, 255, 255, 0.9);
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;

  background: rgba(15, 23, 42, 0.92);
  border-bottom: 1px solid rgba(255, 255, 255, 0.10);
}

.upload-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;

  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.upload-list::-webkit-scrollbar {
  width: 8px;
}

.upload-list::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.04);
  border-radius: 999px;
}

.upload-list::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.45);
  border-radius: 999px;
  border: 2px solid rgba(2, 6, 23, 0.8);
}

.upload-list::-webkit-scrollbar-thumb:hover {
  background: rgba(203, 213, 225, 0.65);
}

.upload-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;

  padding: 8px 10px;
  border-radius: 12px;

  background: rgba(15, 23, 42, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.10);

  color: white;
  font-size: 12px;
}

.upload-name {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.upload-name a {
  color: white;
  text-decoration: none;
}

.upload-status {
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.upload-status.queued {
  color: #facc15;
}

.upload-status.uploading {
  color: #38bdf8;
}

.upload-status.uploaded {
  color: #22c55e;
}

.upload-status.failed {
  color: #ef4444;
}

.status {
  grid-column: 1 / -1;

  min-height: 38px;
  padding: 9px 12px;
  border-radius: 14px;

  display: flex;
  align-items: center;

  color: rgba(255, 255, 255, 0.82);
  background: rgba(2, 6, 23, 0.58);
  border: 1px solid rgba(255, 255, 255, 0.10);

  font-size: 13px;
  font-weight: 700;
  display:none;
}

.remote-sink {
  position: fixed;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.upload-card {
  display: none;
}

#preview {
  display: none !important;
}

@media (max-width: 800px), (orientation: portrait) {
  .card.app-layout {
    max-width: none;
    width: calc(100dvw - 16px);
    height: calc(100dvh - 16px);
    margin: 8px;

    grid-template-columns: 1fr;
    grid-template-rows: 40% auto 1fr auto;
  }

  .camera-panel {
    min-height: 0;
  }

  .button-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow: visible;
  }

  .button-panel button {
    min-height: 44px;
    font-size: 13px;
    padding: 9px 10px;
  }

  .button-separator {
    display: none;
  }

  .log-panel {
    min-height: 0;
  }

  .status {
    font-size: 12px;
    display:none;
  }
}

#wakeBtn.wake-active {
  background: linear-gradient(180deg, #22c55e, #15803d);
  color: white;
}