:root {
  color-scheme: dark;
  --page: #11151b;
  --panel: #20262e;
  --text: #f7fbff;
  --muted: #b6c0cc;
  --accent: #35d3a7;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { width: 100%; height: 100%; }
body { margin: 0; overflow: hidden; background: var(--page); color: var(--text); }
button { font: inherit; }

.deck {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  gap: 16px;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.stage-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  touch-action: pan-y pinch-zoom;
}

.stage-wrap--zoomed {
  display: block;
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y pinch-zoom;
}

.stage {
  position: relative;
  flex: none;
  margin: auto;
  overflow: hidden;
  background: #f9fbff;
  opacity: 0;
}

.stage--ready { opacity: 1; }
.slide-layer { position: absolute; inset: 0; }
.slide-layer--exiting { pointer-events: none; }
.slide-image { display: block; width: 100%; height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; }
.slide-animation { position: absolute; object-fit: cover; pointer-events: none; }

.deck-status {
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(100%, 880px);
  justify-self: center;
  padding: 6px;
  border: 1px solid #39434f;
  border-radius: 8px;
  background: var(--panel);
}

.icon-button, .install-button {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 26px;
  line-height: 1;
  touch-action: manipulation;
}

.icon-button:hover:not(:disabled), .install-button:hover { background: #35404d; }
.icon-button:disabled { opacity: 0.3; cursor: default; }
#refreshButton img { width: 20px; height: 20px; filter: invert(1); }
#refreshButton[aria-busy="true"] img { animation: refresh-spin 900ms linear infinite; }
@keyframes refresh-spin { to { transform: rotate(360deg); } }
button:focus-visible, .stage-wrap:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.install-button { width: auto; padding: 0 12px; font-size: 13px; font-weight: 600; }
.progress { flex: 1; min-width: 20px; height: 4px; overflow: hidden; border-radius: 2px; background: #485461; }
.progress__bar { display: block; width: 0; height: 100%; background: var(--accent); transition: width 180ms ease; }
.slide-count { flex: none; min-width: 44px; font-size: 13px; font-weight: 600; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.restore-controls { position: fixed; right: max(12px, env(safe-area-inset-right)); bottom: max(12px, env(safe-area-inset-bottom)); background: var(--panel); opacity: 0.7; }
.cache-status { width: min(100%, 880px); justify-self: center; color: var(--muted); font-size: 12px; }
.cache-status__heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 20px; }
.cache-status progress { display: block; width: 100%; height: 4px; margin-top: 6px; border: 0; border-radius: 2px; overflow: hidden; appearance: none; background: #485461; accent-color: var(--accent); }
.cache-status progress::-webkit-progress-bar { background: #485461; }
.cache-status progress::-webkit-progress-value { background: var(--accent); }
.cache-status progress::-moz-progress-bar { background: var(--accent); }
.cache-status .install-button { height: 44px; font-size: 12px; }
.controls-hidden .deck { grid-template-rows: minmax(0, 1fr); gap: 0; }
.controls-hidden .deck-status { display: none; }
.controls-hidden .cache-status { display: none; }

@media (max-width: 600px) {
  .deck {
    gap: 8px;
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }
  .deck-status { gap: 2px; padding: 4px; flex-wrap: wrap; }
  .progress { flex-basis: 24px; }
  .install-button { margin-left: auto; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .deck { gap: 4px; padding-top: max(4px, env(safe-area-inset-top)); padding-bottom: max(4px, env(safe-area-inset-bottom)); }
  .deck-status { padding: 0 4px; }
}

@media (prefers-reduced-motion: reduce) {
  .progress__bar { transition: none; }
  #refreshButton[aria-busy="true"] img { animation: none; }
}
