:root {
  --ink: #22211f;
  --muted: #6c6760;
  --paper: #fff8ea;
  --line: #22211f;
  --white: #ffffff;
  --mint: #84dcc6;
  --coral: #ff826b;
  --yellow: #ffd56f;
  --blue: #82a9ff;
  --green: #9bd46a;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(90deg, rgba(34, 33, 31, 0.07) 1px, transparent 1px),
    linear-gradient(rgba(34, 33, 31, 0.07) 1px, transparent 1px),
    var(--paper);
  background-size: 30px 30px;
  -webkit-tap-highlight-color: rgba(255, 130, 107, 0.22);
}

button,
input {
  font: inherit;
}

input {
  min-width: 0;
  min-height: 48px;
  padding: 0 12px;
  border: 2px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--white);
  font-weight: 800;
}

button {
  appearance: none;
  border: 2px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--white);
  cursor: pointer;
  font-weight: 900;
  touch-action: manipulation;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

button:hover {
  transform: translate(-2px, -2px);
  box-shadow: 5px 5px 0 var(--ink);
}

button:active {
  transform: translate(0, 0);
  box-shadow: 2px 2px 0 var(--ink);
}

.shell {
  width: min(1180px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(340px, 0.65fr);
  gap: 24px;
  align-items: stretch;
  padding: 32px 0;
}

.studio,
.result-panel {
  border: 3px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 10px 10px 0 var(--ink);
}

.studio {
  padding: clamp(22px, 4vw, 42px);
}

.masthead {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 18px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 1000;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(46px, 7vw, 88px);
  line-height: 0.95;
  letter-spacing: 0;
}

.lead {
  max-width: 520px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.6;
  font-weight: 800;
}

.stamp,
.result-code {
  width: max-content;
  padding: 8px 12px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--mint);
  font-weight: 1000;
}

.quick-steps {
  margin: 0 0 20px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.quick-steps span {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: #f0fbff;
  font-size: 14px;
  font-weight: 1000;
}

.workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 270px;
  gap: 20px;
}

.upload-zone {
  position: relative;
  min-height: 540px;
  display: grid;
  place-items: center;
  border: 3px dashed var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 213, 111, 0.34), transparent 42%),
    linear-gradient(315deg, rgba(132, 220, 198, 0.32), transparent 48%),
    var(--white);
  overflow: hidden;
}

.upload-zone.dragging {
  background: #e9fff9;
}

.upload-zone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 2;
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 10px;
  text-align: center;
  pointer-events: none;
  padding: 24px;
}

.empty-state strong {
  font-size: 34px;
  line-height: 1;
}

.empty-state span {
  color: var(--muted);
  font-weight: 900;
}

.upload-icon {
  width: 112px;
  height: 112px;
  border: 3px solid var(--line);
  border-radius: 18px;
  background:
    radial-gradient(circle at 73% 30%, var(--coral) 0 13px, transparent 14px),
    linear-gradient(135deg, transparent 50%, var(--blue) 51% 66%, transparent 67%),
    var(--yellow);
  box-shadow: 7px 7px 0 var(--ink);
}

#previewImage {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.upload-zone.has-image #previewImage {
  display: block;
}

.upload-zone.has-image .empty-state {
  display: none;
}

.signal-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.mobile-note {
  margin: -6px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
  font-weight: 850;
}

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

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--yellow);
  flex: 0 0 auto;
}

.panel-title {
  margin: 0;
  font-size: 22px;
  line-height: 1.1;
}

.chip-grid {
  display: grid;
  gap: 10px;
}

.chip-grid button {
  min-height: 46px;
  padding: 0 12px;
  text-align: left;
  line-height: 1.2;
}

.chip-grid button.active {
  background: var(--green);
}

.primary {
  min-height: 54px;
  margin-top: auto;
  padding: 0 16px;
  background: var(--coral);
  font-size: 17px;
}

.secondary,
.poster-download {
  min-height: 54px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--yellow);
  font-size: 17px;
  font-weight: 900;
  text-decoration: none;
}

.result-panel {
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.result-panel h2 {
  margin-bottom: 0;
  font-size: clamp(34px, 5vw, 58px);
  line-height: 1;
}

.result-panel p {
  color: var(--muted);
  font-size: 18px;
  line-height: 1.65;
}

.metrics {
  display: grid;
  gap: 12px;
  margin-top: 4px;
}

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

.metric-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  font-weight: 1000;
  color: var(--muted);
}

.bar {
  height: 13px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--white);
  overflow: hidden;
}

.bar span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--mint), var(--blue), var(--coral));
  transition: width 280ms ease;
}

.insight-list {
  display: grid;
  gap: 10px;
  margin-top: auto;
}

.insight {
  padding: 13px 14px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff4d3;
  font-weight: 850;
  line-height: 1.55;
}

.share-card,
.link-card {
  padding: 16px;
  display: grid;
  gap: 14px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #f0fbff;
}

.share-card.hidden {
  display: none;
}

.share-preview {
  display: grid;
  grid-template-columns: 116px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
}

.share-preview img {
  width: 116px;
  aspect-ratio: 1;
  object-fit: cover;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--white);
}

.share-preview span {
  width: max-content;
  margin-bottom: 8px;
  padding: 6px 10px;
  display: inline-flex;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--mint);
  font-weight: 1000;
}

.share-preview strong,
.link-card h3 {
  display: block;
  margin: 0;
  color: var(--ink);
  font-size: 24px;
  line-height: 1.1;
  font-weight: 1000;
}

.share-preview p,
.save-note,
.poster-sheet p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
  font-weight: 850;
}

.result-actions,
.poster-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.link-card {
  background: #e8fff9;
}

.link-card > img {
  width: min(220px, 70%);
  margin: 0 auto;
  display: block;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--white);
}

.copy-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.promo-banner {
  display: block;
  overflow: hidden;
  border-radius: 0;
}

.promo-banner img {
  display: block;
  width: 100%;
  height: auto;
}

.poster-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  padding: 18px;
  display: grid;
  place-items: center;
  background: rgba(34, 33, 31, 0.68);
}

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

.poster-sheet {
  width: min(430px, 100%);
  max-height: min(92vh, 820px);
  padding: 14px;
  display: grid;
  gap: 12px;
  overflow: auto;
  border: 3px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  box-shadow: 8px 8px 0 var(--ink);
}

#posterImage {
  width: 100%;
  display: block;
  border: 2px solid var(--line);
  border-radius: 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 30;
  max-width: min(340px, calc(100% - 32px));
  padding: 11px 14px;
  border: 2px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  background: var(--yellow);
  box-shadow: 4px 4px 0 var(--ink);
  font-size: 14px;
  font-weight: 900;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 180ms ease, transform 180ms ease;
}

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

#analysisCanvas,
#posterCanvas {
  display: none;
}

@media (max-width: 940px) {
  .shell,
  .workbench {
    grid-template-columns: 1fr;
  }

  .shell {
    align-items: start;
    max-width: 560px;
  }

  .upload-zone {
    min-height: 0;
    aspect-ratio: 4 / 5;
  }

  .studio,
  .result-panel {
    box-shadow: 7px 7px 0 var(--ink);
  }
}

@media (max-width: 560px) {
  body {
    background-size: 22px 22px;
  }

  .shell {
    width: min(100% - 16px, 520px);
    gap: 12px;
    padding: 8px 0 calc(24px + env(safe-area-inset-bottom));
  }

  .studio,
  .result-panel {
    border-width: 2px;
    box-shadow: 5px 5px 0 var(--ink);
  }

  .studio {
    padding: 16px;
  }

  .masthead {
    display: flex;
    align-items: start;
    gap: 12px;
    margin-bottom: 14px;
  }

  .eyebrow {
    margin-bottom: 6px;
    font-size: 11px;
  }

  h1 {
    font-size: clamp(36px, 13vw, 54px);
  }

  .lead {
    margin-top: 8px;
    font-size: 15px;
    line-height: 1.45;
  }

  .stamp {
    padding: 6px 9px;
    font-size: 12px;
  }

  .quick-steps {
    margin-bottom: 14px;
    gap: 7px;
  }

  .quick-steps span {
    min-height: 36px;
    padding: 0 8px;
    font-size: 13px;
  }

  .workbench {
    gap: 12px;
  }

  .upload-zone {
    aspect-ratio: 1 / 1.08;
    max-height: 48svh;
    border-width: 2px;
    border-style: solid;
  }

  .upload-zone.has-image #previewImage {
    object-fit: contain;
    background: #f7f0df;
  }

  .upload-icon {
    width: 86px;
    height: 86px;
    border-radius: 14px;
    box-shadow: 5px 5px 0 var(--ink);
  }

  .empty-state strong {
    font-size: 26px;
  }

  .empty-state span {
    font-size: 14px;
  }

  .signal-panel {
    gap: 12px;
    padding: 14px;
    border: 2px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.76);
  }

  .panel-head {
    align-items: end;
  }

  .icon-btn {
    width: 42px;
    height: 42px;
  }

  .panel-title {
    font-size: 21px;
  }

  .mobile-note {
    margin: -4px 0 0;
    font-size: 14px;
  }

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

  .chip-grid button {
    min-height: 48px;
    padding: 0 10px;
    text-align: center;
    font-size: 14px;
    line-height: 1.2;
  }

  .primary {
    width: 100%;
    min-height: 56px;
    margin-top: 2px;
    font-size: 18px;
  }

  .secondary,
  .poster-download {
    min-height: 56px;
    font-size: 16px;
  }

  .result-panel {
    padding: 18px;
    gap: 14px;
  }

  .result-top {
    align-items: start;
  }

  .result-code {
    padding: 7px 10px;
    font-size: 13px;
  }

  .result-panel h2 {
    font-size: clamp(32px, 11vw, 46px);
  }

  .result-panel p {
    font-size: 16px;
    line-height: 1.58;
  }

  .metrics {
    gap: 10px;
  }

  .insight-list {
    margin-top: 0;
  }

  .insight {
    padding: 12px;
    font-size: 15px;
  }

  .share-card,
  .link-card {
    padding: 14px;
    gap: 12px;
  }

  .share-preview {
    grid-template-columns: 94px minmax(0, 1fr);
    gap: 12px;
  }

  .share-preview img {
    width: 94px;
  }

  .share-preview strong,
  .link-card h3 {
    font-size: 21px;
  }

  .copy-row,
  .result-actions,
  .poster-actions {
    grid-template-columns: 1fr;
  }
}

@media (hover: none) {
  button:hover {
    transform: none;
    box-shadow: none;
  }
}
