:root {
  color-scheme: light;
  --surface: rgba(255, 255, 255, 0.88);
  --surface-strong: rgba(255, 255, 255, 0.97);
  --surface-muted: rgba(255, 245, 251, 0.85);
  --border: rgba(204, 55, 142, 0.16);
  --border-strong: rgba(204, 55, 142, 0.28);
  --text: #2f1025;
  --text-strong: #240718;
  --muted: #81506c;
  --accent: #d81b84;
  --accent-strong: #b4126a;
  --accent-soft: #ffe0f0;
  --accent-ink: #fff8fc;
  --accent-alt: #f768be;
  --chip: #fff2f9;
  --chip-border: rgba(216, 27, 132, 0.14);
  --success: #dcf8ea;
  --success-ink: #1d7c4c;
  --danger: #ffe7ee;
  --danger-ink: #a83262;
  --link: #b31573;
  --shadow: 0 22px 58px rgba(193, 45, 126, 0.14);
  --radius-xl: 30px;
  --toolbar-top: calc(env(safe-area-inset-top, 0px) + 0.75rem);
  --card-head-top: calc(env(safe-area-inset-top, 0px) + 7.15rem);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 8.5rem;
  overflow-x: clip;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  font-family: "Bai Jamjuree", "Noto Sans Thai", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 0% 0%, rgba(255, 122, 191, 0.24), transparent 28%),
    radial-gradient(circle at 100% 0%, rgba(255, 196, 228, 0.55), transparent 26%),
    radial-gradient(circle at 50% 100%, rgba(255, 224, 239, 0.78), transparent 34%),
    linear-gradient(180deg, #fffdfd 0%, #fff6fb 44%, #fff4fa 100%);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  border-radius: 999px;
  padding: 0.92rem 1.18rem;
  background: linear-gradient(180deg, var(--accent-alt) 0%, var(--accent) 100%);
  color: var(--accent-ink);
  font-weight: 800;
  box-shadow: 0 14px 30px rgba(216, 27, 132, 0.22);
  transition: transform 0.18s ease, filter 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

button:hover {
  transform: translateY(-1px);
  filter: brightness(1.02);
}

button.secondary {
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--border), 0 8px 18px rgba(162, 38, 103, 0.08);
}

button.secondary:hover {
  background: #ffffff;
}

button.danger {
  background: linear-gradient(180deg, #ff7aab 0%, #e2407f 100%);
  color: #fff8fc;
  box-shadow: 0 12px 28px rgba(226, 64, 127, 0.22);
}

button.danger:hover {
  filter: brightness(1.03);
}

input {
  width: 100%;
  border: 1px solid rgba(216, 27, 132, 0.18);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--text-strong);
  padding: 1.12rem 1.25rem;
  outline: none;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.8),
    0 14px 28px rgba(214, 76, 149, 0.08);
}

input::placeholder {
  color: #b88ba2;
}

input:focus {
  border-color: rgba(216, 27, 132, 0.46);
  box-shadow:
    0 0 0 5px rgba(216, 27, 132, 0.12),
    0 18px 36px rgba(214, 76, 149, 0.12);
}

.shell {
  width: min(1440px, calc(100vw - 2rem));
  margin: 0 auto;
  padding: 1.35rem 0 4rem;
  position: relative;
  z-index: 1;
}

.toolbar,
.results-meta,
.card,
.image-dialog {
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.toolbar {
  position: sticky;
  top: var(--toolbar-top);
  z-index: 30;
  border-radius: 30px;
  padding: 1rem;
  display: grid;
  gap: 0.95rem;
  margin-bottom: 0.9rem;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(255, 241, 249, 0.94)),
    var(--surface-strong);
  border-color: var(--border-strong);
  box-shadow:
    0 24px 60px rgba(216, 27, 132, 0.16),
    0 10px 24px rgba(216, 27, 132, 0.08);
}

.toolbar-head {
  display: block;
}

.toolbar-head h2 {
  margin: 0;
  font-size: clamp(1.08rem, 2vw, 1.45rem);
  line-height: 1.15;
  color: var(--text-strong);
}

.search-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  grid-template-areas: "input submit clear";
  gap: 0.75rem;
  align-items: center;
}

.search-box input {
  grid-area: input;
  min-height: 4rem;
  font-size: 1.08rem;
  font-weight: 600;
}

#searchButton {
  grid-area: submit;
  min-height: 4rem;
  min-width: 7.5rem;
}

#clearButton {
  grid-area: clear;
  min-height: 4rem;
  min-width: 5.25rem;
}

.results-meta {
  border-radius: 20px;
  padding: 0.95rem 1rem;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 1rem;
  margin-bottom: 0.8rem;
  color: var(--accent-strong);
  font-weight: 700;
  background: rgba(255, 255, 255, 0.7);
  box-shadow: 0 14px 28px rgba(193, 45, 126, 0.08);
}

.results {
  display: grid;
  gap: 1rem;
  min-width: 0;
}

.card {
  width: 100%;
  min-width: 0;
  border-radius: var(--radius-xl);
  overflow: visible;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(255, 246, 251, 0.94)),
    var(--surface-strong);
  box-shadow:
    0 18px 44px rgba(193, 45, 126, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.card.is-match {
  box-shadow:
    0 22px 56px rgba(216, 27, 132, 0.14),
    0 8px 22px rgba(216, 27, 132, 0.08);
}

.card-head {
  position: sticky;
  top: var(--card-head-top);
  z-index: 8;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, auto);
  gap: 1rem;
  padding: 1.2rem 1.25rem 1rem;
  align-items: start;
  border-bottom: 1px solid rgba(216, 27, 132, 0.08);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(255, 245, 251, 0.96)),
    var(--surface-strong);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  box-shadow: 0 14px 26px rgba(193, 45, 126, 0.08);
}

.card-head > div,
.actions,
.panel,
.detail {
  min-width: 0;
}

.title-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.65rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.76rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  background: #fff3fa;
  color: var(--accent-strong);
  border: 1px solid rgba(216, 27, 132, 0.08);
}

.badge.on {
  background: var(--success);
  color: var(--success-ink);
  border-color: rgba(29, 124, 76, 0.08);
}

.badge.off {
  background: var(--danger);
  color: var(--danger-ink);
  border-color: rgba(168, 50, 98, 0.08);
}

.badge.accent {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.card-title {
  margin: 0;
  font-size: 1.42rem;
  line-height: 1.18;
  letter-spacing: -0.03em;
  color: var(--text-strong);
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem 1rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: flex-end;
  align-content: start;
}

.actions button {
  padding: 0.78rem 1rem;
  font-size: 0.92rem;
}

.actions button.action-copy-answer {
  order: -3;
  background: linear-gradient(180deg, #ff74c0 0%, var(--accent) 100%);
  color: var(--accent-ink);
  box-shadow: 0 14px 32px rgba(216, 27, 132, 0.24);
}

.actions button.action-copy-qa {
  order: -2;
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--border), 0 8px 18px rgba(162, 38, 103, 0.08);
}

.actions button.action-copy-qa:hover {
  background: #ffffff;
}

.actions button.action-copy-images {
  background: linear-gradient(180deg, #fff9fd 0%, #ffd9ec 100%);
  color: var(--accent-strong);
  box-shadow:
    inset 0 0 0 1px rgba(216, 27, 132, 0.18),
    0 10px 22px rgba(216, 27, 132, 0.12);
}

.detail {
  border-top: 1px solid rgba(216, 27, 132, 0.06);
  padding: 0.95rem 1.25rem 1.3rem;
  display: grid;
  gap: 1rem;
}

.answer-media-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(300px, 0.8fr);
  gap: 1rem;
  align-items: start;
}

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

.panel {
  background: var(--surface-muted);
  border: 1px solid rgba(216, 27, 132, 0.08);
  border-radius: 20px;
  padding: 1rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.74);
}

.panel h3 {
  margin: 0 0 0.7rem;
  font-size: 1rem;
  color: var(--text-strong);
}

.image-upload-row {
  display: flex;
  justify-content: flex-start;
  margin-bottom: 0.8rem;
}

.image-upload-row button {
  padding: 0.72rem 0.98rem;
  font-size: 0.9rem;
}

.panel-stack {
  display: grid;
  gap: 1rem;
}

.panel-block {
  display: grid;
  gap: 0.65rem;
}

.panel-block h3 {
  margin: 0;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.48rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 0.36rem 0.68rem;
  border-radius: 999px;
  background: var(--chip);
  color: var(--accent-strong);
  border: 1px solid var(--chip-border);
  font-size: 0.84rem;
  font-weight: 700;
}

.answer-lines,
.plain-lines {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.75;
  color: var(--text);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.answer-lines a {
  color: var(--link);
  font-weight: 700;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.8rem;
}

.image-card {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(216, 27, 132, 0.08);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 12px 24px rgba(193, 45, 126, 0.08);
}

.image-card img {
  display: block;
  width: 100%;
  height: 190px;
  object-fit: cover;
  background: linear-gradient(180deg, #fff7fb, #ffe7f4);
}

.image-card-body {
  padding: 0.82rem;
  display: grid;
  gap: 0.52rem;
}

.image-card-body button {
  width: 100%;
  padding: 0.76rem 0.9rem;
  font-size: 0.9rem;
}

.image-actions {
  display: grid;
  gap: 0.45rem;
}

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

.bg-orb {
  position: fixed;
  width: 40vw;
  height: 40vw;
  filter: blur(70px);
  opacity: 0.58;
  pointer-events: none;
  z-index: 0;
}

.bg-orb-one {
  top: -12vw;
  left: -12vw;
  background: radial-gradient(circle, rgba(255, 124, 189, 0.3) 0%, rgba(255, 124, 189, 0) 68%);
}

.bg-orb-two {
  right: -14vw;
  top: 6vw;
  background: radial-gradient(circle, rgba(255, 204, 230, 0.55) 0%, rgba(255, 204, 230, 0) 70%);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 1rem);
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  pointer-events: none;
  background: rgba(61, 12, 41, 0.92);
  color: #fff8fc;
  padding: 0.95rem 1.15rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 18px 32px rgba(108, 17, 66, 0.22);
  transition: opacity 0.22s ease, transform 0.22s ease;
  z-index: 40;
}

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

.scroll-top-button {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right, 0px) + 1rem);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 1rem);
  z-index: 45;
  padding: 0.95rem 1.1rem;
  border-radius: 999px;
  box-shadow: 0 18px 34px rgba(216, 27, 132, 0.26);
  opacity: 0;
  pointer-events: none;
  transform: translateY(14px);
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.scroll-top-button.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.image-dialog {
  width: min(980px, calc(100vw - 2rem));
  border-radius: 24px;
  padding: 1rem;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.99), rgba(255, 244, 250, 0.98)),
    var(--surface-strong);
}

.image-dialog::backdrop {
  background: rgba(84, 15, 54, 0.3);
  backdrop-filter: blur(8px);
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  margin-bottom: 0.9rem;
}

.dialog-caption {
  color: var(--muted);
  margin-top: 0.2rem;
  font-size: 0.92rem;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.image-dialog img {
  width: 100%;
  max-height: 72vh;
  object-fit: contain;
  background: linear-gradient(180deg, #fff7fb, #fff0f8);
  border-radius: 20px;
}

.dialog-actions {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  margin-top: 0.95rem;
}

mark {
  background: rgba(255, 109, 185, 0.2);
  color: inherit;
  padding: 0 0.18rem;
  border-radius: 0.24rem;
}

@media (max-width: 1180px) {
  :root {
    --card-head-top: calc(env(safe-area-inset-top, 0px) + 7.5rem);
  }
}

@media (max-width: 860px) {
  :root {
    --card-head-top: calc(env(safe-area-inset-top, 0px) + 8.6rem);
  }

  html {
    scroll-padding-top: 9.5rem;
  }

  body {
    background:
      radial-gradient(circle at 10% 0%, rgba(255, 122, 191, 0.24), transparent 30%),
      radial-gradient(circle at 100% 20%, rgba(255, 205, 232, 0.52), transparent 30%),
      linear-gradient(180deg, #fffefd 0%, #fff7fb 46%, #fff3f9 100%);
  }

  .shell {
    width: min(100vw - 1rem, 1440px);
    padding-top: 0.8rem;
    padding-bottom: 5rem;
  }

  .toolbar,
  .results-meta,
  .card {
    border-radius: 24px;
  }

  .toolbar {
    top: calc(env(safe-area-inset-top, 0px) + 0.5rem);
    padding: 0.9rem;
  }

  .search-box {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas:
      "input input"
      "submit clear";
  }

  .search-box input,
  #searchButton,
  #clearButton {
    min-height: 3.55rem;
  }

  .card-head {
    grid-template-columns: 1fr;
    top: var(--card-head-top);
    padding: 1rem 1rem 0.9rem;
    border-radius: 24px 24px 0 0;
  }

  .actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    justify-content: stretch;
    width: 100%;
  }

  .actions button.action-copy-answer {
    grid-column: 1 / -1;
    min-height: 3.4rem;
    font-size: 1rem;
  }

  .actions button {
    width: 100%;
    min-height: 3.1rem;
  }

  .detail {
    padding-left: 1rem;
    padding-right: 1rem;
  }

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

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

  .dialog-head,
  .dialog-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .dialog-actions button {
    width: 100%;
  }
}

@media (max-width: 560px) {
  :root {
    --card-head-top: calc(env(safe-area-inset-top, 0px) + 8.9rem);
  }

  html {
    scroll-padding-top: 9.75rem;
  }

  .toolbar-head h2 {
    font-size: 1.08rem;
  }

  .results {
    gap: 0.85rem;
  }

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

  .card-title {
    font-size: 1.22rem;
  }
}

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