:root {
  --app-scale: 0.72;
  --bg: #f3eee5;
  --panel: #2f3639;
  --panel-soft: #394145;
  --panel-deeper: #22282b;
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.18);
  --text: #f7f4ec;
  --muted: #c3c5bc;
  --accent: #f0a55b;
  --accent-strong: #ff8d4d;
  --grid: rgba(80, 143, 255, 0.34);
  --selection: rgba(255, 141, 77, 0.18);
  --selection-line: rgba(255, 141, 77, 0.95);
  --shadow: 0 28px 60px rgba(17, 20, 24, 0.18);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  width: 100%;
  overflow-x: clip;
}

body {
  font-family:
    "Avenir Next",
    "DIN Alternate",
    "PingFang SC",
    "Hiragino Sans GB",
    "Microsoft YaHei",
    sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(240, 165, 91, 0.16), transparent 24%),
    linear-gradient(180deg, #f4efe7 0%, #ece5d8 100%);
}

button,
input {
  font: inherit;
}

canvas,
img {
  display: block;
  border-radius: 0;
}

.hidden {
  display: none !important;
}

.app-shell {
  zoom: var(--app-scale);
  max-width: min(1720px, calc(100% / var(--app-scale)));
  margin: 0 auto;
  padding: 24px 18px 34px;
  display: grid;
  gap: 20px;
  width: 100%;
  min-width: 0;
}

.app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
}

.topbar-brand,
.topbar-link {
  color: #2a2520;
  text-decoration: none;
}

.topbar-brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-size: 0.96rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 700;
}

.topbar-brand-logo {
  width: 40px;
  height: 40px;
  object-fit: cover;
  flex: 0 0 auto;
}

.topbar-brand-text {
  display: inline-block;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topbar-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 14px;
  border: 1px solid rgba(42, 37, 32, 0.12);
  background: rgba(255, 255, 255, 0.55);
  font-weight: 600;
}

.topbar-link-strong {
  border-color: rgba(42, 37, 32, 0.22);
  background: rgba(42, 37, 32, 0.08);
}

.hero-card,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  min-width: 0;
}

.hero-card {
  padding: 24px 28px;
  text-align: center;
}

.workspace {
  display: block;
  min-width: 0;
}

.preview-panel,
.output-panel {
  padding: 18px;
}

.app-hero,
.preview-panel,
.output-panel {
  border-radius: 0;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.78rem;
}

h1,
h2 {
  margin: 0;
  line-height: 1.08;
  overflow-wrap: anywhere;
  word-break: break-word;
  max-width: 100%;
}

h1 {
  font-size: clamp(1.7rem, 2.5vw, 2.6rem);
}

h2 {
  font-size: 1.26rem;
}

.hero-copy,
.muted,
.field span,
.slider-field span {
  color: var(--muted);
}

.hero-copy {
  margin: 12px auto 0;
  max-width: 1080px;
  line-height: 1.55;
  word-break: break-word;
  font-size: 0.96rem;
}

.hero-actions {
  margin-top: 18px;
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  min-width: 0;
}

.hero-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border: 1px solid var(--line-strong);
  color: var(--text);
  text-decoration: none;
  background: rgba(255, 255, 255, 0.05);
}

.hero-link-primary {
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: #221c17;
  font-weight: 700;
}

.hero-points {
  margin: 18px auto 0;
  max-width: 900px;
  width: 100%;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  text-align: left;
  min-width: 0;
}

.hero-points li {
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  line-height: 1.5;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.panel-head,
.output-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.panel-head {
  justify-content: space-between;
}

.section-head {
  gap: 18px;
}

.preview-stage {
  margin-top: 14px;
  position: relative;
}

.canvas-scroller {
  position: relative;
  overflow: auto;
  width: 100%;
  max-height: 70vh;
  background: var(--panel-deeper);
  -webkit-overflow-scrolling: touch;
}

.canvas-scroller.empty {
  min-height: 540px;
}

.canvas-upload-card {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  padding: 18px;
  border: 1px dashed rgba(255, 255, 255, 0.24);
  background: rgba(34, 40, 43, 0.96);
  cursor: pointer;
  text-align: center;
}

.canvas-upload-card.dragover {
  border-color: rgba(240, 165, 91, 0.95);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.06), rgba(240, 165, 91, 0.14));
}

.upload-title {
  display: block;
  color: var(--text);
  font-size: 0.96rem;
  margin-bottom: 6px;
}

.upload-hint {
  color: var(--muted);
}

#mainCanvas {
  transform-origin: top left;
  image-rendering: pixelated;
  max-width: none;
  margin: 0 auto;
  display: block;
}

.preview-toolbar {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(320px, 520px) auto;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.preview-toolbar-copy {
  margin: 0;
}

.background-status {
  margin: 8px 0 0;
  min-height: 1.5em;
}

.preview-toolbar-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: nowrap;
  min-width: 0;
  overflow: hidden;
}

.preview-toolbar-actions {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  flex: 0 0 auto;
}

.selection-action-bubble {
  position: absolute;
  z-index: 3;
  display: flex;
}

.selection-action-toolbar {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 3px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(24, 28, 31, 0.94);
  box-shadow: 0 10px 24px rgba(17, 20, 24, 0.28);
}

.selection-action-button {
  width: 20px;
  height: 20px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  line-height: 1;
  border: 0;
}

.selection-action-button + .selection-action-button {
  margin-left: 3px;
}

.selection-action-button-confirm {
  background: linear-gradient(135deg, #ffb261 0%, #ff8d4d 100%);
  color: #23150a;
}

.selection-action-button-cancel {
  background: rgba(255, 157, 79, 0.26);
  color: #ffe3c3;
}

.inline-settings {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  display: grid;
  gap: 12px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field span,
.slider-field span,
.toggle span {
  font-size: 0.92rem;
}

input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
}

.settings-actions {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 44px;
}

.setting-actions {
  display: grid;
  justify-items: center;
}

.slider-field {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
}

.compact-slider {
  min-width: 0;
  width: 100%;
  flex: 1 1 auto;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  white-space: nowrap;
}

button {
  border: 0;
  padding: 10px 16px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: #221c17;
  font-weight: 700;
  cursor: pointer;
}

button.small {
  padding: 9px 12px;
  font-size: 0.88rem;
}

.ghost-button {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

#applySettingsButton {
  min-width: 220px;
}

#applySettingsButton.is-dirty {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: #221c17;
}

#applySettingsButton:not(.is-dirty) {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.output-panel {
  display: grid;
  gap: 12px;
}

.info-panel {
  padding: 18px;
  display: grid;
  gap: 14px;
}

.info-grid,
.faq-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  min-width: 0;
}

.info-card,
.faq-item {
  padding: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
}

.info-card h3,
.faq-item h3 {
  margin: 0 0 10px;
  font-size: 1.05rem;
  line-height: 1.35;
}

.info-card p,
.faq-item p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.feature-list {
  display: grid;
  gap: 10px;
}

.feature-list p {
  margin: 0;
  padding: 12px 14px;
  border-left: 3px solid var(--accent);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  line-height: 1.6;
}

.step-list {
  margin: 0;
  padding-left: 22px;
  display: grid;
  gap: 12px;
  color: var(--muted);
  line-height: 1.7;
}

.layout-panel {
  display: grid;
  gap: 12px;
  margin-top: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.layout-head-side {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

#layoutSummary {
  margin: 0;
}

.layout-export-button {
  flex: 0 0 auto;
}

.tile-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 136px));
  gap: 10px;
  max-height: 34vh;
  overflow: auto;
  align-content: start;
  justify-content: start;
  padding-top: 4px;
  -webkit-overflow-scrolling: touch;
}

.tile-preview-grid.empty {
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
}

.layout-board {
  position: relative;
  min-height: 420px;
  overflow: auto;
  padding: 0;
  border: 1px solid var(--line);
  background-color: #2a3134;
  background-image:
    linear-gradient(to right, rgba(255, 141, 77, 0.2) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 141, 77, 0.2) 1px, transparent 1px);
  background-size: var(--layout-grid-step-x, 32px) var(--layout-grid-step-y, 32px);
  background-position: var(--layout-grid-origin-x, 24px) var(--layout-grid-origin-y, 24px);
  -webkit-overflow-scrolling: touch;
}

.layout-board.empty {
  display: grid;
  place-items: center;
  padding: 20px;
}

.layout-empty-copy {
  margin: 0;
  color: var(--muted);
  text-align: center;
}

.layout-item {
  position: absolute;
  cursor: grab;
  box-shadow: 0 10px 24px rgba(17, 20, 24, 0.12);
  background: transparent;
  user-select: none;
  touch-action: none;
}

.layout-item:active {
  cursor: grabbing;
}

.layout-item canvas {
  width: 100%;
  height: 100%;
}

.tile-card {
  position: relative;
  padding: 8px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  display: grid;
  gap: 6px;
  align-content: start;
}

.screenshot-thumb {
  min-height: 92px;
  max-height: 110px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #2a3134;
  border: 1px solid var(--line);
}

.tile-card canvas {
  width: auto;
  max-width: 100%;
  max-height: 108px;
  height: auto;
  background: #2a3134;
}

.tile-check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 700;
  font-size: 0.78rem;
  min-width: 0;
}

.tile-check span,
.screenshot-meta {
  margin: 0;
}

.tile-check input {
  margin: 0;
  flex: 0 0 auto;
}

.screenshot-title {
  display: inline-block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.screenshot-canvas {
  cursor: zoom-in;
  background: #2a3134;
}

.screenshot-meta {
  font-size: 0.72rem;
  line-height: 1.3;
}

.screenshot-card.is-checked {
  border-color: rgba(120, 217, 139, 0.55);
  box-shadow: inset 0 0 0 1px rgba(120, 217, 139, 0.32);
}

.preview-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
}

.preview-modal.hidden {
  display: none;
}

.preview-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 20, 24, 0.68);
}

.preview-dialog {
  position: relative;
  z-index: 1;
  width: min(1100px, calc(100vw - 48px));
  max-height: calc(100vh - 48px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 18px;
  box-shadow: var(--shadow);
}

.preview-modal-body {
  margin-top: 18px;
  display: grid;
  gap: 18px;
}

.preview-modal-canvas-wrap,
.preview-layout-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  background: #2a3134;
}

#previewModalCanvas,
.preview-layout-canvas {
  width: 100%;
  height: auto;
  image-rendering: pixelated;
}

.preview-modal-tiles {
  display: grid;
  gap: 10px;
}

.preview-layout-label {
  margin: 0;
}

@media (max-width: 1100px) {
  .app-shell {
    zoom: 1;
    padding: 24px 18px 36px;
    max-width: 1440px;
  }

  .preview-toolbar {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .preview-toolbar-controls,
  .preview-toolbar-actions {
    justify-self: stretch;
    justify-content: space-between;
  }

  .preview-toolbar-controls {
    overflow: visible;
  }
}

@media (max-width: 980px) {
  .panel-head.section-head {
    align-items: flex-start;
  }

  .settings-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hero-points,
  .info-grid,
  .faq-list {
    grid-template-columns: 1fr;
  }

  .tile-preview-grid {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 18px 14px 30px;
  }

  .hero-card,
  .preview-panel,
  .output-panel,
  .info-panel,
  .preview-dialog {
    padding: 18px;
  }

  h1 {
    font-size: clamp(1.6rem, 8vw, 2.2rem);
    line-height: 1.16;
  }

  h2 {
    font-size: 1.25rem;
  }

  .panel-head,
  .output-actions,
  .layout-head-side,
  .preview-toolbar-controls,
  .preview-toolbar-actions,
  .hero-actions,
  .app-topbar,
  .topbar-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .hero-link,
  .topbar-link {
    width: 100%;
  }

  .panel-head {
    gap: 10px;
  }

  .canvas-scroller {
    max-height: 56vh;
  }

  .canvas-scroller.empty {
    min-height: 360px;
  }

  .canvas-upload-card {
    padding: 18px;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  .slider-field {
    grid-template-columns: 1fr;
  }

  .compact-slider {
    min-width: 0;
    width: 100%;
  }

  .toggle {
    justify-content: flex-start;
  }

  .preview-toolbar,
  .inline-settings {
    gap: 14px;
  }

  .selection-action-bubble {
    gap: 0;
  }

  .selection-action-toolbar {
    padding: 3px;
  }

  .selection-action-button {
    width: 20px;
    height: 20px;
    font-size: 0.72rem;
  }

  .hero-points li,
  .info-card,
  .faq-item,
  .feature-list p {
    padding: 14px;
  }

  .hero-copy {
    font-size: 0.98rem;
  }

  .tile-preview-grid {
    grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
    max-height: none;
  }

  .tile-card {
    padding: 8px;
  }

  .preview-modal {
    padding: 12px;
  }

  .preview-dialog {
    width: calc(100vw - 24px);
    max-height: calc(100vh - 24px);
    padding: 16px;
  }
}

@media (max-width: 520px) {
  .app-shell {
    padding: 12px 10px 24px;
    gap: 16px;
  }

  .topbar-link,
  .topbar-brand {
    text-align: center;
  }

  .topbar-brand {
    letter-spacing: 0.08em;
    font-size: 0.88rem;
  }

  .hero-card,
  .preview-panel,
  .output-panel,
  .info-panel,
  .preview-dialog {
    padding: 14px;
  }

  .eyebrow {
    letter-spacing: 0.14em;
    font-size: 0.72rem;
  }

  .hero-copy,
  .muted,
  .field span,
  .slider-field span,
  .toggle span {
    font-size: 0.9rem;
  }

  input[type="text"],
  button {
    padding: 11px 12px;
  }

  .output-actions {
    gap: 10px;
  }

  .layout-head-side {
    align-items: stretch;
  }

  .preview-toolbar {
    padding-top: 12px;
  }

  .canvas-scroller {
    max-height: 50vh;
  }
}
