
:root {
  --accent: #9b4a2d;
  --paper: #f1ece4;
  --ink: #242424;
  --muted: #77736e;
  --line: #dfd9cf;
  --control: #ffffff;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.24);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: #211f1d;
  font-family: Inter, Arial, Helvetica, sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

.app {
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  min-height: 100vh;
}

.mobile-tabs {
  display: none;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-height: 100vh;
  overflow: auto;
  padding: 28px;
  background: #f3efe7;
  border-right: 1px solid #ddd6ca;
}

.controls__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.controls h1,
.controls h2 {
  margin: 0;
}

.controls h1 {
  font-size: 28px;
  line-height: 1.05;
}

.controls h2 {
  grid-column: 1 / -1;
  font-size: 14px;
  color: var(--accent);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.back-link {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 38px;
  padding: 0 13px;
  color: #615d58;
  background: #fff;
  border: 1px solid #ded6cb;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.back-link::before {
  content: '<';
  margin-right: 8px;
  color: var(--accent);
}

.control-section {
  display: grid;
  gap: 12px;
  padding: 18px;
  background: var(--control);
  border: 1px solid #e5dfd5;
  border-radius: 12px;
}

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

.control-grid label:has(textarea),
.control-grid label:last-child {
  grid-column: 1 / -1;
}

label,
.file-field {
  display: grid;
  gap: 7px;
  min-width: 0;
  font-size: 12px;
  font-weight: 700;
  color: #615d58;
}

input[type='text'],
input[type='file'],
textarea {
  width: 100%;
  min-width: 0;
  padding: 10px 11px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #d9d2c8;
  border-radius: 7px;
}

textarea {
  resize: vertical;
}

input[type='color'] {
  width: 100%;
  height: 42px;
  padding: 4px;
  background: #fff;
  border: 1px solid #d9d2c8;
  border-radius: 7px;
}

.color-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.eyedropper-button {
  min-height: 42px;
  padding: 0 12px;
  color: var(--accent);
  background: #fff;
  border: 1px solid #d9d2c8;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 850;
  cursor: pointer;
}

.eyedropper-button:disabled {
  color: #aaa49d;
  cursor: not-allowed;
}

.eyedropper-button[hidden] {
  display: none;
}

.eyedropper-button.is-active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

input[type='range'] {
  width: 100%;
  accent-color: var(--accent);
}

.hint {
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
  color: #827d75;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  color: var(--accent);
  background: #fff;
  border: 1px solid #ded6cb;
  border-radius: 10px;
  cursor: pointer;
}

.export-button,
.download-link {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 12px 16px;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 12px;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

.download-link {
  color: var(--accent);
  background: #fff;
  border: 1px solid var(--accent);
}

.download-link[hidden] {
  display: none;
}

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

.option-row {
  display: grid;
  grid-template-columns: 18px minmax(96px, 0.8fr) minmax(150px, 1.2fr);
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: #fbfaf7;
  border: 1px solid #e4ded4;
  border-radius: 12px;
}

.option-row input[type='checkbox'] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.option-row span {
  color: #4f4b46;
  font-size: 12px;
  font-weight: 800;
}

.stage {
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 32px;
  overflow: auto;
}

.preview-tools {
  display: none;
}

.phone {
  width: min(405px, calc(100vw - 48px));
  aspect-ratio: 9 / 16;
  overflow: hidden;
  background: #000;
  box-shadow: var(--shadow);
  border-radius: 0;
}

.story-preview {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.stage.is-sampling .story-preview {
  cursor: crosshair;
  touch-action: none;
  user-select: none;
}

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

  .mobile-tabs {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 10px;
    background: #faf8f4;
    border-bottom: 1px solid #ddd6ca;
  }

  .mobile-tab {
    min-height: 42px;
    color: #615d58;
    background: #fff;
    border: 1px solid #ded6cb;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 850;
    cursor: pointer;
  }

  .mobile-tab.is-active {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
  }

  .controls {
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid #ddd6ca;
  }

  .stage {
    min-height: 760px;
  }

  .preview-tools {
    display: none;
  }

  .app[data-mobile-view='controls'] .stage,
  .app[data-mobile-view='preview'] .controls {
    display: none;
  }

  .app[data-mobile-view='preview'] .stage {
    grid-template-rows: auto minmax(0, 1fr);
    align-items: start;
    gap: 14px;
    min-height: calc(100vh - 63px);
  }

  .app[data-mobile-view='preview'] .preview-tools {
    position: sticky;
    top: 73px;
    z-index: 5;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: min(405px, calc(100vw - 36px));
    padding: 8px;
    background: rgba(250, 248, 244, .94);
    border: 1px solid #ddd6ca;
    border-radius: 8px;
  }

  .preview-tools .eyedropper-button {
    position: relative;
    width: 100%;
    padding-left: 34px;
  }

  .preview-tools .eyedropper-button::before {
    content: '';
    position: absolute;
    left: 10px;
    top: 50%;
    width: 16px;
    height: 16px;
    background: var(--sample-color, #ffffff);
    border: 1px solid rgba(0, 0, 0, .22);
    border-radius: 999px;
    transform: translateY(-50%);
  }

  .sample-hint {
    display: none;
    grid-column: 1 / -1;
    color: #615d58;
    font-size: 12px;
    font-weight: 800;
    text-align: center;
  }

  .stage.is-sampling .sample-hint {
    display: block;
  }
}

@media (max-width: 560px) {
  .controls {
    padding: 18px;
  }

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

  .stage {
    padding: 18px;
  }
}
