/* =========================================================
   My First Half · 我的前半生 · Design System
   Warm, paper-like, contemplative.  Not Stripe-blue.
   ========================================================= */
:root {
  --cream:       #F5F0E8;
  --cream-soft:  #EFE8DB;
  --paper:       #FAF6EE;
  --brown:       #4A3728;
  --brown-soft:  #6B5544;
  --gold:        #C9A961;
  --gold-deep:   #A88847;
  --burgundy:    #8B3A3A;
  --burgundy-soft: #A85050;
  --ink:         #2A1F18;
  --line:        rgba(74, 55, 40, 0.12);
  --line-strong: rgba(74, 55, 40, 0.24);
  --shadow:      0 12px 40px rgba(74, 55, 40, 0.12);
  --shadow-sm:   0 4px 16px rgba(74, 55, 40, 0.08);
  --serif:       'Noto Serif TC', 'Cormorant Garamond', serif;
  --sans:        'Noto Sans TC', -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--cream);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.6;
  font-size: 16px;
  overflow-x: hidden;
}
a { color: var(--burgundy); text-decoration: none; }
a:hover { color: var(--burgundy-soft); }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input { font-family: inherit; font-size: inherit; }

/* ============= Topbar ============= */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(245, 240, 232, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  padding: 14px 24px;
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px;
}
.brand-mark { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--brown); letter-spacing: 0.08em; }
.brand-mark .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--burgundy); }
.lang-switch { display: flex; gap: 4px; padding: 4px; border: 1px solid var(--line); border-radius: 999px; background: var(--paper); }
.lang-switch button { padding: 5px 12px; border-radius: 999px; font-size: 12px; color: var(--brown-soft); transition: all 0.2s; }
.lang-switch button.active { background: var(--brown); color: var(--cream); }

/* ============= Auth Pages ============= */
.auth-page {
  min-height: 100vh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 40px 24px;
  background:
    radial-gradient(ellipse at top, rgba(201, 169, 97, 0.18), transparent 60%),
    var(--cream);
}
.auth-card {
  width: 100%; max-width: 420px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 40px 32px;
  box-shadow: var(--shadow);
}
.auth-logo {
  width: 72px; height: 72px;
  border-radius: 18px;
  margin: 0 auto 24px;
  display: block;
  box-shadow: var(--shadow-sm);
}
.auth-title {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 28px;
  color: var(--brown);
  text-align: center;
  margin-bottom: 6px;
  letter-spacing: 0.04em;
}
.auth-slogan {
  font-family: 'Cormorant Garamond', var(--serif);
  font-style: italic;
  color: var(--brown-soft);
  text-align: center;
  font-size: 16px;
  margin-bottom: 32px;
  letter-spacing: 0.02em;
}
.auth-subtitle {
  font-size: 14px;
  color: var(--brown-soft);
  text-align: center;
  margin-bottom: 24px;
}
.input-group { margin-bottom: 16px; }
.input-group label { display: block; font-size: 13px; color: var(--brown-soft); margin-bottom: 6px; font-weight: 500; }
.input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--cream);
  font-size: 16px;
  color: var(--ink);
  transition: all 0.2s;
}
.input:focus { outline: none; border-color: var(--gold); background: var(--paper); box-shadow: 0 0 0 3px rgba(201, 169, 97, 0.15); }
.input::placeholder { color: rgba(74, 55, 40, 0.4); }
.btn-primary {
  width: 100%;
  padding: 14px 24px;
  background: var(--brown);
  color: var(--cream);
  border-radius: 12px;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.04em;
  transition: all 0.2s;
  margin-top: 8px;
}
.btn-primary:hover { background: var(--ink); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-secondary {
  width: 100%;
  padding: 13px 24px;
  background: transparent;
  color: var(--brown);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  font-size: 15px;
  font-weight: 500;
  transition: all 0.2s;
  margin-top: 12px;
}
.btn-secondary:hover { background: var(--cream-soft); border-color: var(--brown); }
.divider { text-align: center; margin: 24px 0; color: var(--brown-soft); font-size: 13px; position: relative; }
.divider::before, .divider::after { content: ""; position: absolute; top: 50%; width: calc(50% - 24px); height: 1px; background: var(--line); }
.divider::before { left: 0; }
.divider::after { right: 0; }
.auth-terms { font-size: 12px; color: var(--brown-soft); text-align: center; margin-top: 24px; line-height: 1.5; }
.auth-terms a { color: var(--brown-soft); border-bottom: 1px dotted var(--line-strong); }
.auth-switch { text-align: center; margin-top: 20px; font-size: 14px; color: var(--brown-soft); }
.auth-switch a { color: var(--burgundy); font-weight: 500; cursor: pointer; }

/* ============= OTP Input ============= */
.otp-row { display: flex; gap: 10px; justify-content: center; margin: 24px 0 8px; }
.otp-box {
  width: 48px; height: 56px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--cream);
  text-align: center;
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 600;
  color: var(--ink);
  transition: all 0.15s;
}
.otp-box:focus { outline: none; border-color: var(--gold); background: var(--paper); box-shadow: 0 0 0 3px rgba(201, 169, 97, 0.15); }
.otp-box.filled { border-color: var(--gold-deep); background: var(--paper); }
.resend-row { text-align: center; font-size: 13px; color: var(--brown-soft); margin-top: 16px; }
.resend-row a { color: var(--burgundy); cursor: pointer; font-weight: 500; }
.resend-row .countdown { color: var(--brown-soft); }
.email-sent-to { text-align: center; font-size: 13px; color: var(--brown-soft); margin-bottom: 8px; }
.email-sent-to strong { color: var(--brown); font-weight: 500; }

/* ============= Feed (Home) ============= */
.feed-page { min-height: 100vh; background: var(--cream); }
.feed-hero {
  padding: 56px 24px 40px;
  text-align: center;
  background: radial-gradient(ellipse at top, rgba(201, 169, 97, 0.18), transparent 60%), var(--cream);
}
.feed-hero h1 {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 32px;
  color: var(--brown);
  margin-bottom: 8px;
  letter-spacing: 0.04em;
}
.feed-hero p {
  font-family: 'Cormorant Garamond', var(--serif);
  font-style: italic;
  color: var(--brown-soft);
  font-size: 17px;
  letter-spacing: 0.02em;
}
.feed-list { padding: 0 24px 80px; max-width: 720px; margin: 0 auto; }
.feed-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 28px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  transition: all 0.3s;
  cursor: pointer;
}
.feed-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--line-strong); }
.feed-card .meta { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.feed-card .avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: linear-gradient(135deg, var(--gold), var(--gold-deep));
  display: flex; align-items: center; justify-content: center;
  font-family: var(--serif); font-weight: 700; color: var(--paper); font-size: 18px;
}
.feed-card .author { font-weight: 500; color: var(--brown); font-size: 15px; }
.feed-card .role { font-size: 12px; color: var(--brown-soft); }
.feed-card h2 {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 22px;
  color: var(--ink);
  margin-bottom: 8px;
  line-height: 1.3;
  letter-spacing: 0.02em;
}
.feed-card .excerpt { color: var(--brown-soft); font-size: 15px; line-height: 1.7; margin-bottom: 16px; }
.feed-card .footer { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--brown-soft); padding-top: 14px; border-top: 1px solid var(--line); }
.feed-card .footer .tag { padding: 3px 10px; background: var(--cream-soft); border-radius: 999px; color: var(--brown); }
.feed-card .footer .stats { display: flex; gap: 14px; }
.feed-card .footer .stat { display: flex; align-items: center; gap: 4px; }

/* ============= Profile ============= */
.profile-page { padding: 24px; max-width: 720px; margin: 0 auto; }
.profile-header { display: flex; align-items: center; gap: 16px; margin: 24px 0 32px; }
.profile-header .avatar { width: 64px; height: 64px; }
.profile-header .name { font-family: var(--serif); font-size: 22px; color: var(--brown); font-weight: 600; }
.profile-header .sub { color: var(--brown-soft); font-size: 14px; }
.profile-section { background: var(--paper); border: 1px solid var(--line); border-radius: 16px; padding: 20px 24px; margin-bottom: 16px; }
.profile-section h3 { font-family: var(--serif); font-size: 16px; color: var(--brown); margin-bottom: 12px; font-weight: 600; }
.profile-row { display: flex; justify-content: space-between; padding: 10px 0; font-size: 14px; border-bottom: 1px solid var(--line); }
.profile-row:last-child { border-bottom: 0; }
.profile-row .label { color: var(--brown-soft); }
.profile-row .value { color: var(--ink); font-weight: 500; }

/* ============= Toast ============= */
.toast {
  position: fixed; bottom: 32px; left: 50%; transform: translateX(-50%) translateY(100px);
  background: var(--ink); color: var(--cream);
  padding: 12px 20px; border-radius: 12px;
  font-size: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: all 0.3s;
  z-index: 100;
  max-width: 90%;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--burgundy); }
.toast.success { background: var(--gold-deep); }

/* ============= Loading ============= */
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--cream); border-top-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: middle; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============= Mobile ============= */
@media (max-width: 480px) {
  .auth-card { padding: 32px 24px; border-radius: 16px; }
  .auth-title { font-size: 24px; }
  .feed-hero { padding: 40px 20px 32px; }
  .feed-hero h1 { font-size: 26px; }
  .feed-list { padding: 0 16px 60px; }
  .otp-box { width: 42px; height: 50px; font-size: 22px; }
}


/* ===== SMS Login Form ===== */
.sms-form {
  margin-top: 12px;
  padding: 16px;
  background: rgba(245, 240, 232, 0.6);
  border-radius: 12px;
  border: 1px solid rgba(74, 55, 40, 0.1);
  animation: smsSlideDown 0.3s ease-out;
}
@keyframes smsSlideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
.phone-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.cc-select {
  flex: 0 0 auto;
  width: 130px;
  font-size: 14px;
  padding: 10px 8px;
  background: white;
}
.phone-input {
  flex: 1;
  font-size: 16px;  /* iOS won't zoom on focus */
  letter-spacing: 0.02em;
}
.otp-input {
  font-size: 24px;
  text-align: center;
  letter-spacing: 0.5em;
  font-weight: 600;
  font-feature-settings: "tnum";
}
.sms-form .btn-primary {
  width: 100%;
  margin-top: 8px;
}
.sms-tip {
  margin-top: 12px;
  font-size: 12px;
  color: rgba(74, 55, 40, 0.65);
  line-height: 1.5;
  text-align: left;
}
.sms-tip-warn {
  color: #B85C00;
  font-weight: 500;
}
@media (max-width: 380px) {
  .cc-select { width: 110px; font-size: 12px; }
  .phone-input { font-size: 14px; }
}
