/* The designer only. The page does not scroll: canvas and panel fill the screen. */
html, body {
  height: 100%;
  height: 100dvh;
  width: 100%;
  max-width: 100vw;
  background: var(--bg-edge);
  overflow: hidden;
  overflow-x: hidden;
  position: fixed;
  inset: 0;
  /* The page can be zoomed with two fingers. A double tap does not zoom, so quick taps on the
     buttons and tabs stay taps. */
  touch-action: manipulation;
}

#app {
  display: flex;
  height: 100%;
  height: 100dvh;
  width: 100%;
  max-width: 100vw;
  position: relative;
  overflow: hidden;
  overflow-x: hidden;
  /* The top fades in from --bg-edge, the colour of the mobile browser bar */
  background:
    linear-gradient(to bottom, var(--bg-edge), transparent 96px),
    radial-gradient(
      circle at 45% 40%,
      var(--bg-sun) 0%,
      var(--bg) 55%,
      var(--bg-shadow) 100%
    );
  transition: background 0.4s ease;
}

#canvas-wrap {
  flex: 1;
  min-width: 0;
  min-height: 0;
  position: relative;
}

#canvas-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  transition: filter 0.5s ease;
}

#canvas-wrap.prompt-active canvas {
  filter: blur(3px);
}

/* A browser that cannot draw the preview: a still picture and two sentences in its place */
.no-preview {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 88px 28px 28px;
  text-align: center;
}

.no-preview .notice-text {
  max-width: 44ch;
}

.no-preview-still {
  width: min(100%, 420px);
  flex: 0 1 380px;
  min-height: 0;
  object-fit: contain;
  margin-bottom: 8px;
}

/* One line over the preview while it cannot be trusted (designer.js) */
.preview-notice {
  position: absolute;
  top: 84px;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: min(46ch, calc(100% - 32px));
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-elevated);
  color: var(--text);
  font-size: var(--fs-sm);
  line-height: 1.45;
  text-align: center;
  z-index: 6;
}

/* The two order buttons before the studio's mode is known (designer.js): they keep their place */
.status-pending {
  visibility: hidden;
}

/* Top Navigation Bar */
#topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 20px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  pointer-events: none;
  z-index: 10;
  box-sizing: border-box;
  max-width: 100vw;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex-shrink: 1;
}

.brand-link {
  text-decoration: none;
  color: inherit;
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: opacity 0.2s ease;
  flex-shrink: 0;
}

.brand-link:hover { opacity: 0.75; }

.topbar-actions {
  pointer-events: auto;
  flex-shrink: 0;
  white-space: nowrap;
}

/* Desktop orders from the panel button; this pill is the order button on phones only */
.order-trigger-btn {
  display: none;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  border: none;
  border-radius: var(--radius-pill);
  padding: 6px 14px;
  cursor: pointer;
  font-family: inherit;
  box-shadow: var(--shadow-button);
  transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
  white-space: nowrap;
  align-items: center;
  gap: 3px;
  line-height: 1.3;
  flex-shrink: 0;
}

.order-trigger-btn .pill-short {
  display: none;
}
.order-trigger-btn .pill-full {
  display: inline;
}

.order-trigger-btn:hover {
  transform: translateY(-1px);
  opacity: 0.92;
  box-shadow: var(--shadow-button-hover);
}

#hint {
  position: absolute;
  bottom: 22px;
  left: 24px;
  font-size: var(--fs-xs);
  color: var(--muted);
  font-family: var(--font-sans);
  letter-spacing: 0.04em;
  pointer-events: none;
  z-index: 2;
  transition: opacity 0.35s ease;
}

#canvas-wrap.prompt-active #hint {
  opacity: 0;
}

/* Drag Orbit Guide */
.drag-prompt {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.94);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-elevated);
  color: var(--text);
  padding: 16px 22px;
  border-radius: var(--radius-lg);
  font-size: var(--fs-md);
  font-family: var(--font-serif-text);
  letter-spacing: 0.06em;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: all 0.5s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 5;
  user-select: none;
}

.drag-prompt.visible {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, -50%) scale(1);
}

.drag-prompt-hand-wrap {
  position: relative;
  width: 28px;
  height: 28px;
  color: var(--text);
}

/* The control panel at the right, edged like a timber slat */
#panel {
  width: 350px;
  min-height: 0;
  background: var(--panel);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  border-left: 1px solid var(--slat);
  box-shadow: -3px 0 0 var(--slat-shadow), -1px 0 0 var(--timber-light);
  padding: 28px 22px 32px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
  z-index: 5;
  position: relative;
}

/* A second, fainter line beside the edge */
#panel::before {
  content: '';
  position: absolute;
  top: 0;
  left: 3px;
  bottom: 0;
  width: 1px;
  background: var(--border);
  opacity: 0.6;
  pointer-events: none;
}

.panel-cards-deck {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section-header {
  font-size: var(--fs-md);
  font-family: var(--font-serif-text);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 2px;
  border-bottom: 1px dashed var(--card-border);
}

.slider-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 16px 14px;
  box-shadow: var(--shadow-card);
}

.group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--card-border);
  transition: opacity 0.2s ease;
}

.slider-stack .group:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.group.inert { opacity: 0.45; }

.inert-note {
  display: none;
  font-size: var(--fs-xs);
  font-style: italic;
  color: var(--muted);
  margin-top: 2px;
  font-family: var(--font-sans);
}

.group.inert .inert-note { display: block; }

.group-label {
  font-size: var(--fs-sm);
  color: var(--text);
  display: flex;
  justify-content: space-between;
  font-family: var(--font-sans);
  font-weight: 500;
}

/* Sliders: a hairline track and a round thumb */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 32px;
  background: transparent;
  cursor: pointer;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  margin: -6px 0;
}

input[type="range"]::-webkit-slider-runnable-track {
  width: 100%;
  height: 1.5px;
  background: var(--slider-track);
  border-radius: 1px;
  transition: background 0.2s ease;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -6.25px;
  border-radius: 50%;
  background: var(--slider-thumb);
  border: 2px solid var(--bg);
  box-shadow: var(--shadow-knob);
  transition: transform 0.15s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.15s ease;
}

input[type="range"]:active::-webkit-slider-thumb {
  transform: scale(1.3);
  box-shadow: 0 0 0 5px var(--slider-halo), var(--shadow-knob);
}

input[type="range"]::-moz-range-track {
  width: 100%;
  height: 1.5px;
  background: var(--slider-track);
  border-radius: 1px;
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--slider-thumb);
  border: 2px solid var(--bg);
  box-shadow: var(--shadow-knob);
  transition: transform 0.15s cubic-bezier(0.2, 0.8, 0.2, 1);
}

input[type="range"]:active::-moz-range-thumb {
  transform: scale(1.3);
}

.slider-endpoints {
  display: flex;
  justify-content: space-between;
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--muted);
  margin-top: 2px;
  letter-spacing: 0.01em;
  user-select: none;
  font-family: var(--font-sans);
}

.slider-endpoints.three-endpoints span { flex: 1 1 0; }
.slider-endpoints.three-endpoints span:first-child { text-align: left; }
.slider-endpoints.three-endpoints span:nth-child(2) { text-align: center; }
.slider-endpoints.three-endpoints span:last-child { text-align: right; }

/* Style preset buttons */
.template-row { display: flex; gap: 8px; }

.template-btn {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 10px 4px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.template-btn:hover {
  border-color: var(--timber);
  background: var(--panel);
}

.template-btn.active {
  border-color: var(--text);
  background: var(--text);
  box-shadow: var(--shadow-button);
}

.template-name {
  white-space: nowrap;
  font-size: var(--fs-md);
  font-family: var(--font-serif-text);
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.05em;
  transition: color 0.15s ease;
}

.template-btn.active .template-name {
  color: var(--accent-contrast);
  font-weight: 600;
}

/* The light switch in the top bar, filled while the light is on */
.light-switch-btn[aria-pressed="true"] {
  color: var(--accent-contrast);
  background: var(--accent);
  border-color: var(--accent);
}

/* Wooden base preview toggle */
.base-toggle-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  box-shadow: var(--shadow-card);
  min-width: 0;
}

.base-toggle-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.base-toggle-label {
  font-size: var(--fs-md);
  font-family: var(--font-serif-text);
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.02em;
  line-height: 1.3;
}

.base-toggle-sub {
  font-size: var(--fs-xs);
  font-family: var(--font-sans);
  color: var(--muted);
  line-height: 1.3;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 22px;
  flex-shrink: 0;
  cursor: pointer;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-track {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: var(--slider-track);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-pill);
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.toggle-track::before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 2px;
  bottom: 2px;
  background-color: var(--panel);
  border-radius: 50%;
  box-shadow: var(--shadow-knob);
  transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1), background-color 0.2s ease;
}

.toggle-switch input:checked + .toggle-track {
  background-color: var(--text);
  border-color: var(--text);
}

.toggle-switch input:checked + .toggle-track::before {
  transform: translateX(16px);
  background-color: var(--accent-contrast);
}

.toggle-switch input:focus-visible + .toggle-track {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

/* Desktop Order Button */
.desktop-order-btn {
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  padding: 13px;
  font-size: var(--fs-md);
  font-family: var(--font-serif-text);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: var(--shadow-button);
  transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
  margin-top: auto;
}

.desktop-order-btn:hover {
  transform: translateY(-1px);
  opacity: 0.92;
  box-shadow: var(--shadow-button-hover);
}

.desktop-order-btn:active {
  transform: scale(0.98);
}

/* Mobile Tool Ribbon */
#toolRibbon { display: none; }

@media (max-width: 860px) {
  #topbar {
    padding: 12px 14px;
    padding-top: max(12px, env(safe-area-inset-top, 12px));
    padding-left: max(14px, env(safe-area-inset-left, 14px));
    padding-right: max(14px, env(safe-area-inset-right, 14px));
    gap: 8px;
  }
  .topbar-brand {
    gap: 8px;
  }
  .topbar-actions {
    padding: 3px 4px 3px 10px;
    gap: 6px;
  }
  .lang-btn {
    padding: 2px 3px;
  }
  .theme-toggle-btn {
    width: 24px;
    height: 24px;
  }
  .order-trigger-btn {
    display: inline-flex;
    padding: 5px 10px;
    gap: 2px;
  }
  .order-trigger-btn .pill-full {
    display: none !important;
  }
  .order-trigger-btn .pill-short {
    display: inline !important;
  }
  #app {
    flex-direction: column;
  }
  #canvas-wrap {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
  }
  #panel {
    flex: 0 0 auto;
    width: 100%;
    height: auto;
    max-height: 48vh;
    max-height: 48dvh;
    margin-top: auto;
    border-left: none;
    border-top: 1px solid var(--slat);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: var(--shadow-sheet), 0 -3px 0 var(--slat-shadow);
    padding: 12px 14px max(12px, env(safe-area-inset-bottom, 12px));
    gap: 8px;
    overflow-y: auto;
  }
  .panel-cards-deck {
    gap: 0;
  }
  .tab-card {
    display: none;
  }
  .tab-card.active {
    display: flex;
    animation: cardFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  }
  @keyframes cardFadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
  }
  .tab-card .section-header {
    display: none;
  }
  .slider-stack {
    padding: 10px 12px;
    gap: 10px;
  }
  .twin-stack .group {
    padding-bottom: 8px;
    gap: 7px;
  }
  .twin-stack .group:last-child {
    padding-bottom: 0;
  }
  .slider-endpoints {
    font-size: var(--fs-xs);
    margin-top: 1px;
  }
  .template-btn {
    padding: 8px 2px;
  }
  #toolRibbon {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding: 4px 0 2px;
    touch-action: pan-x;
  }
  #toolRibbon::-webkit-scrollbar { display: none; }
  .tab-btn {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 7px 14px;
    border-radius: var(--radius-pill);
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    color: var(--muted);
    font-size: var(--fs-md);
    font-family: var(--font-serif-text);
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
  }
  .tab-btn.active {
    background: var(--text);
    color: var(--accent-contrast);
    border-color: var(--text);
    font-weight: 600;
    box-shadow: var(--shadow-button);
  }
  .desktop-order-btn { display: none !important; }
}

/* The order pane: a modal dialog, shown as a sheet that slides up over the dimmed page. The dialog
   itself is the dimmed layer over the whole screen, so a click that reaches it is one beside the
   sheet (designer.js closes the pane on it). It is not dimmed through ::backdrop, which in
   browsers before 2024 cannot read the colour tokens. */
dialog:not([open]) {
  display: none !important;
}

.order-modal {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: none;
  background: var(--overlay);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: inherit;
  overflow: hidden;
  align-items: flex-end;
  justify-content: center;
}

.order-modal[open] {
  display: flex;
  animation: order-modal-in 0.25s ease;
}

.order-modal::backdrop {
  background: none;
}

.order-modal-sheet {
  background: var(--panel);
  border: 1px solid var(--slat);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  max-height: 88dvh;
  overflow-y: auto;
  padding: 28px 24px max(24px, env(safe-area-inset-bottom, 24px));
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: var(--shadow-sheet);
}

.order-modal[open] .order-modal-sheet {
  animation: order-sheet-up 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes order-modal-in {
  from { opacity: 0; }
}

@keyframes order-sheet-up {
  from { transform: translateY(100%); }
}

.order-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.order-modal-title-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.order-modal-titles h2 {
  font-size: var(--fs-lg);
  font-family: var(--font-serif);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.order-modal-price {
  font-size: var(--fs-md);
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text);
  white-space: nowrap;
}

.order-modal-price-group {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
}

.order-modal-currency {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  font-size: var(--fs-xs);
  font-family: var(--font-mono);
  color: var(--muted);
  cursor: pointer;
}

.order-modal-sub {
  font-size: var(--fs-md);
  color: var(--muted);
  font-family: var(--font-serif-text);
}

.order-modal-close {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  color: var(--text);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: var(--fs-sm);
  flex-shrink: 0;
}

.order-modal-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* One pane per studio mode: paused, open (order), pre-launch (waitlist) */
.checkout-pane { display: none; }
.checkout-pane.active { display: flex; flex-direction: column; gap: 14px; }

.notice-box {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.notice-title {
  font-family: var(--font-serif);
  font-size: var(--fs-lg);
  font-weight: 600;
}

.notice-text {
  font-size: var(--fs-sm);
  line-height: 1.45;
  color: var(--muted);
}

/* The form pieces themselves (input, button, messages) are in shared/base.css */
.form-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.save-reassurance-note {
  font-size: var(--fs-xs);
  color: var(--muted);
  margin-top: 4px;
}

/* The turn video (designer.js). Its dialog is a sheet like the order pane and uses that pane's
   classes; these are its own pieces. While the video is made the canvas has the video's size, so
   it is not shown. */
#canvas-wrap.video-running canvas {
  opacity: 0;
}

.video-sheet .order-modal-sub {
  display: block;
  margin-top: 6px;
  line-height: 1.45;
}

.video-progress {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 4px;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--slider-track);
  overflow: hidden;
}

.video-progress::-webkit-progress-bar {
  background: var(--slider-track);
}

.video-progress::-webkit-progress-value {
  background: var(--accent);
  border-radius: var(--radius-pill);
  transition: width 0.25s linear;
}

.video-progress::-moz-progress-bar {
  background: var(--accent);
  border-radius: var(--radius-pill);
}

.video-player {
  display: block;
  width: auto;
  max-width: 100%;
  height: min(52vh, 460px);
  height: min(52dvh, 460px);
  aspect-ratio: 9 / 16;
  margin: 0 auto;
  background: var(--bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
}

.video-actions {
  display: flex;
  gap: 10px;
}

.video-actions .submit-btn {
  flex: 1;
  text-align: center;
  text-decoration: none;
}

/* The second choice beside the first: saving on a phone, sharing on a desktop (.save-first) */
.video-actions:not(.save-first) #videoShareBtn:not([hidden]) + #videoSaveLink,
.video-actions.save-first #videoShareBtn {
  background: none;
  border: 1px solid var(--card-border);
  box-shadow: none;
  color: var(--text);
}

.video-actions.save-first #videoSaveLink {
  order: -1;
}
