/*
 * Fluid app shell and shared chrome.
 *
 * `#viewport` fills the visual viewport; `#stage` is the query container that
 * every screen sizes against. There is no fixed-pixel scaling transform:
 * screens reflow with `cqw`/`cqh`, safe-area insets, and orientation media
 * queries. `src/ui/stage.ts` only validates the mount point.
 */

html,
body {
  height: 100%;
  background: var(--page);
}

body {
  overflow: hidden;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
}

#viewport {
  position: relative;
  width: 100dvw;
  height: 100dvh;
  overflow: hidden;
  background: var(--page);
}

@supports not (height: 100dvh) {
  #viewport {
    height: 100vh;
  }
}

#stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  container-type: size;
  color: var(--text);
  font-family: var(--font-ui);
}

.screen {
  position: absolute;
  inset: 0;
}

#stage img {
  -webkit-user-drag: none;
  user-select: none;
}

/* ------------------------------------------------------------------ */
/* Buttons                                                             */
/* ------------------------------------------------------------------ */

.btn {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45em;
  min-width: 96px;
  min-height: 40px;
  margin: 0;
  padding: 9px 18px;
  border: 0;
  border-radius: var(--radius-control);
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--text);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: 0.01em;
  text-align: center;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition:
    transform 0.15s var(--ease-out),
    background-color 0.15s ease,
    color 0.15s ease,
    opacity 0.15s ease;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
}

.btn:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.32;
  transform: none;
  cursor: default;
}

.btn--primary {
  background: var(--p-bg);
  box-shadow: none;
  color: var(--p-ink);
}

.btn--secondary {
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--text);
  color: var(--text);
}

.btn--danger {
  background: var(--accent-fill);
  box-shadow: none;
  color: #fffdf8;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  transition:
    transform 0.15s var(--ease-out),
    background-color 0.15s ease,
    color 0.15s ease;
}

.icon-btn:hover {
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: translateY(0);
}

.icon-btn:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.icon-svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

/* ------------------------------------------------------------------ */
/* Generic overlays and helpers                                        */
/* ------------------------------------------------------------------ */

.toast {
  position: absolute;
  left: 50%;
  bottom: max(24px, calc(var(--safe-bottom) + 18px));
  z-index: 80;
  max-width: min(520px, calc(100vw - 32px));
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--modal);
  box-shadow: var(--shadow-paper);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
}

.toast.visible,
.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.hidden {
  display: none !important;
}

/* Debug overlay, enabled only with ?debug=1. Kept out of the play area. */
.debug-overlay {
  position: absolute;
  left: 6px;
  top: max(64px, calc(var(--safe-top) + 48px));
  z-index: 65;
  max-width: 300px;
  margin: 0;
  padding: 6px 8px;
  border: 1px solid var(--accent);
  border-radius: 5px;
  background: color-mix(in srgb, var(--text) 88%, transparent);
  color: var(--bg-solid);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 8.5px;
  line-height: 1.35;
  white-space: pre-wrap;
  pointer-events: none;
}

.noscript-message {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 40px;
  color: var(--accent);
  font-size: 18px;
  line-height: 1.5;
  text-align: center;
}
