:root {
  color-scheme: dark;
  --bg: #101114;
  --panel: #181a1f;
  --panel-2: #20232a;
  --line: #30343d;
  --text: #f3f4f6;
  --muted: #9ca3af;
  --accent: #f5b642;
  --danger: #ffb86b;
  --shadow: 0 18px 55px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button,
.import-label {
  border: 1px solid #3c414c;
  border-radius: 8px;
  background: #f4f4f0;
  color: #101114;
  min-height: 38px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 700;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

button:hover,
.import-label:hover {
  transform: translateY(-1px);
}

button.secondary,
button.ghost,
.import-label.ghost {
  background: #242831;
  color: var(--text);
}

button.ghost,
.import-label.ghost {
  border-color: #343944;
}

button.small,
.import-label.small {
  min-height: 31px;
  padding: 0 10px;
  font-size: 12px;
}

button.wide {
  width: 100%;
}

select,
input[type="text"],
input[type="number"] {
  min-height: 38px;
  border: 1px solid #343944;
  border-radius: 8px;
  background: #111318;
  color: var(--text);
  padding: 0 10px;
}

.wide-select {
  width: 100%;
  margin-bottom: 8px;
}

input[type="color"] {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  background: transparent;
}

.app-shell {
  width: min(1560px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 42px;
}

.topbar,
.section-title,
.inline-actions,
.preview-meta,
.export-row,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar {
  justify-content: space-between;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 56px);
  line-height: 0.95;
  letter-spacing: 0;
}

h2 {
  font-size: 15px;
  letter-spacing: 0;
}

.code-pill {
  border: 1px solid #3b414e;
  border-radius: 8px;
  padding: 10px 13px;
  background: #171a20;
  color: #f4f4f0;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-weight: 800;
  white-space: nowrap;
}

.id-stack {
  display: grid;
  gap: 5px;
  justify-items: end;
}

.iteration-id,
.proposal-id {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  letter-spacing: 0;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 16px;
  align-items: start;
}

.preview-panel,
.control-panel,
.proposals-section,
.saved-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.preview-panel {
  padding: 14px;
}

.preview-frame {
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  aspect-ratio: 16 / 9;
}

.logo-preview,
.logo-preview svg,
.proposal-logo svg {
  display: block;
  width: 100%;
  height: 100%;
}

.preview-meta {
  justify-content: space-between;
  min-height: 42px;
  padding-top: 12px;
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

.warning {
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
}

.control-panel {
  padding: 14px;
}

.panel-section + .panel-section {
  border-top: 1px solid var(--line);
  margin-top: 14px;
  padding-top: 14px;
}

.section-title {
  justify-content: space-between;
  margin-bottom: 10px;
}

.role-controls {
  display: grid;
  gap: 8px;
}

.role-button {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  width: 100%;
  padding: 0 10px;
  border-radius: 8px;
  background: #111318;
  color: var(--text);
  border: 1px solid #303640;
  text-align: left;
}

.role-button.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(245, 182, 66, 0.12);
}

.role-dot,
.mini-swatch,
.color-chip {
  border: 1px solid rgba(255, 255, 255, 0.35);
}

.role-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
}

.role-name {
  font-weight: 800;
}

.role-hex {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

.palette-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.swatch-card {
  border: 1px solid #303640;
  border-radius: 8px;
  background: #111318;
  padding: 8px;
}

.swatch-button {
  width: 100%;
  height: 46px;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  padding: 0;
}

.swatch-card.used .swatch-button {
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.28);
}

.swatch-meta {
  display: grid;
  grid-template-columns: 1fr 36px;
  gap: 6px;
  align-items: center;
  margin-top: 7px;
}

.swatch-meta input[type="text"] {
  min-width: 0;
  min-height: 31px;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.load-id-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 8px;
}

.palette-actions {
  margin-bottom: 8px;
}

.mobile-quick-actions {
  display: none;
}

.export-row {
  margin-bottom: 8px;
}

.export-row select {
  flex: 1;
}

.quality-row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.proposals-section,
.saved-section {
  margin-top: 16px;
  padding: 14px;
}

.proposal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}

.proposal-card,
.saved-card {
  border: 1px solid #303640;
  border-radius: 8px;
  background: var(--panel-2);
}

.proposal-card {
  overflow: hidden;
  cursor: pointer;
}

.proposal-logo {
  aspect-ratio: 16 / 9;
  background: #fff;
}

.proposal-body,
.saved-card {
  padding: 10px;
}

.color-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  margin: 8px 0;
}

.color-chip {
  height: 22px;
  border-radius: 5px;
}

.card-code {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  color: #d7d9de;
}

.card-actions,
.saved-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 9px;
}

.saved-presets {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.saved-card.favorite {
  border-color: var(--accent);
}

.saved-name {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-weight: 800;
  margin-bottom: 4px;
}

.saved-card input.rename-input {
  width: 100%;
  margin: 8px 0 2px;
}

.import-label {
  display: inline-flex;
  align-items: center;
}

.import-label input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 1px;
  height: 1px;
}

.preset-dialog {
  width: min(420px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 18px;
}

.preset-dialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
}

.preset-dialog form {
  display: grid;
  gap: 14px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  border: 1px solid #3b414e;
  border-radius: 8px;
  background: #f4f4f0;
  color: #101114;
  padding: 10px 13px;
  font-weight: 800;
  box-shadow: var(--shadow);
  z-index: 20;
}

@media (min-width: 981px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  button,
  .import-label {
    min-height: 34px;
    padding: 0 11px;
  }

  select,
  input[type="text"],
  input[type="number"] {
    min-height: 34px;
  }

  .app-shell {
    width: calc(100vw - 20px);
    height: 100dvh;
    max-width: none;
    padding: 10px 0;
    display: grid;
    grid-template-columns: minmax(520px, 1.35fr) 360px minmax(360px, 0.95fr);
    grid-template-rows: 48px minmax(0, 1fr) minmax(0, 0.82fr);
    gap: 10px;
  }

  .topbar {
    grid-column: 1 / -1;
    margin: 0;
    min-height: 0;
  }

  .eyebrow {
    display: none;
  }

  h1 {
    font-size: 30px;
  }

  .code-pill {
    padding: 8px 11px;
  }

  .workspace {
    display: contents;
  }

  .preview-panel {
    grid-column: 1;
    grid-row: 2 / 4;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 10px;
  }

  .preview-frame {
    flex: 0 0 auto;
    width: 100%;
    aspect-ratio: 16 / 9;
  }

  .preview-meta {
    min-height: 32px;
    padding-top: 8px;
  }

  .control-panel {
    grid-column: 2;
    grid-row: 2 / 4;
    min-height: 0;
    overflow: auto;
    padding: 10px;
  }

  .panel-section + .panel-section {
    margin-top: 10px;
    padding-top: 10px;
  }

  .section-title {
    margin-bottom: 7px;
  }

  .role-controls {
    gap: 6px;
  }

  .role-button {
    min-height: 38px;
    grid-template-columns: 20px 1fr auto;
    gap: 8px;
  }

  .role-dot {
    width: 20px;
    height: 20px;
  }

  .palette-grid {
    gap: 6px;
  }

  .swatch-card {
    padding: 6px;
  }

  .swatch-button {
    height: 32px;
  }

  .swatch-meta {
    grid-template-columns: 1fr 30px;
    gap: 5px;
    margin-top: 5px;
  }

  .swatch-meta input[type="text"] {
    min-height: 27px;
  }

  input[type="color"] {
    width: 30px;
    height: 30px;
  }

  .button-grid,
  .export-row {
    gap: 6px;
  }

  .quality-row {
    margin-top: 7px;
  }

  .proposals-section {
    grid-column: 3;
    grid-row: 2;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 10px;
  }

  .proposal-grid {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 260px;
    grid-template-columns: none;
    grid-template-rows: 1fr;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    min-height: 0;
    padding: 0 2px 8px 0;
    scroll-snap-type: x proximity;
  }

  .proposal-card {
    display: flex;
    flex-direction: column;
    min-width: 0;
    scroll-snap-align: start;
  }

  .proposal-logo {
    flex: 0 0 auto;
    width: 100%;
    aspect-ratio: 16 / 9;
  }

  .proposal-body {
    flex: 0 0 auto;
    padding: 7px;
  }

  .color-strip {
    gap: 4px;
    margin: 6px 0;
  }

  .color-chip {
    height: 16px;
  }

  .card-actions {
    gap: 5px;
    margin-top: 6px;
  }

  .card-actions button.small {
    flex: 1;
    min-height: 27px;
    padding: 0 7px;
  }

  .saved-section {
    grid-column: 3;
    grid-row: 3;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 10px;
  }

  .saved-presets {
    grid-template-columns: 1fr;
    gap: 8px;
    overflow: auto;
    min-height: 0;
    padding-right: 2px;
  }

  .saved-card {
    padding: 8px;
  }

  .saved-card input.rename-input {
    min-height: 30px;
    margin: 6px 0 1px;
  }

  .saved-actions {
    gap: 5px;
    margin-top: 7px;
  }

  .saved-actions button.small {
    min-height: 27px;
    padding: 0 7px;
  }
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 20px, 1560px);
    padding-top: 16px;
  }

  .topbar,
  .section-title,
  .inline-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar {
    gap: 10px;
    margin-bottom: 12px;
  }

  h1 {
    font-size: 30px;
  }

  .preview-panel {
    padding: 10px;
  }

  .preview-frame {
    border-radius: 7px;
  }

  .preview-meta {
    align-items: flex-start;
    gap: 6px;
    min-height: 0;
    padding-top: 8px;
  }

  .mobile-quick-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 10px;
  }

  .control-panel {
    box-shadow: none;
  }

  .code-pill {
    width: 100%;
    text-align: center;
  }

  .id-stack {
    width: 100%;
    justify-items: stretch;
  }

  .iteration-id {
    text-align: center;
  }

  .load-id-row {
    grid-template-columns: 1fr;
  }

  .palette-grid,
  .button-grid,
  .saved-presets {
    grid-template-columns: 1fr;
  }
}
