:root {
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: #10141f;
  color: #eef3ff;
}

* { box-sizing: border-box; }
html {
  width: 100%;
  min-height: 100%;
  height: -webkit-fill-available;
}
body {
  width: 100%;
  min-height: 100%;
  min-height: -webkit-fill-available;
  margin: 0;
  overflow: hidden;
  touch-action: none;
}

#appShell {
  height: 100vh;
  height: 100dvh;
  min-height: -webkit-fill-available;
  display: grid;
  grid-template-rows: auto 1fr;
  background: radial-gradient(circle at 20% 0%, #27344f 0%, #111827 42%, #070a12 100%);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: max(14px, env(safe-area-inset-top)) 18px 12px;
  border-bottom: 1px solid rgba(255,255,255,.12);
  background: rgba(8, 12, 22, .72);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand img {
  display: block;
  width: clamp(180px, 23vw, 300px);
  height: auto;
  max-height: 58px;
  object-fit: contain;
}

h1 {
  margin: 0;
  font-size: clamp(16px, 2.4vw, 23px);
  white-space: nowrap;
  transform: translateY(8px);
}
p { margin: 4px 0 0; color: #aab6cf; font-size: 14px; }

.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
label { color: #c8d2e8; font-size: 14px; }
select, button {
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 12px;
  background: rgba(255,255,255,.08);
  color: #f5f8ff;
  padding: 9px 12px;
  font-size: 15px;
}
button { cursor: pointer; }
button:active { transform: translateY(1px); }

#viewerWrap { position: relative; min-height: 0; }
#viewerCanvas { width: 100%; height: 100%; display: block; outline: none; }

.panel {
  position: absolute;
  left: 50%; top: 50%; transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-radius: 16px;
  background: rgba(6, 10, 18, .86);
  border: 1px solid rgba(255,255,255,.14);
  box-shadow: 0 18px 60px rgba(0,0,0,.35);
  z-index: 4;
}

.spinner {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  border: 3px solid rgba(255,255,255,.22);
  border-top-color: #6ea8ff;
  border-radius: 50%;
  animation: spin .75s linear infinite;
}
.panel.is-error { flex-wrap: wrap; justify-content: center; max-width: min(90vw, 430px); }
.panel.is-error .spinner { display: none; }
.retry-button { background: #2563eb; border-color: #60a5fa; font-weight: 600; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 1.6s; } }

.status {
  position: absolute;
  left: 14px; bottom: 14px;
  max-width: min(720px, calc(100% - 28px));
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(6, 10, 18, .66);
  color: #c7d2eb;
  font-size: 13px;
  line-height: 1.35;
  opacity: 1;
  transition: opacity .45s ease, visibility .45s ease;
}
.status.is-hidden { opacity: 0; visibility: hidden; }

.exit-focus {
  display: none;
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 3;
  background: rgba(6, 10, 18, .7);
  backdrop-filter: blur(8px);
}
#appShell.focus-mode { grid-template-rows: 1fr; }
#appShell.focus-mode .topbar { display: none; }
#appShell.focus-mode .exit-focus { display: block; }
#appShell.focus-mode .status { display: none; }

@media (max-width: 720px) {
  .topbar { align-items: flex-start; flex-direction: column; gap: 10px; padding: max(10px, env(safe-area-inset-top)) 12px 10px; }
  .brand { width: 100%; justify-content: space-between; gap: 10px; }
  .brand img { width: min(52vw, 225px); max-height: 44px; }
  h1 { font-size: 15px; white-space: normal; text-align: right; transform: translateY(5px); }
  .controls { justify-content: flex-start; width: 100%; }
  select { max-width: 100%; }
}
