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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: #eceef1;
  color: #1d1d1f;
  -webkit-tap-highlight-color: transparent;
}

#viewer { position: fixed; inset: 0; touch-action: none; }
#viewer canvas { display: block; outline: none; }

/* ---------- Title ---------- */
.topbar {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: 16px;
  pointer-events: none;
  z-index: 2;
}
.topbar h1 {
  font-size: 17px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(8px);
  padding: 8px 14px;
  border-radius: 10px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}
.topbar h1 span { font-weight: 400; color: #555; margin-left: 6px; }

/* ---------- View buttons ---------- */
.controls {
  position: fixed;
  bottom: max(18px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  padding: 6px;
  max-width: calc(100vw - 24px);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
  z-index: 2;
}
.controls button {
  border: none;
  background: transparent;
  min-height: 38px;
  padding: 8px 14px;
  font: 600 13px/1 inherit;
  font-family: inherit;
  border-radius: 8px;
  cursor: pointer;
  color: #333;
  transition: background 0.15s, color 0.15s;
}
.controls button:hover { background: #f0f0f0; }
.controls button:focus-visible { outline: 2px solid #1d1d1f; outline-offset: 1px; }
.controls button.active { background: #1d1d1f; color: #fff; }

.hint {
  position: fixed;
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + 62px);
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: #444;
  background: rgba(255, 255, 255, 0.8);
  padding: 4px 10px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 0.6s;
  z-index: 2;
}

/* ---------- Loading & error overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background: #eceef1;
  z-index: 10;
  transition: opacity 0.5s;
}
.overlay.hidden { opacity: 0; pointer-events: none; visibility: hidden; }

.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid #ddd;
  border-top-color: #1d1d1f;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.bar { width: 220px; height: 4px; background: #e5e5e5; border-radius: 2px; overflow: hidden; }
#bar-fill { width: 0; height: 100%; background: #1d1d1f; transition: width 0.2s; }

.err-title { font-size: 17px; font-weight: 700; }
.err-detail { font-size: 13px; color: #666; max-width: 420px; }
#retry-btn {
  border: none;
  background: #1d1d1f;
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

/* ---------- Tablet & mobile ---------- */
@media (max-width: 600px) {
  .topbar h1 { font-size: 14px; padding: 6px 10px; }
  .controls button { padding: 7px 10px; font-size: 12px; min-height: 36px; }
  .hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
