/* ============================================
   古诗词学习 - 中国风 v4.1 · iPad 优化
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=ZCOOL+XiaoWei&display=swap');

:root {
  --font-poem: 'Noto Serif SC', 'STKaiti', 'KaiTi', serif;
  --font-display: 'ZCOOL XiaoWei', 'Noto Serif SC', serif;
  --parchment: #fdf3e3;
  --ink: #2c1810;
  --ink-light: #5c3d2e;
  --blossom: #e8829a;
  --jade: #4a9b6f;
  --gold: #c9882a;
  --red: #c0392b;
  --paper: #fff9f0;
}

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

body {
  font-family: var(--font-poem);
  background-color: var(--parchment);
  color: var(--ink);
  min-height: 100vh;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  font-size: 18px;
}

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(200,136,42,0.3); border-radius: 2px; }

/* ===== TOP HEADER ===== */
.top-header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(253,243,227,0.92); backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(201,136,42,0.15);
  padding: 12px 20px;
}
.top-header-inner { max-width: 860px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; }
.logo { display: flex; align-items: center; gap: 8px; font-family: var(--font-display); color: var(--ink); font-size: 22px; font-weight: 700; cursor: pointer; text-decoration: none; }
.nav-tabs { display: flex; align-items: center; gap: 8px; }
.nav-tab { display: flex; align-items: center; gap: 5px; padding: 9px 20px; border-radius: 9999px; font-size: 16px; font-weight: 500; border: none; cursor: pointer; font-family: var(--font-poem); transition: all 0.2s; background: transparent; color: var(--ink-light); text-decoration: none; }
.nav-tab:hover { background: rgba(201,136,42,0.08); }
.nav-tab.active { background: linear-gradient(135deg, #c0392b, #e8829a); color: #fff; box-shadow: 0 2px 12px rgba(192,57,43,0.3); }

/* ===== MAIN ===== */
.main-container { max-width: 860px; margin: 0 auto; padding: 22px 24px 40px; position: relative; z-index: 1; }

/* ===== SEARCH ===== */
.search-row { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.search-box { flex: 1; display: flex; align-items: center; gap: 10px; padding: 13px 20px; border-radius: 9999px; background: rgba(255,255,255,0.8); border: 1.5px solid rgba(44,24,16,0.1); }
.search-box input { flex: 1; border: none; background: transparent; outline: none; font-size: 18px; font-family: var(--font-poem); color: var(--ink); }
.search-box input::placeholder { color: #bba; font-size: 16px; }
.search-box .clear-btn { background: none; border: none; color: var(--ink-light); font-size: 18px; cursor: pointer; }
.nav-btn { padding: 13px 22px; border-radius: 9999px; border: 1.5px solid rgba(44,24,16,0.1); background: rgba(255,255,255,0.8); font-size: 16px; font-weight: 500; font-family: var(--font-poem); color: var(--ink); cursor: pointer; transition: all 0.2s; white-space: nowrap; }
.nav-btn:hover { border-color: var(--gold); color: var(--gold); }
.nav-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.search-count { font-size: 14px; color: var(--ink-light); text-align: center; min-height: 20px; margin-top: -8px; margin-bottom: 8px; }

/* ===== POEM HEADER ===== */
.poem-header { border-radius: 20px; padding: 32px 28px; margin-bottom: 20px; position: relative; overflow: hidden; background: linear-gradient(135deg, #fff9f0 0%, #fdf3e3 60%, #f9e8d4 100%); border: 1.5px solid rgba(201,136,42,0.2); box-shadow: 0 4px 30px rgba(201,136,42,0.1); text-align: center; }
.poem-header .deco-corner { position: absolute; top: 0; right: 0; width: 90px; height: 90px; border-bottom-left-radius: 9999px; opacity: 0.18; background: radial-gradient(circle, #e8829a, transparent); }
.poem-header .deco-corner2 { position: absolute; bottom: 0; left: 0; width: 72px; height: 72px; border-top-right-radius: 9999px; opacity: 0.12; background: radial-gradient(circle, #4a9b6f, transparent); }
.poem-header .title-pinyin { color: var(--gold); font-size: 16px; letter-spacing: 0.1em; margin-bottom: 4px; min-height: 22px; font-family: sans-serif; }
.poem-header h1 { font-family: var(--font-display); color: var(--ink); letter-spacing: 0.06em; font-size: 38px; font-weight: 700; margin-bottom: 8px; }
.poem-header .meta { display: flex; align-items: center; justify-content: center; gap: 14px; }
.poem-header .dynasty-tag { font-size: 14px; padding: 4px 14px; border-radius: 9999px; background: rgba(192,57,43,0.08); color: var(--red); border: 1px solid rgba(192,57,43,0.2); }
.poem-header .author-name { color: var(--ink-light); font-size: 16px; }

/* ===== CONTROLS ===== */
.controls { display: flex; justify-content: center; gap: 14px; margin-top: 18px; position: relative; z-index: 1; }
.ctrl-btn { display: flex; align-items: center; gap: 6px; padding: 10px 22px; border-radius: 9999px; font-size: 15px; font-weight: 500; border: 1.5px solid rgba(201,136,42,0.3); cursor: pointer; font-family: var(--font-poem); transition: all 0.2s; background: rgba(201,136,42,0.08); color: var(--gold); }
.ctrl-btn:hover { border-color: var(--gold); }
.ctrl-btn.active-pinyin { background: var(--gold); color: #fff; border-color: var(--gold); }
.ctrl-btn.active-trans { background: var(--jade); color: #fff; border-color: var(--jade); }
.ctrl-btn.active-audio { background: var(--blossom); color: #fff; border-color: var(--blossom); animation: pulse-ring 1.2s ease-in-out infinite; }
@keyframes pulse-ring { 0%,100% { box-shadow: 0 0 0 0 rgba(232,130,154,0.4); } 50% { box-shadow: 0 0 0 10px rgba(232,130,154,0); } }

/* ===== POEM BODY ===== */
.poem-body { border-radius: 20px; padding: 22px; margin-bottom: 20px; background: rgba(255,255,255,0.6); border: 1.5px solid rgba(44,24,16,0.07); backdrop-filter: blur(8px); }

/* ===== POEM LINE ===== */
.poem-line-item { padding: 12px 16px; transition: all 0.2s; border-radius: 10px; position: relative; }
.poem-line-item:hover { background: rgba(232,130,154,0.05); }
.poem-line-item .pinyin-row { font-size: 15px; color: var(--gold); letter-spacing: 0.06em; font-family: sans-serif; margin-bottom: 4px; min-height: 22px; }
.poem-line-item .line-content { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.poem-line-item .line-text { flex: 1; font-size: 22px; line-height: 2; color: var(--ink); }
.poem-line-item .line-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.poem-line-item .line-actions button { font-size: 22px; background: none; border: none; cursor: pointer; line-height: 1; transition: transform 0.15s; padding: 4px; }
.poem-line-item .line-actions button:hover { transform: scale(1.2); }
.poem-line-item .line-actions .star-btn { opacity: 0.35; }
.poem-line-item .line-actions .star-btn.starred { opacity: 1; }

/* ===== TRANSLATION HINT ===== */
.translation-hint { font-size: 17px; color: var(--jade); font-family: var(--font-poem); line-height: 1.9; border-left: 3px solid rgba(74,155,111,0.3); padding-left: 14px; margin-top: 6px; margin-left: 6px; animation: fadeSlideIn 0.25s ease; }
@keyframes fadeSlideIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }

/* ===== KEYWORD ===== */
.keyword { border-bottom: 3px solid #d97706; cursor: pointer; color: #b45309; font-weight: 600; padding: 0 3px; transition: background 0.15s; border-radius: 3px; }
.keyword:hover { background: #fef3c7; }

/* ===== ANNOTATION POPUP ===== */
.annotation-popup { position: fixed; z-index: 999; pointer-events: none; opacity: 0; transform: translateX(-50%) translateY(4px); transition: all 0.2s; }
.annotation-popup.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.annotation-popup .bubble { background: #1e293b; color: #fff; font-size: 16px; border-radius: 14px; padding: 14px 20px; max-width: 260px; box-shadow: 0 8px 30px rgba(0,0,0,0.2); font-family: var(--font-poem); }
.annotation-popup .bubble strong { color: #fbbf24; display: block; margin-bottom: 4px; font-size: 18px; }
.annotation-popup .tail { width: 0; height: 0; margin: 0 auto; border-left: 8px solid transparent; border-right: 8px solid transparent; border-top: 8px solid #1e293b; }

/* ===== LEARN TABS ===== */
.learn-tabs { border-radius: 20px; overflow: hidden; margin-bottom: 30px; background: rgba(255,255,255,0.6); border: 1.5px solid rgba(44,24,16,0.07); backdrop-filter: blur(8px); }
.tab-bar { display: flex; overflow-x: auto; border-bottom: 1px solid rgba(44,24,16,0.07); scrollbar-width: none; }
.tab-bar::-webkit-scrollbar { display: none; }
.tab-item { display: flex; align-items: center; gap: 5px; padding: 16px 20px; font-size: 15px; font-weight: 500; white-space: nowrap; border: none; background: transparent; cursor: pointer; font-family: var(--font-poem); color: var(--ink-light); transition: all 0.2s; flex-shrink: 0; border-bottom: 3px solid transparent; }
.tab-item:hover { color: var(--ink); }
.tab-item.active { color: var(--red); background: rgba(192,57,43,0.04); border-bottom-color: var(--red); }
.tab-content-panel { padding: 24px; font-size: 18px; line-height: 2.2; color: var(--ink); white-space: pre-line; }

/* Tab: translation */
.tab-trans-item { padding: 8px 0; border-bottom: 1px dashed rgba(201,136,42,0.12); font-size: 17px; }
.tab-trans-item:last-child { border-bottom: none; }
.tab-trans-num { display: inline-block; width: 24px; height: 24px; line-height: 24px; border-radius: 50%; background: rgba(232,130,154,0.2); color: var(--blossom); font-size: 13px; text-align: center; margin-right: 10px; font-weight: 600; }

/* Tab: annotations */
.anno-list { display: flex; flex-direction: column; gap: 14px; }
.anno-item { display: flex; align-items: flex-start; gap: 12px; }
.anno-key { font-weight: 700; color: #b45309; white-space: nowrap; min-width: 50px; font-size: 17px; }
.anno-val { color: var(--ink-light); font-size: 17px; flex: 1; line-height: 1.7; }
.anno-audio { background: none; border: none; cursor: pointer; font-size: 18px; padding: 4px; transition: transform 0.15s; flex-shrink: 0; }
.anno-audio:hover { transform: scale(1.2); }

/* Tab audio button */
.tab-audio-btn { display: inline-flex; align-items: center; gap: 6px; margin-top: 14px; padding: 10px 22px; border-radius: 9999px; font-size: 15px; font-weight: 500; border: 1.5px solid rgba(201,136,42,0.3); cursor: pointer; font-family: var(--font-poem); transition: all 0.2s; background: rgba(201,136,42,0.08); color: var(--gold); }
.tab-audio-btn:hover { border-color: var(--gold); }
.tab-audio-btn.speaking { background: var(--blossom); color: #fff; border-color: var(--blossom); }
.tab-empty { text-align: center; padding: 30px; color: #bba; font-size: 17px; }

/* Search highlight */
.search-hl { background: #fde68a; padding: 2px 3px; border-radius: 3px; font-weight: 600; }

/* ===== POEM LIST OVERLAY ===== */
.overlay { position: fixed; inset: 0; background: rgba(44,24,16,0.35); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding-top: 80px; animation: fadeIn 0.2s ease; }
.overlay.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.dropdown { background: var(--paper); border-radius: 20px; max-width: 540px; width: calc(100% - 32px); max-height: 70vh; overflow-y: auto; box-shadow: 0 8px 40px rgba(44,24,16,0.15); padding: 24px; border: 1.5px solid rgba(201,136,42,0.2); }
.dropdown h3 { font-family: var(--font-display); font-size: 20px; margin-bottom: 16px; color: var(--ink); }
.poem-list-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.poem-list-item { padding: 14px 16px; border-radius: 14px; cursor: pointer; transition: all 0.15s; border: 1.5px solid transparent; font-size: 16px; }
.poem-list-item:hover { background: rgba(201,136,42,0.06); border-color: rgba(201,136,42,0.15); }
.poem-list-item.active { background: rgba(232,130,154,0.08); border-color: rgba(232,130,154,0.3); font-weight: 600; }
.pli-author { font-size: 13px; color: #bba; display: block; }

/* ===== LOADING / ERROR ===== */
.loading-wrap { display: flex; flex-direction: column; align-items: center; padding: 80px 20px; color: #bba; font-size: 17px; }
.spinner { width: 44px; height: 44px; border: 3px solid rgba(201,136,42,0.15); border-top-color: var(--gold); border-radius: 50%; animation: spin 0.8s linear infinite; margin-bottom: 16px; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-wrap { display: none; flex-direction: column; align-items: center; padding: 60px 20px; text-align: center; color: var(--ink-light); font-size: 17px; }
.retry-btn { margin-top: 16px; padding: 12px 28px; border-radius: 9999px; border: none; background: var(--blossom); color: #fff; font-weight: 600; font-size: 16px; cursor: pointer; font-family: var(--font-poem); }

/* ===== PETAL FALL ===== */
@keyframes petal-fall {
  0% { transform: translateY(-40px) rotate(0deg) translateX(0px); opacity: 1; }
  50% { transform: translateY(50vh) rotate(360deg) translateX(30px); opacity: 0.7; }
  100% { transform: translateY(105vh) rotate(720deg) translateX(-20px); opacity: 0; }
}
.petal {
  position: fixed; top: -40px;
  animation: petal-fall linear infinite; pointer-events: none; z-index: 0;
  font-size: 20px; user-select: none;
}

/* ===== FOOTER ===== */
.footer {
  text-align: center; padding: 20px; font-size: 15px;
  color: rgba(92,61,46,0.4); border-top: 1px solid rgba(201,136,42,0.1);
  position: relative; z-index: 1; font-family: var(--font-poem);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
  .top-header-inner { flex-wrap: wrap; gap: 8px; justify-content: center; }
  .logo { font-size: 18px; }
  .nav-tab { font-size: 14px; padding: 7px 14px; }
  .poem-header { padding: 24px 18px; }
  .poem-header h1 { font-size: 30px; }
  .poem-line-item .line-text { font-size: 19px; }
  .main-container { padding: 16px 14px 30px; }
  .search-row { flex-wrap: wrap; gap: 8px; }
  .search-box input { font-size: 16px; }
  .nav-btn { font-size: 14px; padding: 10px 16px; }
  .controls { flex-wrap: wrap; gap: 8px; }
  .ctrl-btn { font-size: 14px; padding: 8px 16px; }
  .poem-list-grid { grid-template-columns: 1fr; }
  .tab-item { font-size: 14px; padding: 14px 14px; }
  .tab-content-panel { font-size: 16px; padding: 18px; }
}
