/* Iron Script — chat UI styling
   Classical aesthetic: ink on paper, serif Chinese, subdued palette */

:root {
  --paper:       #f6f1e6;
  --paper-edge:  #ebe2cc;
  --ink:         #1c1a17;
  --ink-soft:    #4a443a;
  --ink-mute:    #8a8170;
  --accent:      #6b1d1d;       /* 朱砂 cinnabar */
  --accent-soft: #b07474;
  --user-bg:     #ece3cf;
  --system-bg:   #fffaf0;
  --shadow:      rgba(0,0,0,0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Noto Serif TC", "Source Han Serif TC", "Songti TC", "PMingLiU", "Times New Roman", serif;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 780px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  box-shadow: 0 0 24px var(--shadow);
}

/* === Header === */
.masthead {
  padding: 32px 28px 20px;
  border-bottom: 1px solid var(--paper-edge);
  text-align: center;
  position: relative;
}
.mast-actions {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 8px;
}
.icon-btn {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  height: 38px;
  padding: 0 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  background: var(--system-bg);
  color: var(--accent);
  border: 1.5px solid var(--accent);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 1px 3px var(--shadow);
}
.icon-btn .ib-glyph { font-size: 17px; }
.icon-btn:hover:not(:disabled) { background: var(--accent); color: var(--paper); }
.icon-btn:disabled {
  opacity: 0.4;
  border-color: var(--paper-edge);
  color: var(--ink-mute);
  cursor: not-allowed;
  box-shadow: none;
}
.title-cn {
  font-family: "Noto Serif TC", serif;
  font-weight: 900;
  font-size: 34px;
  letter-spacing: 0.3em;
  color: var(--accent);
}
.title-en {
  font-family: "Playfair Display", serif;
  font-weight: 500;
  font-size: 26px;
  letter-spacing: 0.12em;
  color: var(--ink-soft);
  margin-top: 7px;
}
.subtitle {
  font-size: 13px;
  color: var(--ink-soft);
  margin-top: 12px;
  font-style: italic;
}

/* === Chat scroll area === */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  scroll-behavior: smooth;
}

.welcome {
  max-width: 600px;
  margin: 6px auto 26px;
  background: #fffaf0;
  border: 1px solid var(--paper-edge);
  border-radius: 12px;
  padding: 30px 34px;
  color: var(--ink);
  text-align: center;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
}
.welcome p { margin: 11px 0; }
.welcome p:last-child { margin-bottom: 0; }

/* Chinese intro — larger, Noto Serif TC */
.w-cn {
  font-family: "Noto Serif TC", serif;
  font-size: 16.5px;
  line-height: 1.95;
  color: var(--ink);
  margin-top: 0 !important;
}
/* Ornament between Chinese and English */
.w-orn {
  color: var(--accent-soft);
  font-size: 14px;
  letter-spacing: 0.4em;
  margin: 16px 0 14px;
}
/* English hook — Playfair display headline */
.w-lead {
  font-family: "Playfair Display", "Noto Serif TC", serif;
  font-style: italic;
  font-size: 19px;
  line-height: 1.5;
  color: var(--accent);
}
/* English body — Playfair, a bit smaller */
.welcome p:not(.w-cn):not(.w-lead):not(.welcome-note):not(.welcome-quotes) {
  font-family: "Playfair Display", "Noto Serif TC", serif;
  font-size: 14px;
  line-height: 1.7;
  color: var(--ink);
}
/* Example verses */
.welcome-quotes {
  font-family: "Playfair Display", "Noto Serif TC", serif;
  font-style: italic;
  font-size: 15px;
  color: var(--accent);
  line-height: 2;
}
/* Privacy note */
.welcome-note {
  margin-top: 20px !important;
  padding-top: 14px;
  border-top: 1px solid var(--paper-edge);
  font-size: 12px;
  color: var(--ink-mute);
  line-height: 1.7;
}

.msg {
  margin-bottom: 16px;
  display: flex;
}
.msg .role-label {
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--ink-mute);
  margin-bottom: 4px;
  text-transform: uppercase;
}
.msg.user {
  justify-content: flex-end;
}
.msg.user .bubble {
  background: var(--user-bg);
  border: 1px solid var(--paper-edge);
  max-width: 75%;
  padding: 12px 16px;
  border-radius: 4px;
  white-space: pre-wrap;
}
.msg.assistant .bubble {
  max-width: 100%;
  padding: 4px 0;
  white-space: pre-wrap;
}
.msg.assistant .bubble {
  font-size: 16px;
  color: var(--ink);
  line-height: 1.55;
}

/* Render markdown-ish formatting in assistant messages */
.msg.assistant .bubble strong { color: var(--accent); }
/* 【模塊】【段／年】【ID】… structural markers — accent + bold so every
   section's item name reads consistently (六親 與 大運/流年 一致) */
.msg.assistant .bubble .tag {
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.04em;
}
.msg.assistant .bubble .hd {
  display: block;
  color: var(--accent);
  font-weight: 700;
  font-size: 1.05em;
  letter-spacing: 0.02em;
  margin: 6px 0 1px;
}
.msg.assistant .bubble em { font-style: italic; color: var(--ink-soft); }
.msg.assistant .bubble hr.rule {
  border: none;
  border-top: 1px solid var(--paper-edge);
  margin: 8px 0;
}
.msg.assistant .bubble .li {
  display: block;
  padding-left: 1.3em;
  text-indent: -0.7em;
}
.msg.assistant .bubble .li::before {
  content: "· ";
  color: var(--accent);
  font-weight: 700;
}
.msg.assistant .bubble code {
  background: var(--paper-edge);
  padding: 2px 6px;
  border-radius: 2px;
  font-family: "Menlo", "Consolas", monospace;
  font-size: 0.9em;
}

/* "Calculating" abacus indicator (language-neutral) */
.abacus { display: inline-block; line-height: 0; }
.abacus svg { width: 116px; height: 53px; display: block; }
.ab-frame { stroke: var(--ink); }
.ab-rod   { stroke: var(--ink-mute); }
.ab-bead  { fill: var(--accent); }
.ab-bead2 { fill: var(--accent-soft); }

/* === Composer === */
.composer {
  display: flex;
  padding: 16px 28px;
  border-top: 1px solid var(--paper-edge);
  gap: 12px;
  background: var(--paper);
}

.actions {
  padding: 6px 28px 10px;
  display: flex;
  justify-content: flex-end;
  background: var(--paper);
}
/* 下載命書 — clearly visible cinnabar-outline button (was an easy-to-miss ghost) */
.download-btn {
  font-family: inherit;
  font-size: 13px;
  letter-spacing: 0.2em;
  padding: 8px 20px;
  background: var(--system-bg);
  color: var(--accent);
  border: 1.5px solid var(--accent);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 1px 3px var(--shadow);
}
.download-btn:hover:not(:disabled) {
  background: var(--accent);
  color: var(--paper);
}
.download-btn:disabled {
  opacity: 0.45;
  border-color: var(--paper-edge);
  color: var(--ink-mute);
  cursor: not-allowed;
  box-shadow: none;
}

/* === Feedback modal === */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(28, 26, 23, 0.55);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay.open { display: flex; }
.modal-card {
  position: relative;
  background: #fffaf0;
  border: 1px solid var(--paper-edge);
  border-radius: 10px;
  padding: 26px 26px 24px;
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}
.modal-close {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  font-size: 26px;
  line-height: 1;
  color: var(--ink-mute);
  cursor: pointer;
}
.modal-close:hover { color: var(--accent); }
.modal-card h2 {
  font-family: "Noto Serif TC", serif;
  font-weight: 700;
  font-size: 20px;
  color: var(--accent);
  margin: 0 0 4px;
  letter-spacing: 0.04em;
}
.modal-sub { font-size: 13px; color: var(--ink-mute); margin: 0 0 14px; line-height: 1.6; }
.fb-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--paper-edge);
}
.fb-mod { display: flex; flex-direction: column; min-width: 0; }
.fb-mod-zh { font-size: 14px; color: var(--ink); }
.fb-mod-en { font-size: 11px; color: var(--ink-mute); letter-spacing: 0.02em; }
.fb-stars { flex: none; white-space: nowrap; }
.fb-star {
  font-size: 22px;
  color: var(--paper-edge);
  cursor: pointer;
  transition: color 0.12s;
  padding: 0 1px;
}
.fb-star:hover, .fb-star.on { color: var(--accent); }
.fb-label { display: block; margin-top: 16px; margin-bottom: 5px; font-size: 13px; color: var(--ink-soft); }
.fb-input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--paper-edge);
  border-radius: 5px;
  background: #fff;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  box-sizing: border-box;
}
.fb-input:focus { outline: none; border-color: var(--accent-soft); }
.fb-hint { font-size: 11px; color: var(--ink-mute); margin-top: 4px; }
.fb-submit { width: 100%; margin-top: 20px; }
.ghost-btn {
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 0.2em;
  padding: 6px 14px;
  background: transparent;
  color: var(--ink-mute);
  border: 1px solid var(--paper-edge);
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.2s;
}
.ghost-btn:hover {
  color: var(--accent);
  border-color: var(--accent-soft);
}
.ghost-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
#msgInput {
  flex: 1;
  font-family: inherit;
  font-size: 15px;
  padding: 10px 14px;
  border: 1px solid var(--paper-edge);
  border-radius: 4px;
  background: #fffefa;
  resize: vertical;
  min-height: 50px;
  max-height: 200px;
  color: var(--ink);
  line-height: 1.5;
}
#msgInput:focus {
  outline: none;
  border-color: var(--accent-soft);
}
#sendBtn {
  font-family: inherit;
  font-size: 14px;
  letter-spacing: 0.3em;
  padding: 0 22px;
  background: var(--accent);
  color: var(--paper);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s;
}
#sendBtn:hover:not(:disabled) { background: #4d1010; }
#sendBtn:disabled {
  background: var(--ink-mute);
  cursor: not-allowed;
}

/* === Status bar === */
.status-bar {
  padding: 6px 28px;
  font-size: 11px;
  color: var(--ink-mute);
  text-align: center;
  border-top: 1px solid var(--paper-edge);
  min-height: 22px;
}
.status-bar.error { color: var(--accent); }

/* Mobile */
@media (max-width: 600px) {
  .masthead { padding: 20px 16px 14px; }
  .title-cn { font-size: 26px; }
  .chat-area { padding: 16px; }
  .composer { padding: 12px 16px; gap: 8px; }
  #sendBtn { padding: 0 14px; letter-spacing: 0.2em; }
}
