/* =============================================================================
 *  有機化學 3D 位向觀察器 — style.css
 *  清爽教學風格；桌機左右分欄、手機上下堆疊（側欄改為抽屜）。
 * ========================================================================== */

:root {
  --accent: #14857a;
  --accent-light: #1aa193;
  --accent-soft: #e3f1ef;
  --bg: #eef4f5;
  --panel: #ffffff;
  --ink: #1f2b2b;
  --muted: #5d6d6d;
  --border: #dbe6e6;
  --shadow: 0 1px 3px rgba(20, 60, 56, 0.08), 0 6px 18px rgba(20, 60, 56, 0.06);
  --header-h: 60px;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

/* ----------------------------- 頁首 ----------------------------- */
.app-header {
  flex: 0 0 auto;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: linear-gradient(100deg, var(--accent) 0%, var(--accent-light) 100%);
  color: #fff;
  box-shadow: 0 2px 10px rgba(20, 60, 56, 0.18);
  z-index: 30;
}
.title-block h1 { margin: 0; font-size: 1.18rem; font-weight: 700; letter-spacing: .3px; }
.title-block .subtitle { margin: 0; font-size: .72rem; opacity: .85; letter-spacing: .5px; }
.header-actions { margin-left: auto; display: flex; gap: 8px; }

.ghost-btn {
  background: rgba(255, 255, 255, .14);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, .35);
  padding: 7px 13px;
  border-radius: 8px;
  font-size: .82rem;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}
.ghost-btn:hover { background: rgba(255, 255, 255, .26); }
.ghost-btn.active { background: #fff; color: var(--accent); border-color: #fff; font-weight: 600; }

.icon-btn {
  background: rgba(255, 255, 255, .16);
  color: #fff; border: none;
  width: 38px; height: 38px; border-radius: 8px;
  font-size: 1.2rem; cursor: pointer;
}
.menu-btn { display: none; }

/* ----------------------------- 版面 ----------------------------- */
.layout { flex: 1 1 auto; display: flex; min-height: 0; position: relative; }

/* 側欄 */
.sidebar {
  flex: 0 0 296px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 14px 12px 28px;
}
.nav-group { margin-bottom: 18px; }
.nav-group-title {
  font-size: .82rem; font-weight: 700; color: var(--accent);
  padding: 4px 8px 8px; border-bottom: 2px solid var(--accent-soft); margin-bottom: 8px;
}
.mol-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  width: 100%; text-align: left;
  background: transparent; border: 1px solid transparent; border-radius: 9px;
  padding: 8px 11px; margin-bottom: 3px; cursor: pointer;
  transition: background .12s, border-color .12s;
}
.mol-btn:hover { background: var(--accent-soft); }
.mol-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}
.mol-zh { font-size: .92rem; font-weight: 600; color: var(--ink); }
.mol-en { font-size: .72rem; color: var(--muted); }
.cmp-btn .mol-zh { font-size: .85rem; font-weight: 600; }
.cmp-btn { background: #f4f9f8; }

/* 行動版抽屜遮罩 */
.sidebar-scrim { display: none; }

/* 主要工作區 */
.main { flex: 1 1 auto; overflow-y: auto; min-width: 0; padding: 16px 18px 28px; }

/* 資訊列 */
.info-bar {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 18px; box-shadow: var(--shadow); margin-bottom: 14px;
}
.info-main { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.info-bar h2 { margin: 0; font-size: 1.32rem; }
.info-en { font-size: .92rem; font-weight: 500; color: var(--muted); }
.info-meta { display: inline-flex; gap: 8px; margin-left: auto; }
.chip {
  display: inline-block; background: var(--accent); color: #fff;
  padding: 3px 11px; border-radius: 20px; font-size: .8rem; font-weight: 600;
}
.chip-ghost { background: var(--accent-soft); color: var(--accent); }
.info-desc { margin: 10px 0 0; color: #36474a; line-height: 1.65; font-size: .95rem; }
.module-intro {
  margin: 10px 0 0; padding: 9px 13px; background: #f1f8f7;
  border-left: 3px solid var(--accent-light); border-radius: 0 8px 8px 0;
  font-size: .88rem; color: #2c4744; line-height: 1.6;
}

/* ----------------------------- 3D 檢視區 ----------------------------- */
.viewer-section {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px; margin-bottom: 14px;
}
.viewer-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.tool-seg { display: inline-flex; background: #eef3f3; border-radius: 9px; padding: 3px; gap: 2px; }
.seg-btn {
  border: none; background: transparent; color: var(--muted);
  padding: 6px 12px; border-radius: 7px; font-size: .84rem; cursor: pointer; white-space: nowrap;
}
.seg-btn.active { background: #fff; color: var(--accent); font-weight: 700; box-shadow: var(--shadow); }
.tool-divider { width: 1px; height: 24px; background: var(--border); }
.tool-spacer { flex: 1 1 auto; }
.tool-btn {
  border: 1px solid var(--border); background: #fff; color: var(--ink);
  padding: 7px 13px; border-radius: 8px; font-size: .84rem; cursor: pointer; white-space: nowrap;
  transition: all .12s;
}
.tool-btn:hover { border-color: var(--accent-light); }
.tool-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.tool-btn.primary { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.tool-btn.primary:hover { background: var(--accent); color: #fff; }

/* viewer 畫布容器：data-count 決定欄數 */
.viewer-area { display: grid; grid-template-columns: 1fr; gap: 12px; }
.viewer-area[data-count="2"] { grid-template-columns: 1fr 1fr; }
.viewer-area[data-count="3"] { grid-template-columns: 1fr 1fr 1fr; }

.viewer-cell { display: flex; flex-direction: column; min-width: 0; }
.viewer-host {
  position: relative; width: 100%; height: 56vh; min-height: 340px;
  border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
  background: #f7fbfc;
}
.viewer-area[data-count="2"] .viewer-host,
.viewer-area[data-count="3"] .viewer-host { height: 46vh; min-height: 300px; }
.viewer-host canvas { border-radius: 10px; }
.viewer-caption {
  text-align: center; font-size: .82rem; color: var(--muted);
  margin-top: 6px; line-height: 1.35;
}
.viewer-caption strong { color: var(--ink); font-size: .9rem; }
.viewer-hint { text-align: center; color: var(--muted); font-size: .78rem; margin: 10px 0 2px; }

.load-error {
  display: flex; align-items: center; justify-content: center; height: 100%;
  text-align: center; color: #b4452e; padding: 20px; line-height: 1.6;
}

/* ----------------------------- 學習面板 ----------------------------- */
.study-panel { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.study-col {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.study-col h3 { margin: 0 0 10px; font-size: .98rem; color: var(--accent); }
.study-col ul, .study-col ol { margin: 0; padding-left: 20px; }
.study-col li { margin-bottom: 7px; line-height: 1.55; font-size: .9rem; color: #2f3f3f; }
.study-col.teacher { background: #fbfaf3; border-color: #ece6cf; }
.study-col.teacher h3 { color: #9a7d1e; }
.study-col.teacher p { margin: 0; line-height: 1.6; font-size: .9rem; color: #5a4f2c; }

/* ----------------------------- Help Modal ----------------------------- */
.modal {
  position: fixed; inset: 0; background: rgba(15, 35, 33, .5);
  display: none; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal.show { display: flex; }
.modal-card {
  background: #fff; border-radius: 16px; max-width: 540px; width: 100%;
  padding: 26px 28px; position: relative; box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
  max-height: 88vh; overflow-y: auto;
}
.modal-card h2 { margin: 0 0 14px; color: var(--accent); }
.modal-close {
  position: absolute; top: 14px; right: 14px; border: none; background: #eef3f3;
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer; font-size: 1rem; color: var(--muted);
}
.help-list { padding-left: 22px; line-height: 1.75; }
.help-list li { margin-bottom: 4px; }
.help-note {
  background: #fff7ed; border-left: 3px solid #e0a458; border-radius: 0 8px 8px 0;
  padding: 11px 14px; font-size: .88rem; line-height: 1.6; color: #6b4f24;
}
.help-foot { font-size: .78rem; color: var(--muted); margin-bottom: 0; }

/* ----------------------------- 教師投影模式 ----------------------------- */
.projection .sidebar, .projection .sidebar-scrim { display: none; }
.projection .module-intro, .projection .study-col.teacher { display: none; }
.projection .viewer-host { height: 68vh; }
.projection .viewer-area[data-count="2"] .viewer-host,
.projection .viewer-area[data-count="3"] .viewer-host { height: 60vh; }
.projection .study-panel { grid-template-columns: 1fr 1fr; }
.projection .info-bar h2 { font-size: 1.5rem; }

/* ----------------------------- 響應式：平板 ----------------------------- */
@media (max-width: 1080px) {
  .study-panel { grid-template-columns: 1fr; }
}

/* ----------------------------- 響應式：手機 ----------------------------- */
@media (max-width: 820px) {
  .menu-btn { display: inline-flex; align-items: center; justify-content: center; }
  .title-block h1 { font-size: 1rem; }
  .title-block .subtitle { display: none; }
  .header-actions .ghost-btn { padding: 7px 10px; font-size: .76rem; }

  /* 側欄 → 左側抽屜 */
  .sidebar {
    position: fixed; top: var(--header-h); left: 0; bottom: 0; width: 82%; max-width: 320px;
    transform: translateX(-100%); transition: transform .22s ease; z-index: 25;
    box-shadow: 4px 0 24px rgba(0, 0, 0, .18);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-scrim {
    display: block; position: fixed; inset: var(--header-h) 0 0 0;
    background: rgba(0, 0, 0, .35); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 24;
  }
  body.sidebar-open .sidebar-scrim { opacity: 1; pointer-events: auto; }

  .main { padding: 12px; }
  .viewer-host, .viewer-area[data-count="2"] .viewer-host,
  .viewer-area[data-count="3"] .viewer-host { height: 55vh; min-height: 300px; }
  /* 比較模式在手機改為單欄堆疊 */
  .viewer-area[data-count="2"], .viewer-area[data-count="3"] { grid-template-columns: 1fr; }
  .info-meta { margin-left: 0; }
  .viewer-toolbar { gap: 6px; }
  .seg-btn, .tool-btn { padding: 8px 11px; font-size: .82rem; }
  .tool-spacer { flex-basis: 100%; height: 0; }
}

@media (max-width: 420px) {
  .header-actions #btn-help { display: none; }
}
