:root {
  color-scheme: dark;
  --bg: #101114;
  --panel: #191c22;
  --soft: #222733;
  --line: #343b48;
  --text: #f3f5f7;
  --muted: #a4acb8;
  --blue: #56b7ff;
  --green: #80d284;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

main {
  width: min(1480px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 22px 0 36px;
}

header,
.controls,
.layout,
.panel-head,
.presets {
  display: grid;
  gap: 12px;
}

header {
  grid-template-columns: 1fr auto;
  align-items: end;
  margin-bottom: 14px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
}

h2 {
  font-size: 17px;
}

p,
span {
  color: var(--muted);
}

button,
input,
select {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  background: var(--soft);
  font: inherit;
}

button {
  padding: 0 14px;
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--blue);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.controls {
  grid-template-columns: minmax(120px, 160px) repeat(4, minmax(112px, 160px)) 1fr;
  align-items: end;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.file-button {
  min-height: 38px;
  place-content: center;
  align-self: end;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  background: var(--soft);
  cursor: pointer;
  text-align: center;
}

.file-button.compact {
  min-height: 38px;
  padding: 0 12px;
  font-size: 13px;
}

.file-button:hover {
  border-color: var(--blue);
}

.file-button input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
}

input {
  width: 100%;
  padding: 0 10px;
  background: #111319;
}

select {
  width: 100%;
  padding: 0 10px;
  background: #111319;
}

label:has(span) {
  grid-template-columns: 1fr 28px;
}

label:has(span) input,
label:has(span) span {
  grid-row: 2;
}

label:has(span) span {
  align-self: center;
}

.presets {
  grid-template-columns: repeat(5, auto);
  justify-content: end;
}

.layout {
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.9fr);
  align-items: start;
  margin-top: 14px;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}

.panel-head {
  grid-template-columns: 1fr auto;
  align-items: center;
  min-height: 56px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: end;
}

.source-history {
  width: 132px;
}

canvas {
  display: block;
  width: 100%;
  background: #0c0d10;
}

canvas[hidden] {
  display: none;
}

#preview {
  aspect-ratio: 16 / 10;
  cursor: crosshair;
}

.drop-zone {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 160px;
  padding: 24px;
  text-align: center;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(135deg, rgba(86, 183, 255, 0.12), transparent 35%),
    #12151b;
}

.drop-zone.is-hidden {
  display: none;
}

.drop-zone.is-over {
  outline: 2px solid var(--blue);
  outline-offset: -8px;
}

.drop-zone strong {
  font-size: 20px;
}

.drop-zone span {
  max-width: 520px;
  line-height: 1.5;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
  max-height: calc(100vh - 210px);
  overflow: auto;
  padding: 14px;
}

.tiles:empty {
  display: none;
}

.stitch-status {
  padding: 10px 14px 0;
  font-size: 13px;
  line-height: 1.45;
}

.stitch-result {
  display: grid;
  gap: 8px;
  margin: 14px 14px 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #12151b;
}

.stitch-result.is-fullscreen {
  position: fixed;
  inset: 12px;
  z-index: 1000;
  margin: 0;
  padding: 14px;
  background: #101114;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.65);
}

.stitch-result[hidden] {
  display: none;
}

.stitch-result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.stitch-result h3 {
  margin: 0;
  font-size: 14px;
}

#closeFullscreenStitch {
  display: none;
}

.stitch-result.is-fullscreen #closeFullscreenStitch {
  display: inline-block;
}

.stitch-preview {
  max-height: 420px;
  object-fit: contain;
  border-radius: 6px;
  cursor: grab;
  touch-action: none;
}

.stitch-result.is-fullscreen .stitch-preview {
  width: 100%;
  height: calc(100vh - 86px);
  max-height: none;
  object-fit: contain;
}

.stitch-preview:active {
  cursor: grabbing;
}

.tile {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #12151b;
  overflow: hidden;
}

.tile canvas {
  aspect-ratio: 16 / 10;
  object-fit: contain;
}

.tile footer {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.tile strong {
  font-size: 13px;
}

.tile small {
  color: var(--muted);
}

.tile-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.brand-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 14px;
  padding: 12px 2px 0;
  border-top: 1px solid var(--line);
  color: #747d8b;
  font-size: 13px;
}

.brand-footer a {
  color: #8d97a6;
  text-decoration: none;
  transition:
    color 120ms ease,
    text-decoration-color 120ms ease;
}

.brand-footer a:hover {
  color: var(--blue);
  text-decoration: underline;
  text-decoration-color: rgba(86, 183, 255, 0.45);
  text-underline-offset: 3px;
}

.brand-divider {
  color: #4c5563;
}

.brand-author {
  position: relative;
  color: #8d97a6;
}

.brand-author-button {
  min-height: auto;
  padding: 0;
  border: 0;
  border-radius: 0;
  color: #8d97a6;
  background: transparent;
  font: inherit;
  cursor: pointer;
  transition: color 120ms ease;
}

.brand-author-button:hover,
.brand-author-button:focus {
  color: var(--blue);
  text-decoration: underline;
  text-decoration-color: rgba(86, 183, 255, 0.45);
  text-underline-offset: 3px;
}

.brand-note {
  position: absolute;
  left: 50%;
  bottom: 24px;
  z-index: 20;
  display: grid;
  gap: 8px;
  width: 260px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: #344054;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.38);
  font-size: 12px;
  line-height: 1.5;
  text-align: left;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 6px);
  transition:
    opacity 120ms ease,
    transform 120ms ease;
}

.brand-note strong {
  color: #101828;
  font-size: 13px;
}

.brand-author.is-open .brand-note {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, 0);
}

@media (max-width: 900px) {
  header,
  .controls,
  .layout {
    grid-template-columns: 1fr;
  }

  .presets {
    justify-content: start;
  }
}
