/**
 * Trees Pinyin - 全域樣式表 (Global Stylesheet)
 * 包含頂部導覽列、膠囊輸入面板、四位一體注音卡片、錄影工坊、記憶閃卡與響應式列印樣式
 */
:root {
      --bg: #f5f7f9;
      --card: #ffffff;
      --text: #111111;
      --muted: #555555;
      --accent: #1b5e20;
      --accent-hover: #2e7d32;
      --accent-soft: #e8f5e9;
      --blue: #1565c0;
      --border: #dcdcdc;
      --danger: #d32f2f;
    }
    * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
    body {
      margin: 0;
      padding: 0 0 36px;
      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
      background: var(--bg);
      color: var(--text);
      display: flex;
      flex-direction: column;
      align-items: center;
      min-height: 100vh;
    }
    .hidden { display: none !important; }

    /* ================= Navbar ================= */
    .navbar {
      width: 100%;
      background: #ffffff;
      border-bottom: 1px solid #e5e7eb;
      padding: 8px 20px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      position: sticky;
      top: 0;
      z-index: 1000;
      box-shadow: 0 1px 4px rgba(0,0,0,0.03);
      gap: 10px;
    }
    .nav-left {
      display: flex;
      align-items: center;
      gap: 10px;
      text-decoration: none;
      color: inherit;
    }
    .brand-logo {
      width: 34px;
      height: 34px;
      border-radius: 8px;
      object-fit: cover;
      flex-shrink: 0;
    }
    .brand-title {
      font-size: 1.15rem;
      font-weight: 800;
      color: var(--accent);
      line-height: 1.2;
    }

    .nav-center, .nav-right {
      display: flex;
      align-items: center;
      gap: 8px;
    }
    .dropdown {
      position: relative;
      display: inline-block;
    }
    .nav-btn {
      background: #fff;
      border: 1px solid #d0d7de;
      border-radius: 10px;
      padding: 6px 12px;
      font-size: 0.84rem;
      font-weight: 700;
      color: #222;
      cursor: pointer;
      display: inline-flex;
      align-items: center;
      gap: 6px;
      transition: all 0.15s;
      text-decoration: none;
      white-space: nowrap;
    }
    .nav-btn:hover {
      background: #f3f4f6;
      border-color: #adb5bd;
    }
    .nav-btn.has-key {
      border-color: #2e7d32;
      color: #1b5e20;
      background: #e8f5e9;
    }
    .nav-btn.login-btn {
      background: var(--accent);
      color: #fff;
      border-color: var(--accent);
    }
    .nav-btn.login-btn:hover {
      background: var(--accent-hover);
    }
    .btn-mini-icon {
      width: 16px;
      height: 16px;
      border-radius: 4px;
      object-fit: cover;
    }

    .dropdown-menu {
      display: none;
      position: absolute;
      top: calc(100% + 6px);
      left: 0;
      background: #fff;
      min-width: 200px;
      border-radius: 12px;
      border: 1px solid #e5e7eb;
      box-shadow: 0 10px 25px rgba(0,0,0,0.12);
      padding: 6px;
      z-index: 2000;
    }
    .dropdown-menu.right-align {
      left: auto;
      right: 0;
    }
    .dropdown.open .dropdown-menu {
      display: block;
    }
    .dropdown-item {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 8px 12px;
      color: #222;
      text-decoration: none;
      font-size: 0.85rem;
      font-weight: 600;
      border-radius: 8px;
      transition: background 0.15s;
      cursor: pointer;
    }
    .dropdown-item:hover {
      background: var(--accent-soft);
      color: var(--accent);
    }
    .dropdown-divider {
      height: 1px;
      background: #e5e7eb;
      margin: 4px 0;
    }

    /* ================= Main Container ================= */
    .main-wrap {
      width: 100%;
      max-width: 920px;
      padding: 12px 16px 0;
      display: flex;
      flex-direction: column;
      gap: 10px;
    }
    .tab-panel {
      display: flex;
      flex-direction: column;
      gap: 10px;
      width: 100%;
    }

    .panel {
      width: 100%;
      background: var(--card);
      padding: 12px 14px;
      border-radius: 16px;
      box-shadow: 0 2px 10px rgba(0,0,0,0.03);
      border: 1px solid var(--border);
      display: flex;
      flex-direction: column;
      gap: 10px;
    }
    .search-box {
      display: flex;
      align-items: center;
      border: 1.5px solid #cbd5e1;
      border-radius: 14px;
      padding: 6px 8px 6px 12px;
      background: #fff;
      gap: 8px;
      transition: border-color 0.2s, box-shadow 0.2s;
    }
    .search-box:focus-within {
      border-color: var(--accent);
      box-shadow: 0 0 0 3px rgba(27, 94, 32, 0.1);
    }
    textarea {
      flex: 1;
      border: none;
      font-size: 0.96rem;
      line-height: 1.4;
      resize: vertical;
      outline: none;
      font-family: inherit;
      padding: 2px 0;
      background: transparent;
      min-height: 42px;
    }

    /* 膠囊內麥克風左側的 EN / 中文 語音切換小標籤 (預設 EN) */
    .voice-lang-toggle {
      height: 32px;
      padding: 0 11px;
      border-radius: 999px;
      border: 1.5px solid #c8e6c9;
      background: #e8f5e9;
      color: #1b5e20;
      font-size: 0.8rem;
      font-weight: 800;
      cursor: pointer;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;
      user-select: none;
      transition: all 0.15s;
    }
    .voice-lang-toggle:hover {
      background: #1b5e20;
      color: #ffffff;
      border-color: #1b5e20;
    }
    .voice-lang-toggle.zh-mode {
      background: #e8f0fe;
      color: #1565c0;
      border-color: #bfdbfe;
    }
    .voice-lang-toggle.zh-mode:hover {
      background: #1565c0;
      color: #ffffff;
      border-color: #1565c0;
    }

    .icon-action {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      border: none;
      background: #f1f3f4;
      color: #333;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      flex-shrink: 0;
      transition: background 0.15s;
    }
    .icon-action:hover { background: #e2e8f0; }
    .icon-action:active { background: #cbd5e1; }
    .icon-action svg { width: 21px; height: 21px; fill: currentColor; }
    .icon-action.recording {
      background: var(--danger);
      color: #fff;
      animation: pulse 1s infinite;
    }
    @keyframes pulse { 50% { opacity: 0.45; } }

    .action-row {
      display: flex;
      gap: 8px;
      align-items: center;
    }
    .btn {
      flex: 1;
      padding: 10px 14px;
      border: none;
      border-radius: 10px;
      font-size: 0.92rem;
      font-weight: 700;
      cursor: pointer;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 6px;
      white-space: nowrap;
      transition: filter 0.15s, transform 0.1s;
    }
    .btn:hover { filter: brightness(1.06); }
    .btn:active { transform: translateY(1px); }
    .btn-blue { background: var(--blue); color: #fff; }
    .btn-green { background: var(--accent); color: #fff; }
    .btn-soft { background: var(--accent-soft); color: var(--accent); border: 1px solid #c8e6c9; }
    .btn-dark { background: #222; color: #fff; font-size: 0.84rem; padding: 8px 14px; border-radius: 10px; flex: unset; }

    /* Disclaimer Banner (Original Text Preserved) */
    .disclaimer-banner {
      background: #fffdf5;
      border: 1px solid #fde68a;
      border-left: 4px solid #f59e0b;
      border-radius: 10px;
      padding: 9px 14px;
      font-size: 0.82rem;
      color: #4b5563;
      line-height: 1.45;
    }

    /* Minimal Bottom Bar: Only Layout, Print, Record Video */
    .bottom-bar {
      width: 100%;
      background: #ffffff;
      border: 1px solid var(--border);
      border-radius: 14px;
      padding: 10px 16px;
      display: flex;
      align-items: center;
      justify-content: flex-start;
      gap: 10px;
      flex-wrap: wrap;
    }
    .layout-popover {
      min-width: 280px;
      padding: 14px;
      display: none;
      flex-direction: column;
      gap: 10px;
      position: absolute;
      bottom: calc(100% + 8px);
      left: 0;
      background: #fff;
      border: 1px solid #cbd5e1;
      border-radius: 14px;
      box-shadow: 0 10px 30px rgba(0,0,0,0.15);
      z-index: 2500;
      font-size: 0.85rem;
      font-weight: 600;
    }
    .dropdown.open .layout-popover { display: flex; }
    .chk-row { display: flex; flex-direction: column; gap: 6px; }
    .chk-row label { display: flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
    .chk-row input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }
    .layout-select { padding: 6px 9px; border-radius: 8px; border: 1px solid #cbd5e1; font-size: 0.83rem; background: #fff; width: 100%; }

    /* ================= Clean 4-in-1 Sheet Card ================= */
    .sheet-card {
      width: 100%;
      background: #ffffff;
      padding: 14px 18px;
      border-radius: 16px;
      border: 1px solid var(--border);
      box-shadow: 0 3px 12px rgba(0,0,0,0.03);
      min-height: 76px;
      display: flex;
      flex-direction: column;
      align-items: center;
      text-align: center;
      gap: 10px;
      --user-font-size: 20px;
    }
    .sheet-card.align-left {
      align-items: flex-start;
      text-align: left;
    }
    .sheet-card.align-left .char-row {
      justify-content: flex-start;
    }
    .sheet-card.align-left .sentence-block {
      align-items: flex-start;
    }
    .print-header-title {
      font-size: 1.4rem;
      font-weight: 800;
      color: #111;
      margin-bottom: 2px;
      display: none;
    }
    .preview-img {
      max-width: 80%;
      max-height: 150px;
      border-radius: 10px;
      object-fit: contain;
      display: none;
    }
    .ai-reply-box {
      width: 100%;
      background: #f0fdf4;
      border: 1px solid #bbf7d0;
      border-radius: 10px;
      padding: 8px 14px;
      font-size: 0.9rem;
      font-weight: 600;
      color: #166534;
      line-height: 1.45;
      text-align: center;
      display: none;
      word-break: break-word;
    }
    .ai-reply-box.friendly-reminder {
      background: #fffbeb;
      border: 1.5px solid #fcd34d;
      color: #92400e;
    }
    .ai-reply-box.diag-info {
      background: #eff6ff;
      border: 1px solid #bfdbfe;
      color: #1e40af;
      font-size: 0.82rem;
    }
    .annotation-list {
      width: 100%;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 16px;
    }
    .sentence-block {
      width: 100%;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 6px;
      padding-bottom: 12px;
      border-bottom: 1px dashed #e5e7eb;
    }
    .sentence-block:last-child { border-bottom: none; padding-bottom: 0; }
    .en-line {
      font-size: calc(var(--user-font-size) * 0.92);
      font-weight: 600;
      color: #111;
      line-height: 1.4;
      word-break: normal;
      overflow-wrap: break-word;
      max-width: 96%;
    }
    .char-row {
      display: flex;
      flex-wrap: wrap;
      justify-content: center;
      gap: 8px 0;
      align-items: flex-end;
    }
    .tp-col {
      display: inline-flex;
      flex-direction: column;
      align-items: center;
      justify-content: flex-end;
      margin: 0 0.28ch;
      cursor: pointer;
      padding: 2px 3px;
      border-radius: 6px;
      transition: background 0.12s;
      user-select: none;
      -webkit-user-select: none;
      -webkit-touch-callout: none;
    }
    .tp-col:hover { background: #f1f8e9; }
    .tp-col:active { background: #c8e6c9; }
    .tp-py {
      font-size: calc(var(--user-font-size) * 0.96);
      font-weight: 700;
      font-style: italic;
      color: #1b5e20;
      line-height: 1.16;
      white-space: nowrap;
    }
    .tp-std {
      font-size: calc(var(--user-font-size) * 0.78);
      font-weight: 500;
      color: #6b7280;
      line-height: 1.15;
      white-space: nowrap;
    }
    .tp-zh {
      font-size: calc(var(--user-font-size) * 1.25);
      font-weight: 600;
      color: #000;
      line-height: 1.22;
      min-height: 1.22em;
    }

    /* Dynamic Row Visibility */
    .sheet-card.hide-en .en-line, .studio-top-pane.hide-en .en-line { display: none !important; }
    .sheet-card.hide-tp .tp-py, .studio-top-pane.hide-tp .tp-py { display: none !important; }
    .sheet-card.hide-std .tp-std, .studio-top-pane.hide-std .tp-std { display: none !important; }
    .sheet-card.hide-zh .tp-zh, .studio-top-pane.hide-zh .tp-zh { display: none !important; }

    /* ================= 🟢 Floating icon.png + Mini Popover ================= */
    .selection-icon-only {
      position: absolute;
      display: none;
      z-index: 200010;
      width: 36px;
      height: 36px;
      border-radius: 50%;
      background: #1b5e20;
      border: 2px solid #ffffff;
      box-shadow: 0 4px 14px rgba(27,94,32,0.48);
      cursor: pointer;
      padding: 3px;
      transition: transform 0.15s;
    }
    .selection-icon-only:hover { transform: scale(1.12); }
    .selection-icon-only img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }

    .selection-mini-popover {
      position: absolute;
      display: none;
      z-index: 200011;
      width: 92vw;
      max-width: 440px;
      background: #ffffff;
      border: 2px solid var(--accent);
      border-radius: 16px;
      box-shadow: 0 12px 35px rgba(0,0,0,0.25);
      padding: 12px;
      flex-direction: column;
      gap: 8px;
    }

    /* ================= 🎬 Video Studio Overlay ================= */
    .studio-overlay {
      display: none;
      position: fixed;
      top: 0; left: 0; width: 100vw; height: 100vh;
      background: #0f172a;
      z-index: 100000;
      flex-direction: column;
      align-items: center;
      justify-content: space-between;
      padding: 10px;
      color: #fff;
    }
    .studio-overlay.active { display: flex; }
    .studio-top-bar {
      width: 100%; max-width: 900px;
      display: flex; justify-content: space-between; align-items: center;
      flex-wrap: wrap; gap: 8px;
      background: rgba(255,255,255,0.08);
      padding: 8px 12px; border-radius: 12px;
    }
    .studio-select {
      background: #1e293b; color: #fff; border: 1px solid #475569;
      border-radius: 8px; padding: 6px 10px; font-size: 0.82rem; font-weight: 700; outline: none;
    }
    .studio-mode-pill {
      padding: 6px 12px; border-radius: 18px; border: 1px solid rgba(255,255,255,0.25);
      background: transparent; color: #fff; font-size: 0.8rem; font-weight: 700; cursor: pointer;
    }
    .studio-mode-pill.active { background: var(--accent); border-color: #a5d6a7; }

    .studio-stage {
      position: relative; background: #ffffff; color: #111; border-radius: 16px;
      overflow: hidden; display: flex; flex-direction: column;
      box-shadow: 0 10px 40px rgba(0,0,0,0.5); border: 2px solid #334155;
      --user-font-size: 19px;
    }
    .studio-stage.ratio-9-16 { width: min(92vw, 380px); height: min(76vh, 675px); }
    .studio-stage.ratio-16-9 { width: min(94vw, 820px); height: min(72vh, 461px); }

    .studio-top-pane {
      flex: 1; overflow-y: auto; padding: 14px 12px; background: #ffffff;
      display: flex; flex-direction: column; align-items: center; text-align: center; gap: 14px;
      scroll-behavior: smooth; border-bottom: 2px solid #1b5e20;
    }
    .studio-bottom-pane {
      flex: 1; position: relative; background: #000; overflow: hidden;
      display: flex; align-items: center; justify-content: center;
    }
    .studio-bottom-pane video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }

    .studio-stage.view-full-text .studio-bottom-pane { display: none !important; }
    .studio-stage.view-full-text .studio-top-pane { flex: 1; height: 100%; border-bottom: none; }
    .studio-stage.view-full-cam .studio-top-pane { display: none !important; }
    .studio-stage.view-full-cam .studio-bottom-pane { flex: 1; height: 100%; }

    .studio-bottom-controls {
      width: 100%; max-width: 900px; display: flex; justify-content: center;
      align-items: center; gap: 10px; flex-wrap: wrap; padding: 6px;
    }

    /* ================= Mnemonic Cards ================= */
    .reward-banner {
      background: #ffffff; border: 1px solid var(--border); border-radius: 16px;
      padding: 14px 16px; display: flex; flex-direction: column; gap: 10px;
    }
    .reward-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
    .mnemonic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; width: 100%; }
    .mnemonic-card {
      background: #ffffff; border: 1px solid #dce3ea; border-radius: 14px; padding: 14px;
      display: flex; flex-direction: column; gap: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.03);
    }
    .mc-top { display: flex; flex-direction: column; gap: 4px; border-bottom: 1px dashed #e5e7eb; padding-bottom: 8px; }
    .mc-meaning { font-size: 1rem; font-weight: 800; color: var(--accent); }
    .mc-trees { font-size: 1.05rem; color: #111; }
    .mc-hanzi { font-size: 0.92rem; font-weight: 600; color: #444; }
    .mc-sound, .mc-tip { font-size: 0.85rem; line-height: 1.48; color: #222; }
    .locked-pack-box { background: #fff8e1; border: 1.5px dashed #ffb300; border-radius: 14px; padding: 24px 18px; text-align: center; }

    .share-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; width: 100%; }
    .share-app-btn {
      padding: 10px 12px; border-radius: 10px; border: 1px solid #d0d7de; background: #f8fafc;
      font-size: 0.86rem; font-weight: 700; color: #111; cursor: pointer;
      display: flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
    }

    /* Modals */
    .modal {
      display: none; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
      background: rgba(0,0,0,0.55); z-index: 200005; justify-content: center; align-items: center; padding: 16px;
    }
    .modal-box {
      background: #fff; width: 100%; max-width: 420px; border-radius: 16px;
      padding: 20px; display: flex; flex-direction: column; gap: 12px;
      box-shadow: 0 10px 30px rgba(0,0,0,0.2);
      color: #111;
    }
    .option-card-btn {
      width: 100%; padding: 13px 14px; border: 1.5px solid #d0d7de; border-radius: 12px;
      background: #f8fafc; color: #111; font-size: 0.95rem; font-weight: 700;
      cursor: pointer; display: flex; align-items: center; justify-content: space-between; text-align: left;
    }
    .option-card-btn:hover { background: #e8f5e9; border-color: var(--accent); }
    .notice-box { font-size: 0.86rem; line-height: 1.55; background: #fff8e1; border: 1px solid #ffe082; color: #333; padding: 12px; border-radius: 10px; }

    @media (max-width: 768px) {
      .navbar { padding: 8px 12px; flex-wrap: wrap; }
      .action-row { flex-wrap: wrap; }
    }
    @media print {
      .navbar, .panel, .disclaimer-banner, .bottom-bar, .preview-img,
      .selection-icon-only, .selection-mini-popover, .studio-overlay { display: none !important; }
      body { background: #fff; padding: 0; }
      .main-wrap { max-width: 100%; padding: 0; }
      .sheet-card { border: none; box-shadow: none; padding: 8mm; }
      .print-header-title.has-title { display: block !important; }
    }
