:root {
  color-scheme: light;
  --bg: #f3f5f5;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --surface-muted: #f6f8f9;
  --surface-hover: #eef6fb;
  --text: #192d3c;
  --muted: #8496a3;
  --muted-strong: #607786;
  --line: #d9e2e7;
  --line-strong: #bdcbd3;
  --accent: #55acee;
  --accent-strong: #2d94d8;
  --accent-soft: #e6f4fe;
  --selection: #2d94d8;
  --action: #d3dee5;
  --danger: #d75b67;
  --shadow: 0 10px 30px rgba(25, 45, 60, 0.045);
  --timeline-bg: #ffffff;
  --timeline-text: #0f1419;
  --timeline-muted: #536471;
  --timeline-border: #cfd9de;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1113;
  --surface: #171b1e;
  --surface-raised: #1b2024;
  --surface-muted: #20262a;
  --surface-hover: #202d35;
  --text: #edf2f4;
  --muted: #83929c;
  --muted-strong: #a4b1b9;
  --line: #2c3439;
  --line-strong: #414b52;
  --accent: #62b5f0;
  --accent-strong: #7fc6f7;
  --accent-soft: #172b37;
  --selection: #7fc6f7;
  --action: #52616a;
  --danger: #ee7780;
  --shadow: 0 12px 34px rgba(0, 0, 0, 0.18);
  --timeline-bg: #000000;
  --timeline-text: #e7e9ea;
  --timeline-muted: #71767b;
  --timeline-border: #2f3336;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  transition: background-color 160ms ease, color 160ms ease;
}

button,
input,
select {
  font: inherit;
}

button,
label,
select {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

button:focus-visible,
select:focus-visible,
#fileInput:focus-visible + .drop-zone {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.app-bar {
  height: 58px;
  padding: 0 clamp(18px, 4vw, 52px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.025em;
  text-decoration: none;
}

.brand-mark {
  width: 29px;
  height: 29px;
  display: grid;
  place-items: center;
  border-radius: 6px 6px 6px 2px;
  background: var(--accent);
  color: white;
  font-size: 13px;
  font-weight: 800;
}

.theme-toggle {
  display: flex;
  align-items: center;
}

.theme-toggle {
  width: 34px;
  height: 34px;
  padding: 0;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface-muted);
  color: var(--muted-strong);
  font-size: 11px;
  font-weight: 650;
  cursor: pointer;
}

.theme-toggle:hover {
  border-color: var(--line-strong);
  background: var(--surface-hover);
  color: var(--text);
}

.theme-icon {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-icon--moon {
  display: none;
}

:root[data-theme="dark"] .theme-icon--sun {
  display: none;
}

:root[data-theme="dark"] .theme-icon--moon {
  display: block;
}

.app {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.subheading-row,
.preview-size {
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.editor {
  min-height: 710px;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.controls {
  min-width: 0;
  padding: 20px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.pane-heading {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.pane-heading h1,
.pane-heading h2 {
  margin: 0;
  font-size: 19px;
  font-weight: 650;
  line-height: 1;
  letter-spacing: -0.035em;
}

.photo-count {
  padding: 0;
  border: 0;
  color: var(--muted-strong);
  background: transparent;
  font-size: 10px;
  font-weight: 700;
}

.drop-zone {
  min-height: 112px;
  margin-top: 12px;
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
  background: var(--surface-muted);
  cursor: pointer;
  transition: 150ms ease;
}

.drop-zone:hover,
.drop-zone.is-dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
}

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

.upload-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.upload-icon svg {
  width: 17px;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.drop-zone > span:last-child {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

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

.drop-zone small {
  color: var(--muted);
  font-size: 10px;
}

.demo-button {
  width: 100%;
  height: 37px;
  margin-top: 8px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted-strong);
  font-size: 10px;
  font-weight: 650;
  cursor: pointer;
}

.demo-button:hover {
  background: var(--surface-muted);
  color: var(--accent-strong);
}

.photo-list-wrap,
.crop-controls {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.subheading-row {
  margin-bottom: 11px;
  display: flex;
  justify-content: space-between;
}

.photo-list {
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  list-style: none;
}

.photo-row {
  min-width: 0;
  height: 50px;
  padding: 5px 5px 5px 7px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
  cursor: pointer;
}

.row-select {
  min-width: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 18px 38px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.photo-row:hover {
  border-color: var(--line-strong);
}

.photo-row.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--selection);
}

.row-number {
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
  text-align: center;
}

.row-thumb {
  width: 38px;
  height: 38px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--line);
}

.row-name {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.row-name strong {
  overflow: hidden;
  font-size: 10px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-actions {
  display: flex;
  gap: 1px;
  opacity: 0.45;
  transition: opacity 120ms ease;
}

.photo-row:hover .row-actions,
.photo-row:focus-within .row-actions,
.photo-row.is-selected .row-actions {
  opacity: 1;
}

.icon-button {
  width: 23px;
  height: 23px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
}

.icon-button:hover:not(:disabled) {
  background: var(--surface);
  color: var(--accent-strong);
}

.icon-button:disabled {
  opacity: 0.25;
  cursor: default;
}

.icon-button--remove:hover:not(:disabled) {
  color: var(--danger);
}

.add-more {
  width: 100%;
  height: 36px;
  margin-top: 7px;
  border: 1px dashed var(--line-strong);
  border-radius: 7px;
  background: transparent;
  color: var(--muted-strong);
  font-size: 10px;
  font-weight: 650;
  cursor: pointer;
}

.add-more:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.reset-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent-strong);
  font-size: 9px;
  font-weight: 700;
  cursor: pointer;
  text-transform: uppercase;
}

.zoom-control {
  display: grid;
  grid-template-columns: 14px 1fr 14px;
  align-items: center;
  gap: 8px;
}

.zoom-control > span {
  width: 14px;
  height: 20px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 12px;
}

input[type="range"] {
  width: 100%;
  height: 3px;
  appearance: none;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent) var(--range-progress, 0%), var(--line) var(--range-progress, 0%));
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  width: 15px;
  height: 15px;
  appearance: none;
  border: 4px solid var(--surface);
  border-radius: 50%;
  background: var(--selection);
  box-shadow: 0 0 0 1px var(--line-strong);
  cursor: ew-resize;
}

input[type="range"]::-moz-range-thumb {
  width: 8px;
  height: 8px;
  border: 4px solid var(--surface);
  border-radius: 50%;
  background: var(--selection);
  cursor: ew-resize;
}

.crop-hint {
  margin: 11px 0 0;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.45;
}

.preview {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface-muted);
}

.preview-heading {
  min-height: 64px;
  padding: 0 26px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.preview-size {
  align-self: center;
}

.tweet-stage {
  min-height: 500px;
  padding: clamp(26px, 4vw, 44px);
  display: grid;
  place-items: center;
  flex: 1;
  background: var(--surface-muted);
}

.tweet {
  width: min(100%, 600px);
  padding: 12px 16px 8px;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  align-items: start;
  gap: 12px;
  border: 1px solid var(--timeline-border);
  background: var(--timeline-bg);
  color: var(--timeline-text);
}

.avatar {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #536471;
  color: white;
  font-size: 15px;
  font-weight: 800;
}

.tweet-content {
  min-width: 0;
}

.tweet-author {
  display: flex;
  align-items: baseline;
  gap: 4px;
  min-width: 0;
}

.tweet-author strong {
  font-size: 15px;
  line-height: 20px;
  letter-spacing: -0.01em;
}

.tweet-author span {
  min-width: 0;
  overflow: hidden;
  color: var(--timeline-muted);
  font-size: 15px;
  line-height: 20px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tweet-more {
  width: 18px;
  height: 18px;
  margin-left: auto;
  flex: 0 0 auto;
  fill: var(--timeline-muted);
}

.tweet-copy {
  margin: 1px 0 10px;
  font-size: 15px;
  line-height: 20px;
}

.tweet-actions {
  width: 100%;
  height: 28px;
  margin-top: 6px;
  padding: 0 8px 0 2px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--timeline-muted);
}

.tweet-actions svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.classic-grid {
  width: 100%;
  aspect-ratio: 16 / 9;
  display: grid;
  gap: 2px;
  overflow: hidden;
  border: 1px solid var(--timeline-border);
  border-radius: 16px;
  background: var(--timeline-bg);
  user-select: none;
  touch-action: none;
}

.classic-grid[data-count="1"] {
  grid-template-columns: 1fr;
}

.classic-grid[data-count="2"],
.classic-grid[data-count="4"] {
  grid-template-columns: repeat(2, 1fr);
}

.classic-grid[data-count="4"] {
  grid-template-rows: repeat(2, 1fr);
}

.classic-grid[data-count="3"] {
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
}

.classic-grid[data-count="3"] > :first-child {
  grid-row: 1 / 3;
}

.photo-cell,
.empty-cell {
  min-width: 0;
  min-height: 0;
  border: 0;
  position: relative;
  overflow: hidden;
}

.photo-cell {
  padding: 0;
  background: var(--timeline-border);
  cursor: grab;
}

.photo-cell:active {
  cursor: grabbing;
}

.photo-cell img {
  max-width: none;
  position: absolute;
  pointer-events: none;
  -webkit-user-drag: none;
}

.photo-cell::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  box-shadow: inset 0 0 0 0 var(--accent);
  pointer-events: none;
}

.photo-cell:focus-visible::before {
  box-shadow: inset 0 0 0 3px var(--accent);
}

.empty-cell {
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--timeline-border) 72%, var(--timeline-bg));
  color: var(--timeline-muted);
  cursor: pointer;
}

.empty-cell span {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 1px dashed currentColor;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
}

.export-bar {
  min-height: 64px;
  padding: 12px 26px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.export-actions {
  display: flex;
}

.export-button {
  height: 40px;
  padding: 0 15px;
  display: flex;
  align-items: center;
  gap: 15px;
  border: 0;
  border-radius: 8px;
  background: var(--text);
  color: var(--surface);
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
}

.export-button svg {
  width: 16px;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.export-button:hover:not(:disabled) {
  background: var(--accent-strong);
  color: white;
}

.export-button:disabled {
  background: var(--line-strong);
  color: var(--surface-muted);
  cursor: not-allowed;
}

.toast {
  max-width: min(420px, calc(100% - 34px));
  padding: 11px 15px;
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 100;
  border: 1px solid color-mix(in srgb, var(--surface) 20%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--text) 95%, transparent);
  color: var(--surface);
  font-size: 10px;
  font-weight: 650;
  opacity: 0;
  transform: translate(-50%, 10px);
  pointer-events: none;
  transition: 180ms ease;
}

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

@media (max-width: 950px) {
  .app {
    width: min(calc(100% - 28px), 760px);
  }

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

  .controls {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 600px) {
  .app-bar {
    height: 54px;
    padding: 0 14px;
  }

  .app {
    width: calc(100% - 20px);
    padding-top: 10px;
  }

  .editor {
    border-radius: 11px;
  }

  .controls {
    padding: 22px 18px;
  }

  .preview-heading {
    min-height: 58px;
    padding: 0 18px;
  }

  .preview-size {
    display: none;
  }

  .tweet-stage {
    min-height: 420px;
    padding: 24px 8px;
  }

  .tweet {
    padding: 10px 8px 6px;
    grid-template-columns: 40px minmax(0, 1fr);
    gap: 10px;
  }

  .avatar {
    width: 40px;
    height: 40px;
  }

  .tweet-author strong {
    font-size: 15px;
  }

  .tweet-author span {
    font-size: 14px;
  }

  .tweet-copy {
    margin-top: 1px;
    font-size: 14px;
  }

  .tweet-actions {
    width: 100%;
  }

  .tweet-actions svg {
    width: 16px;
    height: 16px;
  }

  .classic-grid {
    gap: 2px;
    border-radius: 16px;
  }

  .export-bar {
    padding: 12px 18px;
  }
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e1113;
    --surface: #171b1e;
    --surface-raised: #1b2024;
    --surface-muted: #20262a;
    --surface-hover: #202d35;
    --text: #edf2f4;
    --muted: #83929c;
    --muted-strong: #a4b1b9;
    --line: #2c3439;
    --line-strong: #414b52;
    --accent: #62b5f0;
    --accent-strong: #7fc6f7;
    --accent-soft: #172b37;
    --selection: #7fc6f7;
    --action: #52616a;
    --danger: #ee7780;
    --shadow: 0 12px 34px rgba(0, 0, 0, 0.18);
    --timeline-bg: #000000;
    --timeline-text: #e7e9ea;
    --timeline-muted: #71767b;
    --timeline-border: #2f3336;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
