:root {
  --bg: #f5f2e8;
  --bg-soft: #fbf9f2;
  --card: #fffdf6;
  --text: #111c2d;
  --muted: #5b6577;
  --border: #d9d3c2;
  --border-strong: #b6ac97;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --accent-ink: #edfffb;
  --warm: #ff764a;
  --dangerBg: #fff1ee;
  --dangerBorder: #f7beb2;
  --dangerText: #a6331a;
  --safePad: env(safe-area-inset-bottom, 0px);
  --shadow-sm: 0 10px 24px rgba(27, 37, 55, 0.08);
  --shadow-lg: 0 22px 44px rgba(27, 37, 55, 0.16);
  --radius-card: 22px;
  --radius-ui: 14px;
  --max-wrap: 1060px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 90% 4%, #fdeed6 0%, rgba(253, 238, 214, 0) 33%),
    radial-gradient(circle at 9% 16%, #d8ece5 0%, rgba(216, 236, 229, 0) 39%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
.t,
.sheetTitle,
.outlineGroupTitle,
.brand-mark {
  font-family: "Syne", "Avenir Next", sans-serif;
}

.app {
  position: relative;
  min-height: 100vh;
  overflow: clip;
  display: flex;
  flex-direction: column;
}

.app-ambient {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

.blob {
  position: absolute;
  border-radius: 999px;
  filter: blur(56px);
  opacity: 0.46;
}

.blob-one {
  width: 250px;
  height: 250px;
  top: -60px;
  right: -70px;
  background: #f6be8f;
  animation: floatBlob 11s ease-in-out infinite;
}

.blob-two {
  width: 280px;
  height: 280px;
  left: -130px;
  bottom: 16%;
  background: #9ad7cb;
  animation: floatBlob 14s ease-in-out infinite reverse;
}

.grid-noise {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(17, 28, 45, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(17, 28, 45, 0.035) 1px, transparent 1px);
  background-size: 22px 22px;
  opacity: 0.3;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  backdrop-filter: blur(12px);
  background: rgba(245, 242, 232, 0.78);
  border-bottom: 1px solid rgba(182, 172, 151, 0.72);
}

.topbar-inner {
  max-width: var(--max-wrap);
  margin: 0 auto;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(145deg, var(--text), #253758);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16), var(--shadow-sm);
}

.brand-copy {
  min-width: 0;
  line-height: 1.1;
}

.brand .t {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.brand .s {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.steps {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 120px;
}

.dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid #9ea7b7;
  background: transparent;
  transition: transform 0.22s ease, background 0.22s ease, border-color 0.22s ease;
}

.dot.active {
  border-color: var(--accent);
  background: var(--accent);
  transform: scale(1.08);
}

.bar {
  width: 52px;
  height: 5px;
  border-radius: 999px;
  background: rgba(158, 167, 183, 0.45);
  overflow: hidden;
}

.bar > i {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #22b7a7);
  transition: width 0.28s ease;
}

main {
  flex: 1;
  width: 100%;
}

.wrap {
  max-width: var(--max-wrap);
  margin: 0 auto;
  padding: 16px 12px 18px;
  display: grid;
  gap: 14px;
}

.card {
  position: relative;
  background: linear-gradient(180deg, #fffef9 0%, var(--card) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  animation: slideReveal 0.45s ease both;
}

.card::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6);
}

.card-head {
  position: relative;
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(182, 172, 151, 0.58);
  display: grid;
  gap: 9px;
}

.eyebrow {
  width: fit-content;
  padding: 6px 10px;
  border: 1px solid rgba(17, 28, 45, 0.18);
  background: rgba(255, 255, 255, 0.72);
  border-radius: 999px;
  color: #2e364a;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.card-head h1 {
  margin: 0;
  max-width: 17ch;
  font-size: clamp(1.6rem, 5.8vw, 2rem);
  line-height: 1.08;
  letter-spacing: -0.02em;
}

.card-head p {
  margin: 0;
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.45;
  max-width: 52ch;
}

.tagRow {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid #c9c1af;
  color: #364259;
  background: #fff;
  font-size: 12px;
  font-weight: 600;
}

.field {
  padding: 14px;
  display: grid;
  gap: 12px;
}

.urlField {
  display: grid;
  gap: 9px;
}

label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.inputRow {
  display: grid;
  gap: 11px;
}

input[type="url"],
input[type="text"],
input[type="email"] {
  width: 100%;
  height: 50px;
  border-radius: var(--radius-ui);
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  padding: 0 14px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

input[type="url"]:focus,
input[type="text"]:focus,
input[type="email"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
  background: #fffefa;
}

.hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.38;
}

.hint code {
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  padding: 2px 4px;
  border-radius: 6px;
  background: #f2ede1;
  border: 1px solid #d9d3c1;
}

.actions {
  display: grid;
  gap: 10px;
}

.btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-ui);
  min-height: 42px;
  padding: 8px 12px;
  background: #fff;
  color: var(--text);
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.01em;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.08s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}

#scanBtn {
  min-height: 50px;
  font-size: 14px;
  font-weight: 700;
}

.btn:hover {
  box-shadow: 0 9px 18px rgba(27, 37, 55, 0.08);
}

.btn:active {
  transform: translateY(1px) scale(0.99);
}

.btn:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.btn.primary {
  background: linear-gradient(130deg, var(--accent), var(--accent-strong));
  border-color: #0e5653;
  color: var(--accent-ink);
  box-shadow: 0 12px 22px rgba(15, 118, 110, 0.2);
}

.btn.primary:hover {
  box-shadow: 0 16px 26px rgba(15, 118, 110, 0.28);
}

.btn.ghost {
  background: transparent;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.65;
  box-shadow: none;
}

.error {
  display: none;
  margin: 12px 14px 0;
  padding: 12px;
  border: 1px solid var(--dangerBorder);
  border-radius: 14px;
  background: var(--dangerBg);
  color: var(--dangerText);
  font-size: 13px;
  line-height: 1.38;
}

.viewer {
  display: none;
}

.viewer-top {
  padding: 13px 12px;
  border-bottom: 1px solid rgba(182, 172, 151, 0.58);
  display: grid;
  gap: 10px;
}

.meta {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.meta .u {
  font-size: 13px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meta .m {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid #cdc4b1;
  background: #fff;
  color: #3b4458;
  font-size: 11px;
  font-weight: 600;
}

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

.viewer-actions .btn {
  width: 100%;
  min-height: 36px;
  padding: 6px 8px;
  border-radius: 11px;
  font-size: 12px;
  font-weight: 650;
}

#seoBtn {
  grid-column: 1 / -1;
  min-height: 38px;
}

#saveScanBtn.is-saved {
  background: rgba(15, 118, 110, 0.16);
  border-color: rgba(14, 86, 83, 0.6);
  color: #0f4f4c;
}

#step2 .viewer-actions {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

#step2 .viewer-actions #seoBtn {
  grid-column: 1 / -1;
}

.editorWrap {
  height: clamp(380px, calc(100vh - 280px), 900px);
  background: #fff;
}

.CodeMirror {
  height: 100%;
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.58;
  color: #17243a;
}

.CodeMirror pre {
  padding: 0 10px;
}

.CodeMirror-gutters {
  border-right: 1px solid #e3ddce;
  background: #faf8f1;
}

.cm-wrap-on .CodeMirror {
  white-space: pre-wrap;
  word-break: break-word;
}

.CodeMirror .cm-outline-hit {
  background: rgba(15, 118, 110, 0.22);
  border-radius: 3px;
  box-shadow: inset 0 -1px 0 rgba(14, 86, 83, 0.65);
  animation: outlinePulse 0.75s ease-in-out 0s 4;
}

.bottomBar {
  display: none;
  position: sticky;
  bottom: 0;
  z-index: 45;
  backdrop-filter: blur(9px);
  background: rgba(255, 253, 246, 0.94);
  border-top: 1px solid rgba(182, 172, 151, 0.72);
  padding: 10px 12px calc(10px + var(--safePad));
}

.bottomBar.show {
  display: block;
  animation: riseIn 0.24s ease both;
}

.bottomBar .grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  max-width: var(--max-wrap);
  margin: 0 auto;
}

.bottomBar .btn {
  min-height: 44px;
  font-size: 13px;
}

.mobileOnly {
  display: none;
}

@media (max-width: 959px) {
  .viewer-mobile-bottom-actions #step2 .viewer-actions #copyBtn,
  .viewer-mobile-bottom-actions #step2 .viewer-actions #downloadBtn {
    display: none;
  }
}

.sheetOverlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 28, 45, 0.52);
  display: none;
  z-index: 88;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 90;
  background: #fffdf7;
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  border: 1px solid rgba(182, 172, 151, 0.8);
  box-shadow: var(--shadow-lg);
  max-height: 86vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  transform: translateY(110%);
  transition: transform 0.24s ease;
}

.sheet.open {
  transform: translateY(0);
}

.sheetHead {
  padding: 12px 12px;
  border-bottom: 1px solid rgba(182, 172, 151, 0.58);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.sheetTitle {
  font-size: 15px;
  font-weight: 700;
}

.sheetBody {
  padding: 12px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.sheetFoot {
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid rgba(182, 172, 151, 0.58);
}

.outlineList {
  display: grid;
  gap: 10px;
}

.outlineGroup {
  margin-top: 8px;
  padding-top: 12px;
  border-top: 1px solid rgba(182, 172, 151, 0.52);
}

.outlineGroupTitle {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.outlineItem {
  border: 1px solid var(--border);
  border-radius: 13px;
  background: #fff;
  padding: 10px 11px;
  display: grid;
  gap: 3px;
}

.outlineItem .t {
  font-size: 13px;
  font-weight: 700;
}

.outlineItem .s {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.savedList {
  display: grid;
  gap: 10px;
}

.savedItem {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
  padding: 11px;
  display: grid;
  gap: 8px;
}

.savedTop {
  display: grid;
  gap: 10px;
}

.savedUrl {
  font-size: 13px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.savedMeta {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.savedActions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.savedEmpty {
  border: 1px dashed var(--border-strong);
  border-radius: 14px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  padding: 14px;
}

#step3 .viewer-actions {
  grid-template-columns: 1fr;
}

#step3 .viewer-actions > div {
  width: 100%;
}

#step3 #reportEmail {
  width: 100%;
  min-width: 0 !important;
}

#step3 #downloadReportBtn {
  width: 100%;
}

@media (max-width: 767px) {
  .mobileOnly {
    display: inline-flex;
  }

  .viewer-actions #prettyBtn,
  .viewer-actions #wrapBtn,
  .viewer-actions #outlineBtn,
  .viewer-actions #mSearchBtn {
    grid-column: auto;
  }

  .viewer-actions #saveScanBtn {
    grid-column: auto;
  }

  .CodeMirror-gutters {
    display: none;
  }

  .CodeMirror-sizer {
    margin-left: 0 !important;
  }
}

@media (min-width: 680px) {
  .topbar-inner {
    padding: 12px 18px;
  }

  .wrap {
    padding: 22px 18px 24px;
  }

  .field {
    padding: 16px;
  }

  .inputRow {
    grid-template-columns: 1fr auto;
    align-items: center;
  }

  .inputRow > .btn {
    min-width: 150px;
  }

  .actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .viewer-top {
    padding: 14px;
  }

  .viewer-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  #step2 .viewer-actions {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  #seoBtn {
    grid-column: auto;
  }

  #step2 #seoBtn {
    grid-column: span 2;
  }

  .savedTop {
    grid-template-columns: 1fr auto;
    align-items: start;
  }
}

@media (min-width: 960px) {
  .brand-mark {
    width: 48px;
    height: 48px;
  }

  .brand .t {
    font-size: 18px;
  }

  .card-head {
    padding: 24px 24px 16px;
  }

  .field {
    padding: 18px 24px 24px;
  }

  .viewer-top {
    padding: 16px 18px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px;
  }

  .viewer-top > #backBtn {
    order: 1;
  }

  .viewer-top > .meta {
    order: 2;
    flex: 1 1 auto;
    min-width: 240px;
  }

  .viewer-top > .viewer-actions {
    order: 4;
  }

  .viewer-top > .codeSearch {
    order: 3;
    flex: 0 1 auto;
  }

  .viewer-actions {
    width: auto;
    min-width: 360px;
  }

  #step2 .viewer-actions {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    min-width: 440px;
  }

  #step2 #seoBtn {
    grid-column: span 2;
  }

  .editorWrap {
    height: clamp(460px, calc(100vh - 200px), 1200px);
  }

  .mobileOnly {
    display: none;
  }

  .bottomBar {
    display: none !important;
  }

  #step3 .viewer-actions > div {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: flex-end;
  }

  #step3 #reportEmail {
    min-width: 260px !important;
    width: auto;
  }

  #step3 #downloadReportBtn {
    width: auto;
  }
}

@keyframes slideReveal {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes riseIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes outlinePulse {
  0%,
  100% {
    background: rgba(15, 118, 110, 0.2);
  }

  50% {
    background: rgba(15, 118, 110, 0.38);
  }
}

@keyframes floatBlob {
  0%,
  100% {
    transform: translate3d(0, 0, 0);
  }

  50% {
    transform: translate3d(0, -12px, 0);
  }
}

/* ------------------------------------------------------------
   Toast notification
   Shown by showToast() for "Link copied!", "Report downloaded!", etc.
------------------------------------------------------------ */
.sourcer-toast {
  position: fixed;
  bottom: calc(24px + var(--safePad));
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 20px;
  border-radius: var(--radius-ui);
  box-shadow: var(--shadow-sm);
  z-index: 999;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
  white-space: nowrap;
}

.sourcer-toast--visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
