/* ===== Divine Lots — gold & vermilion theme ===== */
:root {
  --fs: 17px;                 /* content font size (user adjustable) */
  --maroon: #7c1a00;
  --maroon-dark: #5e1400;
  --gold: #c9a227;
  --gold-deep: #8a6d1f;
  --gold-bright: #ffd24d;
  --paper: #f6efdf;
  --ink: #4a2c0a;
  --font-ui: "Source Han Sans", "Source Han Sans SC", "Source Han Sans TC", "思源黑体",
    "思源黑體", "Microsoft YaHei", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--fs);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 50% -200px, #fdf7e3 0%, transparent 70%),
    var(--paper);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
body[data-lang="en"] { font-family: var(--font-ui); }

/* ---------- top bar ---------- */
.topbar {
  background: linear-gradient(180deg, #8a2300 0%, var(--maroon) 55%, #6b1600 100%);
  border-bottom: 3px solid var(--gold);
  box-shadow: 0 2px 12px rgba(60, 20, 0, .35);
  position: sticky;
  top: 0;
  z-index: 10;
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 980px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
}
.app-logo {
  width: 36px; height: 36px;
  border-radius: 8px;
  border: 1px solid rgba(255, 210, 77, .6);
  flex: none;
}
.app-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--gold-bright);
  letter-spacing: .06em;
  margin: 0;
  flex: 1 1 260px;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 2px rgba(0,0,0,.4);
}
.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-left: auto;
}
.ai-top-btn {
  appearance: none;
  border: 1px solid rgba(255, 210, 77, .65);
  border-radius: 8px;
  background: rgba(255, 210, 77, .13);
  color: var(--gold-bright);
  cursor: pointer;
  font: inherit;
  font-size: .9rem;
  font-weight: 700;
  padding: 7px 12px;
  transition: background .15s, transform .12s;
  white-space: nowrap;
}
.ai-top-btn:hover {
  background: rgba(255, 210, 77, .24);
  transform: translateY(-1px);
}
.lang-switch {
  display: flex;
  border: 1px solid rgba(255, 210, 77, .55);
  border-radius: 999px;
  overflow: hidden;
  flex: none;
}
.lang-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: #f3dfae;
  font: inherit;
  font-size: .9rem;
  padding: 6px 14px;
  cursor: pointer;
  transition: background .15s;
}
.lang-btn + .lang-btn { border-left: 1px solid rgba(255, 210, 77, .35); }
.lang-btn.active {
  background: var(--gold-bright);
  color: var(--maroon-dark);
  font-weight: 700;
}

/* ---------- layout ---------- */
.container {
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding: 18px 14px 30px;
  flex: 1;
}

/* ---------- controls ---------- */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px 14px;
  margin-bottom: 14px;
}
.btn {
  appearance: none;
  font: inherit;
  font-size: .95rem;
  padding: 9px 18px;
  border-radius: 10px;
  border: 1px solid var(--gold-deep);
  background: linear-gradient(180deg, #fdf3d0, #f3e0a8);
  color: var(--maroon-dark);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(90, 60, 0, .25);
  transition: transform .12s, box-shadow .12s, opacity .12s;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 3px 8px rgba(90, 60, 0, .3); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary {
  background: linear-gradient(180deg, #a32a00, var(--maroon) 60%, #6b1600);
  color: var(--gold-bright);
  border-color: #5e1400;
  font-weight: 700;
  font-size: 1.05rem;
  padding: 11px 26px;
  letter-spacing: .08em;
}
.btn-ghost { background: transparent; box-shadow: none; }
.btn-icon { padding: 9px 12px; }
.search-group {
  display: flex;
  align-items: center;
  gap: 8px;
}
.search-group label { font-weight: 700; color: var(--maroon-dark); }
.search-group input {
  width: 86px;
  font: inherit;
  text-align: center;
  padding: 8px 6px;
  border-radius: 10px;
  border: 1px solid var(--gold-deep);
  background: #fffdf4;
  color: var(--ink);
}
.search-group input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.tool-group { display: flex; align-items: center; gap: 8px; }
.font-controls { display: flex; gap: 4px; }

.hint {
  text-align: center;
  color: #a33;
  margin: 4px 0 10px;
  font-weight: 600;
}

/* ---------- empty state ---------- */
.empty-state {
  text-align: center;
  padding: 44px 10px 60px;
  color: #7a5a22;
}
.canister-btn {
  appearance: none;
  border: 0;
  background: transparent;
  cursor: pointer;
  border-radius: 24px;
  transition: transform .15s;
}
.canister-btn:hover { transform: scale(1.04); }
.canister-btn img {
  width: 150px; height: 150px;
  border-radius: 24px;
  box-shadow: 0 8px 26px rgba(90, 50, 0, .35);
  display: block;
}
.canister-btn.shaking { animation: shake .5s ease-in-out 2; }
@keyframes shake {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-7deg); }
  75% { transform: rotate(7deg); }
}
.empty-state p {
  margin-top: 18px;
  font-size: 1.05em;
  letter-spacing: .05em;
  line-height: 1.8;
  white-space: pre-line;
}

/* ---------- result reveal ---------- */
.result { animation: rise .45s ease-out; }
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- lot card (shared structure) ---------- */
.lot-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(190px, 26%, 250px);
  grid-template-areas:
    "header side"
    "poem   side"
    "jie    side"
    "bottom bottom";
  grid-template-rows: auto auto 1fr auto;
  border-radius: 14px;
  overflow: hidden;
  line-height: 1.75;
}
.lc-header {
  grid-area: header;
  text-align: center;
  font-weight: 700;
  font-size: 1.45em;
  letter-spacing: .05em;
  padding: 14px 12px;
}
.lc-poem   { grid-area: poem; }
.lc-jie    { grid-area: jie; }
.lc-bottom { grid-area: bottom; }
.lc-row { display: flex; align-items: stretch; }
.lc-label {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  padding: 12px 9px;
  writing-mode: vertical-rl;
  letter-spacing: .35em;
  text-indent: .35em;
}
.lot-card.en .lc-label {
  transform: rotate(180deg);   /* read bottom-to-top, like the print layout */
  letter-spacing: .12em;
  text-indent: 0;
  font-size: .82em;
  text-transform: none;
}
.lc-text {
  flex: 1;
  min-width: 0;
  padding: 12px 16px;
  white-space: pre-line;
}
.lc-side {
  grid-area: side;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  padding: 18px 14px;
}
.lc-side .lc-logo {
  width: clamp(130px, 88%, 190px);
  height: auto;
  display: block;
}
.lot-card.en .lc-side .lc-logo {
  /* light plate so the blue logo reads on the dark card, like the print layout */
  background: #faf4e2;
  padding: 8px 12px;
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
}
.lc-side-title { font-weight: 700; letter-spacing: .15em; }
.lc-stars { font-size: 1.1em; letter-spacing: .15em; }
.lc-advice { white-space: pre-line; font-weight: 600; line-height: 1.9; }

/* ----- Chinese theme: imperial gold ----- */
.lot-card.zh {
  background: linear-gradient(160deg, #fbeec2 0%, #f7e3a6 45%, #fdf3cf 100%);
  border: 3px solid var(--gold-deep);
  box-shadow:
    inset 0 0 0 2px #fdf3cf,
    inset 0 0 0 4px #d8b545,
    0 10px 30px rgba(110, 70, 0, .3);
  color: #7c2d12;
  font-family: var(--font-ui);
}
.lot-card.zh .lc-header {
  color: #a31515;
  background: linear-gradient(180deg, rgba(255, 246, 214, .9), rgba(250, 230, 170, .4));
  border-bottom: 2px solid #c2992e;
}
.lot-card.zh .lc-row { border-bottom: 1px solid #cfa83a; }
.lot-card.zh .lc-label {
  color: #a31515;
  border-right: 1px solid #cfa83a;
  background: rgba(255, 248, 222, .55);
}
.lot-card.zh .lc-side {
  border-left: 2px solid #c2992e;
  background: linear-gradient(180deg, rgba(255, 248, 222, .65), rgba(248, 228, 165, .35));
}
.lot-card.zh .lc-side-title { color: #a31515; font-size: 1.1em; }
.lot-card.zh .lc-stars { color: #b8860b; }
.lot-card.zh .lc-advice { color: #7c2d12; }
.lot-card.zh .lc-bottom { border-top: 1px solid #cfa83a; border-bottom: 0; }

/* ----- English theme: vermilion & gold ----- */
.lot-card.en {
  background: linear-gradient(165deg, #872d20 0%, #7c241c 55%, #6e1d16 100%);
  border: 3px solid #b3884a;
  box-shadow:
    inset 0 0 0 2px #5e1810,
    inset 0 0 0 4px #caa05c,
    0 10px 30px rgba(60, 15, 5, .45);
  color: #f3dcab;
  font-family: var(--font-ui);
}
.lot-card.en .lc-header {
  color: var(--gold-bright);
  background: linear-gradient(180deg, rgba(140, 50, 35, .9), rgba(110, 32, 22, .4));
  border-bottom: 2px solid #caa05c;
}
.lot-card.en .lc-row { border-bottom: 1px solid #a3704533; border-bottom-color: rgba(202, 160, 92, .5); }
.lot-card.en .lc-label {
  color: #ffd24d;
  border-right: 1px solid rgba(202, 160, 92, .5);
  background: rgba(94, 24, 16, .45);
}
.lot-card.en .lc-side {
  border-left: 2px solid #caa05c;
  background: linear-gradient(180deg, rgba(94, 24, 16, .5), rgba(120, 40, 28, .3));
}
.lot-card.en .lc-side-title { color: var(--gold-bright); font-size: 1.05em; }
.lot-card.en .lc-stars { color: var(--gold-bright); }
.lot-card.en .lc-bottom { border-top: 1px solid rgba(202, 160, 92, .5); border-bottom: 0; }

/* ---------- classical details (Chinese) ---------- */
.details { margin-top: 22px; }
.details-heading {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 14px;
  color: var(--maroon-dark);
  font-size: 1.25em;
  letter-spacing: .2em;
}
.details-heading::before,
.details-heading::after {
  content: "";
  flex: 1;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold));
}
.details-heading::after { background: linear-gradient(90deg, var(--gold), transparent); }
.detail-block {
  background: #fffdf4;
  border: 1px solid #e0c878;
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 4px rgba(120, 85, 10, .12);
}
.detail-label {
  display: inline-block;
  font-weight: 700;
  color: #a31515;
  background: linear-gradient(180deg, #fdf3d0, #f3e0a8);
  border: 1px solid var(--gold-deep);
  border-radius: 8px;
  padding: 2px 12px;
  margin-bottom: 8px;
  letter-spacing: .12em;
}
.detail-text { white-space: pre-line; line-height: 1.85; }
.topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 12px;
}
.topic-grid .detail-block { margin-bottom: 0; }

/* ---------- AI interpretation ---------- */
.modal-open { overflow: hidden; }
.ai-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
}
.ai-modal[hidden] { display: none; }
.ai-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(34, 12, 0, .58);
}
.ai-panel {
  position: relative;
  width: min(760px, 100%);
  max-height: min(86vh, 820px);
  overflow: auto;
  background: #fffdf4;
  border: 2px solid var(--gold-deep);
  border-radius: 8px;
  box-shadow: 0 18px 55px rgba(40, 12, 0, .42);
  padding: 18px;
}
.ai-panel-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.ai-panel-header h2 {
  flex: 1;
  margin: 0;
  color: var(--maroon-dark);
  font-size: 1.28rem;
  letter-spacing: .04em;
}
.ai-close {
  appearance: none;
  width: 36px;
  height: 36px;
  border: 1px solid #d0ad55;
  border-radius: 8px;
  background: #fdf3d0;
  color: var(--maroon-dark);
  cursor: pointer;
  font: inherit;
  font-size: 1.35rem;
  line-height: 1;
}
.ai-form {
  display: grid;
  grid-template-columns: minmax(110px, .55fr) minmax(180px, 1fr) minmax(190px, 1fr) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
}
.ai-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ai-field[hidden] { display: none; }
.ai-field label {
  color: var(--maroon-dark);
  font-size: .9rem;
  font-weight: 700;
}
.ai-field input,
.ai-field select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--gold-deep);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  padding: 8px 10px;
}
.ai-field input:focus,
.ai-field select:focus {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}
.ai-status {
  margin: 8px 0 0;
  color: #8a2b14;
  font-weight: 700;
  line-height: 1.6;
}
.ai-status.error { color: #a31515; }
.ai-response {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}
.ai-answer-block {
  border: 1px solid #e0c878;
  border-radius: 8px;
  background: #fff9e9;
  padding: 12px 14px;
}
.ai-answer-block h3 {
  color: #a31515;
  font-size: 1rem;
  margin: 0 0 8px;
}
.ai-answer-block p {
  margin: 0;
  line-height: 1.8;
  white-space: pre-line;
}

/* ---------- footer & toast ---------- */
.footer {
  text-align: center;
  color: #9c8044;
  font-size: .8rem;
  padding: 14px 10px calc(14px + env(safe-area-inset-bottom));
}
.footer p { margin: 0; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 36px;
  transform: translateX(-50%);
  background: var(--maroon-dark);
  color: var(--gold-bright);
  padding: 10px 22px;
  border-radius: 999px;
  border: 1px solid var(--gold);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .35);
  z-index: 50;
  animation: rise .25s ease-out;
}

/* ---------- phone layout ---------- */
@media (max-width: 640px) {
  .lot-card {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "header"
      "poem"
      "jie"
      "side"
      "bottom";
    grid-template-rows: none;
  }
  .lc-header { font-size: 1.22em; padding: 12px 10px; }
  .lot-card.zh .lc-side, .lot-card.en .lc-side {
    border-left: 0;
    border-bottom: 1px solid rgba(180, 140, 60, .55);
    padding: 14px 12px;
  }
  .lc-side .lc-logo { width: min(58%, 165px); }
  .lc-text { padding: 10px 12px; }
  .app-title { font-size: 1rem; }
  .top-actions {
    width: 100%;
    justify-content: space-between;
  }
  .ai-top-btn {
    flex: 1;
    min-width: 0;
  }
  .btn-primary { width: 100%; }
  .search-group { flex: 1; justify-content: center; }
  .ai-panel { padding: 14px; }
  .ai-form { grid-template-columns: 1fr; }
  .topic-grid { grid-template-columns: 1fr; }
}
