:root {
  --paper: #ffffff;
  --paper-strong: #ffffff;
  --ink: #141311;
  --ink-soft: rgba(20, 19, 17, 0.62);
  --line: rgba(20, 19, 17, 0.08);
  --line-strong: rgba(20, 19, 17, 0.15);
  --shadow-soft: 0 14px 34px rgba(18, 16, 14, 0.08);
  --shadow-lifted: 0 18px 42px rgba(18, 16, 14, 0.1);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  color: var(--ink);
  font-family: "Helvetica Neue", "Avenir Next", "Segoe UI", sans-serif;
  background:
    linear-gradient(rgba(255, 255, 255, 0.985), rgba(255, 255, 255, 0.985)),
    linear-gradient(90deg, rgba(24, 21, 18, 0.018) 1px, transparent 1px),
    linear-gradient(rgba(24, 21, 18, 0.018) 1px, transparent 1px),
    var(--paper);
  background-size: auto, 34px 34px, 34px 34px, auto;
}

button,
input {
  font: inherit;
}

input[type="number"] {
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  margin: 0;
}

.page-shell {
  min-height: 100vh;
  padding: 1rem 1rem 2.8rem;
}

.hud {
  position: sticky;
  top: 0.9rem;
  z-index: 20;
  overflow-x: auto;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow-soft);
}

.hud-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: "nav controls actions";
  align-items: center;
  gap: 0.45rem;
  min-width: max-content;
  padding: 0.28rem 0.34rem;
}

.hud-nav,
.hud-controls,
.hud-actions {
  display: flex;
  align-items: center;
  gap: 0.24rem;
  flex-wrap: nowrap;
}

.hud-nav {
  grid-area: nav;
}

.hud-controls {
  grid-area: controls;
  justify-content: center;
}

.hud-actions {
  grid-area: actions;
  justify-content: flex-end;
  gap: 0.28rem;
}

.hud-preview-group {
  display: inline-flex;
  align-items: center;
  gap: 0.24rem;
  padding-inline-end: 0.18rem;
}

.hud-render-group,
.hud-session-group {
  display: inline-flex;
  align-items: center;
  gap: 0.24rem;
}

.hud-field {
  display: flex;
  align-items: center;
  gap: 0.14rem;
  color: var(--ink-soft);
  font-size: 0.56rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.hud-field input {
  width: 3.1rem;
  min-width: 0;
  height: 1.58rem;
  padding: 0.1rem 0.18rem;
  border: 1px solid var(--line);
  border-radius: 0;
  background: rgba(255, 255, 255, 0.88);
  color: var(--ink);
  text-align: right;
}

.hud-field-compact input {
  width: 2.5rem;
}

.hud-field-wide input {
  width: 5.8rem;
}

.hud-button,
.preview-close {
  min-height: 1.58rem;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  padding: 0.2rem 0.36rem;
  background: rgba(255, 255, 255, 0.78);
  color: var(--ink);
  cursor: pointer;
  transition: transform 160ms ease, background-color 160ms ease, box-shadow 160ms ease;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.6rem;
  line-height: 1;
  white-space: nowrap;
}

.hud-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.24rem;
  min-height: 1.58rem;
  padding: 0 0.12rem;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.58rem;
  user-select: none;
}

.hud-toggle input {
  appearance: none;
  width: 0.84rem;
  height: 0.84rem;
  margin: 0;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  background: rgba(255, 255, 255, 0.92);
  cursor: pointer;
}

.hud-toggle input:checked {
  background: var(--ink);
  box-shadow: inset 0 0 0 2px #ffffff;
}

.hud-toggle input:disabled {
  cursor: progress;
  opacity: 0.5;
}

.hud-slider {
  display: inline-flex;
  align-items: center;
  gap: 0.14rem;
  min-height: 1.58rem;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.54rem;
  user-select: none;
}

.hud-slider-control {
  display: inline-flex;
  align-items: center;
  gap: 0.04rem;
}

.hud-slider input[type="range"] {
  width: 2.8rem;
  margin: 0;
  accent-color: var(--ink);
  cursor: ew-resize;
}

.hud-slider input[type="range"]:disabled {
  cursor: progress;
  opacity: 0.5;
}

.hud-slider output {
  min-width: 0.88rem;
  color: var(--ink);
  font-size: 0.58rem;
  text-align: right;
}

.hud-slider.is-disabled {
  opacity: 0.56;
}

.hud-button:hover,
.preview-close:hover {
  transform: translateY(-1px);
  background: var(--paper-strong);
  box-shadow: 0 8px 18px rgba(18, 16, 14, 0.08);
}

.hud-button:disabled {
  cursor: progress;
  opacity: 0.58;
  transform: none;
  box-shadow: none;
}

.hud-button-strong {
  background: rgba(20, 19, 17, 0.94);
  color: #f7f6f1;
}

.status-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 1.1rem;
  padding: 0.42rem 0.08rem 0;
  color: var(--ink-soft);
  font-size: 0.74rem;
}

.workspace {
  padding-top: 0.85rem;
}

.site-attribution {
  position: fixed;
  left: 50%;
  bottom: 0.85rem;
  z-index: 5;
  width: min(640px, calc(100vw - 2rem));
  margin: 0;
  color: rgba(20, 19, 17, 0.44);
  font-size: 0.64rem;
  line-height: 1.4;
  text-align: center;
  transform: translateX(-50%);
  pointer-events: none;
}

.site-attribution p {
  margin: 0;
}

.view {
  display: none;
}

.view-active {
  display: block;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 150px));
  justify-content: center;
  gap: 1.6rem 1.2rem;
  padding: 2rem 0 3rem;
}

.gallery-card {
  display: grid;
  justify-items: center;
}

.gallery-card figure {
  margin: 0;
  display: grid;
  gap: 0.65rem;
  justify-items: center;
}

.gallery-thumb-button {
  appearance: none;
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
}

.gallery-thumb-frame {
  width: 150px;
  height: 150px;
  border: 1px solid rgba(20, 19, 17, 0.06);
  border-radius: 0;
  overflow: hidden;
  background: #ffffff;
}

.gallery-thumb-frame img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.gallery-thumb-caption,
.gallery-placeholder {
  display: grid;
  gap: 0.2rem;
  color: var(--ink-soft);
  font-size: 0.74rem;
  line-height: 1.45;
  text-align: center;
}

.gallery-thumb-caption strong,
.gallery-placeholder strong {
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 600;
}

.page-shell.gallery-chrome-hidden .hud {
  display: none;
}

.page-shell.gallery-chrome-hidden .workspace {
  padding-top: 0;
}

.page-shell.gallery-chrome-hidden #gallery-grid .gallery-thumb-caption {
  display: none;
}

.render-stage-shell {
  display: grid;
  justify-items: center;
  gap: 0.72rem;
  padding: 0.85rem 0 2.55rem;
}

.render-actions {
  display: flex;
  justify-content: center;
  min-height: 1.48rem;
}

.render-progress {
  display: grid;
  gap: 0.42rem;
  width: min(100%, 1024px);
  max-width: 1024px;
}

.render-progress-meta {
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

.render-progress-bar {
  width: 100%;
  height: 1px;
  background: rgba(20, 19, 17, 0.12);
  overflow: hidden;
}

.render-progress-fill {
  width: 0;
  height: 1px;
  background: #000000;
}

#render-canvas,
#render-image {
  width: min(100%, 1024px);
  max-width: 1024px;
  aspect-ratio: 1 / 1;
  border: 1px solid rgba(20, 19, 17, 0.08);
  border-radius: 0;
  background: #ffffff;
}

.render-meta {
  max-width: min(100%, 1024px);
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.88rem;
}

.panel-dialog {
  width: min(92vw, 28rem);
  border: none;
  padding: 0;
  background: transparent;
}

.panel-dialog::backdrop {
  background: rgba(16, 15, 13, 0.28);
  backdrop-filter: blur(8px);
}

.panel-card {
  display: grid;
  gap: 0.9rem;
  padding: 1.1rem;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  background: rgba(255, 255, 255, 0.985);
  box-shadow: var(--shadow-lifted);
}

.panel-card h2,
.preview-caption strong {
  margin: 0;
  font-family: inherit;
}

.panel-card p {
  margin: 0;
  color: var(--ink-soft);
}

.panel-card label {
  display: grid;
  gap: 0.35rem;
}

.panel-card input {
  padding: 0.6rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 0;
  background: white;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.dialog-error {
  min-height: 1.1rem;
  color: #9f2c19;
  font-size: 0.92rem;
}

.preview-dialog {
  width: min(96vw, 72rem);
}

.preview-card {
  gap: 1rem;
}

.preview-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
}

#preview-image {
  width: min(100%, 1024px);
  aspect-ratio: 1 / 1;
  object-fit: contain;
  justify-self: center;
  border: 1px solid rgba(20, 19, 17, 0.08);
  border-radius: 0;
  background: #ffffff;
}

.preview-caption {
  display: grid;
  gap: 0.3rem;
  color: var(--ink-soft);
  text-align: center;
}

@media (max-width: 920px) {
  .page-shell {
    padding: 0.56rem 0.56rem 2.2rem;
  }

  .hud {
    top: 0.5rem;
    overflow-x: clip;
  }

  .hud-row {
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "nav actions"
      "controls controls";
    row-gap: 0.34rem;
    min-width: 0;
    width: 100%;
    align-items: start;
    padding: 0.24rem 0.24rem;
  }

  .hud-button,
  .preview-close {
    min-height: 1.34rem;
    padding: 0.14rem 0.22rem;
    font-size: 0.58rem;
  }

  .hud-preview-group,
  .hud-render-group,
  .hud-session-group {
    gap: 0.12rem;
  }

  .hud-preview-group {
    padding-inline-end: 0.08rem;
  }

  .hud-toggle,
  .hud-slider,
  .hud-slider output {
    font-size: 0.58rem;
  }

  .hud-controls {
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: 0.12rem;
    width: 100%;
    justify-content: stretch;
  }

  .hud-controls .hud-field {
    display: grid;
    gap: 0.04rem;
    min-width: 0;
    font-size: 0.64rem;
    letter-spacing: 0.03em;
  }

  .hud-controls .hud-field span {
    text-align: center;
  }

  .hud-controls .hud-field input,
  .hud-controls .hud-field-compact input,
  .hud-controls .hud-field-wide input {
    width: 100%;
    height: 1.28rem;
    padding: 0.05rem 0.08rem;
    font-size: 0.64rem;
  }

  .hud-actions {
    min-width: 0;
    justify-content: flex-end;
    gap: 0.14rem;
  }

  #render-volatile {
    display: none;
  }

  .site-attribution {
    bottom: 0.62rem;
    width: min(640px, calc(100vw - 1rem));
    font-size: 0.58rem;
  }

  .render-stage-shell {
    gap: 0.58rem;
    padding: 0.46rem 0 1.9rem;
  }

  .render-actions {
    min-height: 1.34rem;
  }

  .status-strip {
    font-size: 0.7rem;
  }

  .gallery-grid {
    gap: 1.3rem 0.9rem;
  }
}
