:root {
  --bg: #f6f0ea;
  --bg-soft: #ebe1d8;
  --wood: #caa38b;
  --wood-dark: #816253;
  --paper: #fffdf9;
  --paper-2: #f7f0ea;
  --ink: #43352d;
  --muted: #7e6f67;
  --gold: #dcc2ad;
  --gold-deep: #c9a88f;
  --line: rgba(129, 98, 83, 0.16);
  --shadow: 0 18px 42px rgba(88, 67, 54, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.52), transparent 35%),
    linear-gradient(180deg, var(--bg-soft), var(--bg));
}

.app {
  width: min(1180px, calc(100% - 24px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.hero,
.query-panel,
.result-card,
.info-card {
  background: linear-gradient(180deg, var(--paper), var(--paper-2));
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.hero {
  padding: 28px;
  margin-bottom: 18px;
  position: relative;
  overflow: hidden;
}

.hero::after {
  content: "";
  position: absolute;
  inset: auto -40px -60px auto;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(220, 194, 173, 0.3), transparent 68%);
}

.badge,
.section-label {
  display: inline-block;
  margin: 0 0 12px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(220, 194, 173, 0.22);
  color: var(--wood-dark);
  font-size: 13px;
  letter-spacing: 0.08em;
}

h1 {
  margin: 0;
  font-size: clamp(2.4rem, 5vw, 4.6rem);
  letter-spacing: 0.08em;
}

.lead {
  margin: 10px 0 0;
  max-width: 760px;
  color: var(--muted);
  line-height: 1.85;
}

.query-panel {
  padding: 22px;
  margin-bottom: 18px;
}

.query-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.query-head h2,
.result-card h2 {
  margin: 0;
  font-size: 22px;
}

.category-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 16px 0 18px;
}

.category-chip {
  border: 1px solid rgba(91, 59, 33, 0.16);
  background: #fffdfa;
  color: var(--ink);
  padding: 10px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.category-chip:hover {
  transform: translateY(-1px);
  background: #f3e6db;
}

.category-chip.active {
  background: linear-gradient(180deg, #e3cabc, #cfab97);
  color: white;
  border-color: transparent;
}

label {
  display: block;
  margin-bottom: 10px;
  font-size: 16px;
}

.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

input {
  width: 100%;
  border: 1px solid rgba(91, 59, 33, 0.16);
  border-radius: 16px;
  padding: 12px 14px;
  font: inherit;
  color: var(--ink);
  background: #fffefa;
}

input:focus {
  outline: 2px solid rgba(216, 176, 106, 0.7);
  outline-offset: 2px;
}

textarea {
  width: 100%;
  border: 1px solid rgba(91, 59, 33, 0.16);
  border-radius: 18px;
  padding: 16px;
  font: inherit;
  resize: vertical;
  min-height: 120px;
  color: var(--ink);
  background: #fffefa;
}

textarea:focus {
  outline: 2px solid rgba(216, 176, 106, 0.7);
  outline-offset: 2px;
}

.actions {
  display: flex;
  margin-top: 14px;
}

.reader-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 16px 0 18px;
}

.reader-email {
  grid-column: 1 / -1;
}

.toggle-button {
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 13px;
  background: rgba(129, 98, 83, 0.1);
  color: var(--wood-dark);
  box-shadow: none;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  font: inherit;
  cursor: pointer;
  background: linear-gradient(180deg, #e3cab9, #cfac95);
  color: white;
  box-shadow: 0 10px 24px rgba(180, 135, 69, 0.28);
  transition: transform 0.2s ease, filter 0.2s ease;
}

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

.ghost-button {
  background: rgba(129, 98, 83, 0.1);
  color: var(--wood-dark);
  box-shadow: none;
}

.shelf-scene {
  position: relative;
  padding: 10px 10px 22px;
  margin-bottom: 18px;
}

.shelf-top,
.shelf-bottom {
  height: 18px;
  border-radius: 12px;
  background: linear-gradient(180deg, #ceb09d, #b89480);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.18);
}

.shelf-row {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  padding: 12px 2px;
}

.shelf-book {
  min-height: 240px;
  padding: 14px 12px;
  border-radius: 18px 18px 10px 10px;
  color: white;
  box-shadow: 0 12px 24px rgba(88, 67, 54, 0.16);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border: 1px solid rgba(255, 255, 255, 0.1);
  cursor: pointer;
  transition: transform 0.2s ease, filter 0.2s ease;
}

.book-icon {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 14px;
  margin-bottom: 10px;
  background: rgba(255, 255, 255, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.shelf-book:hover {
  transform: translateY(-6px);
  filter: brightness(1.04);
}

.shelf-book.active {
  outline: 3px solid rgba(255, 248, 240, 0.95);
  transform: translateY(-6px) scale(1.02);
}

.book-spine {
  writing-mode: horizontal-tb;
  text-orientation: initial;
  font-size: 30px;
  letter-spacing: 0.18em;
  text-align: center;
  line-height: 1.15;
  font-weight: 700;
  align-self: stretch;
  margin: 6px 0 8px;
}

.book-meta {
  font-size: 14px;
  line-height: 1.6;
  opacity: 0.9;
  text-align: center;
}

.book-tag {
  display: inline-block;
  align-self: flex-start;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  font-size: 12px;
}

.result-grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 18px;
}

.result-card,
.info-card {
  padding: 22px;
}

.prescription-card {
  margin-top: 18px;
  padding: 22px;
  background: linear-gradient(180deg, #fffaf4, #f3e8de);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.prescription-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.download-row {
  margin-top: 14px;
}

.download-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
  border-radius: 999px;
  background: linear-gradient(180deg, #e3cab9, #cfac95);
  color: white;
  text-decoration: none;
  box-shadow: 0 10px 24px rgba(180, 135, 69, 0.28);
}

.download-link:hover {
  filter: brightness(1.03);
}

.prescription-item {
  padding: 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.58);
  border: 1px solid rgba(91, 59, 33, 0.1);
}

.prescription-item span {
  display: inline-block;
  margin-bottom: 10px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(220, 194, 173, 0.28);
  color: var(--wood-dark);
  font-size: 13px;
}

.reader-summary {
  margin: 10px 0 0;
  color: var(--wood-dark);
  font-size: 14px;
  line-height: 1.7;
}

.prescription-meta {
  margin: 8px 0 0;
  color: var(--wood-dark);
  font-size: 14px;
  line-height: 1.7;
}

.prescription-answer {
  margin: 0;
  line-height: 1.85;
  color: var(--muted);
  white-space: pre-line;
}

.answer-text {
  margin: 12px 0 0;
  white-space: pre-line;
  line-height: 1.9;
  color: var(--muted);
}

.source {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid rgba(91, 59, 33, 0.16);
  color: var(--wood-dark);
  font-size: 14px;
}

.info-card ol {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.95;
}

@media (max-width: 960px) {
  .shelf-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

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

@media (max-width: 640px) {
  .app {
    width: min(100% - 16px, 100%);
    padding-top: 8px;
  }

  .hero,
  .query-panel,
  .result-card,
  .info-card {
    border-radius: 20px;
  }

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

  .shelf-book {
    min-height: 200px;
  }

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

  .reader-email {
    grid-column: auto;
  }
}
