:root {
  --paper: #faf3ec;
  --ink: #453832;
  --accent: #d96a58;
  --accent-deep: #b95241;
  --accent-tint: #f9e6df;
  --peach: #efb0a0;
  --muted: #a2908a;
  --line: #ecdcd2;
  --card: #fffdfb;
  --round: "Huninn", "jf-openhuninn", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--round);
  letter-spacing: 0.05em;
  line-height: 1.7;
  background: var(--paper);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

header { text-align: center; padding: 1.8rem 1rem 0.4rem; }
body.in-chat header { display: none; }

.logo { display: inline-block; }
.logo h1 {
  font-size: 2.6rem;
  font-weight: 400;
  letter-spacing: 0.22em;
  margin-right: -0.22em;
  line-height: 1.15;
}

/* 配對標記：兩個靠近的圓與愛心 */
.pair-mark {
  position: relative;
  height: 20px;
  margin-top: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pair-mark .orb { width: 13px; height: 13px; }
.pair-mark .orb.b { margin-left: -4px; }
.pair-mark .spark {
  position: static;
  margin-left: 4px;
  font-size: 0.75rem;
  animation: none;
  opacity: 1;
}

.orb { border-radius: 50%; display: inline-block; }
.orb.a { background: var(--accent); }
.orb.b { background: var(--peach); }
.spark { color: var(--accent); }

.tagline {
  color: var(--muted);
  font-size: 0.92rem;
  letter-spacing: 0.12em;
  margin-top: 0.7rem;
}

main {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
}
body.in-chat { height: 100vh; height: 100dvh; overflow: hidden; }

.view {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: clamp(1.5rem, 9vh, 6.5rem);
  gap: 1.1rem;
}
.hidden { display: none !important; }

label { font-size: 1.2rem; letter-spacing: 0.1em; }

.field-hint {
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  margin-top: -0.7rem;
}

input {
  font-family: var(--round);
  font-size: 1rem;
  letter-spacing: 0.05em;
  padding: 0.7rem 1rem;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  width: 100%;
  max-width: 320px;
  transition: border-color 0.12s ease;
}
input:focus { border-color: var(--accent); }
input:focus-visible { outline: none; border-color: var(--accent); }
input:disabled { background: #f4ede7; color: var(--muted); }
button:disabled { opacity: 0.45; cursor: default; pointer-events: none; }

button {
  font-family: var(--round);
  font-size: 1rem;
  letter-spacing: 0.1em;
  padding: 0.6rem 1.5rem;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.1s ease, background 0.1s ease;
}
button:hover { transform: translateY(-1px); box-shadow: 0 3px 10px rgba(64, 56, 46, 0.12); }
button:active { transform: translateY(1px); box-shadow: none; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); border-color: var(--accent-deep); color: #fff; }
button.danger { border-color: #c0574a; color: #b0473a; }

/* 等待配對：兩圓互相靠近、迸出愛心 */
.pairing { position: relative; width: 150px; height: 72px; }
.pairing .orb {
  position: absolute;
  top: 22px;
  width: 38px;
  height: 38px;
}
.pairing .orb.a { left: 16px; animation: approach-a 2.2s ease-in-out infinite; }
.pairing .orb.b { right: 16px; animation: approach-b 2.2s ease-in-out infinite; }
.pairing .spark {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  font-size: 1.25rem;
  opacity: 0;
  animation: spark 2.2s ease-in-out infinite;
}
@keyframes approach-a {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(16px); }
}
@keyframes approach-b {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(-16px); }
}
@keyframes spark {
  0%, 30%, 100% { opacity: 0; transform: translateX(-50%) translateY(4px) scale(0.7); }
  55% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1.15); }
  75% { opacity: 1; transform: translateX(-50%) translateY(-2px) scale(1); }
}
.wait-text { font-size: 1.15rem; letter-spacing: 0.1em; }
.wait-sub { color: var(--muted); font-size: 0.85rem; margin-top: -0.7rem; letter-spacing: 0.1em; }

/* 聊天室 */
#view-chat { justify-content: flex-start; align-items: stretch; gap: 0.6rem; min-height: 0; padding-top: 0; }

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.6rem 1rem;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 16px;
}
.chat-header > span { font-size: 1rem; }
#peer-name { color: var(--accent); }
.chat-topic { margin-left: 0.5rem; }

/* 主題房號徽章 */
.topic-tag {
  display: inline-block;
  background: var(--accent-tint);
  color: var(--accent-deep);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  padding: 0.08rem 0.55rem;
  border-radius: 6px;
  vertical-align: 0.1em;
}
.wait-sub.topic-tag {
  font-size: 0.85rem;
  padding: 0.15rem 0.7rem;
  margin-top: -0.4rem;
}
.chat-actions { display: flex; gap: 0.2rem; }
.chat-actions button {
  font-size: 0.85rem;
  padding: 0.35rem 0.7rem;
  letter-spacing: 0.06em;
  border: none;
  background: transparent;
}
.chat-actions button:hover {
  transform: none;
  box-shadow: none;
  background: var(--accent-tint);
}
.chat-actions button.danger { color: #b0473a; }

#messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 16px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.bubble {
  max-width: 78%;
  padding: 0.55rem 0.95rem;
  border-radius: 18px;
  line-height: 1.65;
  letter-spacing: 0.04em;
  word-break: break-word;
  white-space: pre-wrap;
  animation: pop 0.16s ease-out;
}
.bubble.me {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 6px;
}
.bubble.them {
  align-self: flex-start;
  background: var(--accent-tint);
  border-bottom-left-radius: 6px;
}
@keyframes pop {
  from { transform: translateY(4px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.notice {
  align-self: center;
  color: var(--muted);
  font-size: 0.83rem;
  letter-spacing: 0.08em;
  padding: 0.2rem 0;
}

/* 聊天靈感 */
#suggest { display: flex; flex-direction: column; gap: 0.35rem; }
#suggest-label {
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
}
#suggest-chips {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding-bottom: 0.15rem;
}
.chip {
  flex: 0 0 auto;
  font-size: 0.88rem;
  padding: 0.4rem 0.8rem;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  white-space: nowrap;
}
.chip:hover {
  transform: none;
  box-shadow: none;
  border-color: var(--accent);
  background: var(--accent-tint);
}

#msg-form { display: flex; gap: 0.5rem; }
#msg-form input { flex: 1; max-width: none; }

/* 對話結束 */
#ended-reason { font-size: 1.15rem; letter-spacing: 0.1em; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(64, 56, 46, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}
.modal {
  background: var(--card);
  border-radius: 18px;
  padding: 1.5rem 1.3rem 1.2rem;
  width: 100%;
  max-width: 340px;
  box-shadow: 0 10px 34px rgba(64, 56, 46, 0.3);
  animation: modal-in 0.15s ease-out;
}
@keyframes modal-in {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.modal p { font-size: 1.02rem; line-height: 1.65; letter-spacing: 0.06em; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.2rem;
}
.modal-actions button.danger-ok { background: #b0473a; border-color: #b0473a; color: #fff; }

/* 子頁面（布告欄 / 故事）與站內連結 */
.logo-link { text-decoration: none; color: inherit; }
.site-links {
  text-align: center;
  padding: 1.2rem 1rem 1.6rem;
  color: var(--muted);
  font-size: 0.88rem;
  letter-spacing: 0.08em;
}
.site-links a { color: var(--accent-deep); text-decoration: none; }
.site-links a:hover { text-decoration: underline; }
body.in-chat .site-links { display: none; }

.page-main {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.stack { display: flex; flex-direction: column; gap: 0.7rem; }
.card {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 1.1rem 1.2rem;
}
.card-title { font-size: 1.15rem; font-weight: 400; letter-spacing: 0.1em; }
.card-hint { color: var(--muted); font-size: 0.84rem; letter-spacing: 0.06em; }
.card input, .card textarea, .card select { max-width: none; }
textarea, select {
  font-family: var(--round);
  font-size: 1rem;
  letter-spacing: 0.05em;
  line-height: 1.65;
  padding: 0.7rem 1rem;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  width: 100%;
  resize: vertical;
}
textarea:focus, select:focus { outline: none; border-color: var(--accent); }
.captcha-row { display: flex; align-items: center; gap: 0.6rem; }
.captcha-q { font-size: 1.05rem; white-space: nowrap; }
.captcha-row input { width: 7em; }
.hp { position: absolute; left: -9999px; opacity: 0; height: 0; padding: 0; border: none; }

.post-head { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.4rem; }
.post-time { color: var(--muted); font-size: 0.78rem; }
.post-msg { white-space: pre-wrap; word-break: break-word; }
.post .topic-tag { margin-top: 0.55rem; text-decoration: none; }

.cat-tabs { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.cat-tabs button { font-size: 0.88rem; padding: 0.35rem 0.9rem; }
.cat-tabs button.active { background: var(--accent); border-color: var(--accent-deep); color: #fff; }

.story-body { white-space: pre-wrap; word-break: break-word; }
.story-body.clamped {
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.story-more {
  align-self: flex-start;
  border: none;
  background: none;
  color: var(--accent-deep);
  font-size: 0.85rem;
  padding: 0.4rem 0 0;
  margin-top: 0.1rem;
}
.story-more:hover { transform: none; box-shadow: none; text-decoration: underline; }

.end-actions {
  align-self: center;
  display: flex;
  gap: 0.5rem;
  padding: 0.3rem 0;
}
.end-actions .chip { text-decoration: none; color: var(--accent-deep); }

@media (max-width: 480px) {
  .logo h1 { font-size: 2.1rem; }
}

@media (prefers-reduced-motion: reduce) {
  .pairing .orb, .pairing .spark { animation: none; }
  .pairing .spark { opacity: 1; transform: translateX(-50%); }
  .bubble, .modal { animation: none; }
}
