:root {
    --ink: #1a1410;
    --rust: #b84c2b;
    --warm-bg: #f7f2eb;
    --paper: #fdf9f4;
    --muted: #6b5e52;
    --rule: #d4c9b8;
    --accent-bg: #2c1f14;
    --gold: #c8973a;
  }

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

  body {
    background: var(--warm-bg);
    color: var(--ink);
    font-family: 'Noto Sans TC', sans-serif;
    font-weight: 300;
    line-height: 1.9;
    font-size: 16px;
  }

  .masthead {
    background: var(--accent-bg);
    color: var(--warm-bg);
    padding: 18px 0 14px;
    text-align: center;
    letter-spacing: 0.35em;
    font-size: 11px;
    font-weight: 400;
    text-transform: uppercase;
    color: var(--gold);
  }

  .hero {
    background: var(--paper);
    border-bottom: 3px solid var(--ink);
    padding: 60px 40px 48px;
    max-width: 860px;
    margin: 0 auto;
    position: relative;
  }

  .hero::before {
    content: '';
    display: block;
    width: 48px;
    height: 4px;
    background: var(--rust);
    margin-bottom: 28px;
  }

  h2 {
    font-family: 'Noto Serif TC', serif;
    font-weight: 900;
    font-size: clamp(26px, 4vw, 38px);
    line-height: 1.3;
    color: var(--ink);
    letter-spacing: 0.02em;
    margin-bottom: 20px;
  }

  .subtitle {
    font-size: 14px;
    color: var(--muted);
    letter-spacing: 0.12em;
    border-left: 2px solid var(--rust);
    padding-left: 14px;
  }

  .article-body {
    max-width: 860px;
    margin: 0 auto;
    padding: 0 40px 80px;
    background: var(--paper);
  }

  h3 {
    font-family: 'Noto Serif TC', serif;
    font-weight: 700;
    font-size: 19px;
    color: var(--ink);
    margin: 52px 0 18px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--rule);
    letter-spacing: 0.04em;
  }

  h3.section-label {
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.25em;
    color: var(--rust);
    border: none;
    margin-bottom: 8px;
    padding: 0;
    text-transform: uppercase;
    font-family: 'Noto Sans TC', sans-serif;
  }

  p {
    margin-bottom: 18px;
    color: #2e2620;
    font-size: 15.5px;
  }

  .callout {
    background: var(--accent-bg);
    color: var(--warm-bg);
    padding: 28px 32px;
    margin: 36px 0;
    border-left: 4px solid var(--gold);
  }

  .callout p {
    color: #e8dfd4;
    margin: 0;
    font-size: 15px;
    line-height: 1.85;
  }

  .callout strong {
    color: var(--gold);
  }

  table {
    width: 100%;
    border-collapse: collapse;
    margin: 24px 0 32px;
    font-size: 14.5px;
  }

  thead tr {
    background: var(--ink);
    color: var(--warm-bg);
  }

  thead th {
    padding: 13px 16px;
    text-align: left;
    font-weight: 500;
    letter-spacing: 0.06em;
    font-size: 13px;
  }

  tbody tr {
    border-bottom: 1px solid var(--rule);
  }

  tbody tr:nth-child(even) {
    background: #f0ebe2;
  }

  tbody td {
    padding: 12px 16px;
    color: var(--ink);
    vertical-align: top;
  }

  tbody td:first-child {
    font-weight: 500;
    color: var(--rust);
  }

  .tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.78rem;
    font-weight: 500;
  }
  .tag-green { background: #dcfce7; color: #166534; }
  .tag-amber { background: #fef3c7; color: #92400e; }
  .tag-red   { background: #fee2e2; color: #991b1b; }
  .tag-blue  { background: #dbeafe; color: #1e40af; }

  .matrix-wrap {
    overflow-x: auto;
    margin: 24px 0 32px;
  }

  .matrix {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
  }

  .matrix th, .matrix td {
    border: 1px solid var(--rule);
    padding: 14px 16px;
    text-align: center;
  }

  .matrix thead th {
    background: var(--ink);
    color: var(--warm-bg);
    font-weight: 500;
    font-size: 13px;
  }

  .matrix .row-header {
    background: #2c1f14;
    color: var(--warm-bg);
    font-weight: 500;
    text-align: left;
    font-size: 13px;
  }

  .matrix td.champion {
    background: #fff5e6;
    font-weight: 600;
    color: var(--rust);
    border-color: var(--gold);
  }

  .matrix td.good {
    background: #f5ede0;
  }

  .insight-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin: 28px 0;
  }

  .insight-card {
    border: 1px solid var(--rule);
    padding: 22px 20px;
    background: var(--warm-bg);
  }

  .insight-card .label {
    font-size: 11px;
    letter-spacing: 0.2em;
    color: var(--muted);
    text-transform: uppercase;
    margin-bottom: 10px;
    font-family: 'Noto Sans TC', sans-serif;
  }

  .insight-card .verdict {
    font-family: 'Noto Serif TC', serif;
    font-weight: 700;
    font-size: 15px;
    color: var(--ink);
    line-height: 1.5;
    margin-bottom: 8px;
  }

  .insight-card .detail {
    font-size: 13px;
    color: var(--muted);
    line-height: 1.7;
  }

  .conclusion {
    background: var(--rust);
    color: white;
    padding: 36px 32px;
    margin-top: 52px;
  }

  .conclusion h3 {
    color: white;
    border-color: rgba(255,255,255,0.3);
    margin-top: 0;
    font-size: 18px;
  }

  .conclusion p {
    color: rgba(255,255,255,0.92);
    font-size: 15px;
  }

  .divider {
    border: none;
    border-top: 1px solid var(--rule);
    margin: 40px 0;
  }

  @media (max-width: 600px) {
    .hero, .article-body { padding-left: 20px; padding-right: 20px; }
    .insight-grid { grid-template-columns: 1fr; }
    h2 { font-size: 24px; }
  }

  /* =====================================================================
     Shared report-widget components (used by money/ report pages, e.g.
     invest_stock.php). Kept here so every page draws from one definition
     instead of re-declaring these in local <style> blocks.
     ===================================================================== */

  .kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin: 1rem 0 1.5rem; }
  .kpi { background: #f0f0f8; border-radius: 8px; padding: 12px 16px; }
  .kpi-label { font-size: 0.78rem; color: #666; margin-bottom: 4px; }
  .kpi-value { font-size: 1.35rem; font-weight: 600; color: #1a1a2e; }
  .kpi-sub { font-size: 0.78rem; color: #888; margin-top: 2px; }

  .up { color: #166534; }
  .down { color: #991b1b; }

  .note { font-size: 0.82rem; color: #666; margin-top: 1rem; border-top: 1px solid #ddd; padding-top: 0.6rem; }

  .box-red    { background:#fdecea; border-left:3px solid #c0392b; padding:12px 16px; margin:14px 0; font-size:13.5px; line-height:1.9; }
  .box-green  { background:#eafaf1; border-left:3px solid #27ae60; padding:12px 16px; margin:14px 0; font-size:13.5px; line-height:1.9; }
  .box-blue   { background:#eaf4fb; border-left:3px solid #2980b9; padding:12px 16px; margin:14px 0; font-size:13.5px; line-height:1.9; }
  .box-orange { background:#fef9ec; border-left:3px solid #e67e22; padding:12px 16px; margin:14px 0; font-size:13.5px; line-height:1.9; }
  .box-gray   { background:#f4f4f4; border-left:3px solid #999; padding:12px 16px; margin:14px 0; font-size:13.5px; line-height:1.9; }

  .eq { background:#f7f7f7; border:1px solid #ddd; border-radius:4px; padding:10px 16px; font-family:monospace; font-size:13.5px; margin:10px 0; line-height:2; }

  table.t { border-collapse:collapse; width:100%; font-size:13.5px; margin:14px 0; }
  table.t th { background:#1a1a2e; color:#f5a623; padding:9px 14px; border:1px solid #2e2e4e; text-align:left; }
  table.t td { padding:8px 14px; border:1px solid #dde; vertical-align:top; line-height:1.8; }
  table.t tr:nth-child(even) td { background:#f7f7fc; }

  .section-label { display:inline-block; background:#1a1a2e; color:#f5a623; font-size:10px; letter-spacing:0.2em; padding:3px 10px; border-radius:2px; margin-bottom:10px; text-transform:uppercase; }

  .two-col { display:grid; grid-template-columns:1fr 1fr; gap:14px; margin:14px 0; }
  @media (max-width:600px) { .two-col { grid-template-columns:1fr; } }
  .col-card { border:1px solid #dde; border-radius:4px; padding:13px 15px; font-size:13.5px; line-height:1.9; }
  .col-card h4 { margin:0 0 8px; font-size:13px; }

  .rank-badge { display:inline-block; border-radius:3px; font-size:11px; font-weight:700; padding:2px 8px; margin-right:4px; }
  .r1 { background:#f5a623; color:#fff; }
  .r2 { background:#aaa; color:#fff; }
  .r3 { background:#cd7f32; color:#fff; }
  .rn { background:#ddd; color:#555; }

  .arrow-up   { color:#27ae60; font-weight:700; font-size:15px; }
  .arrow-down { color:#c0392b; font-weight:700; font-size:15px; }
  .arrow-flat { color:#aaa; font-weight:700; font-size:15px; }

  .event-table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
  .event-table th { background: #1a1a2e; color: #f5a623; padding: 8px 12px; border: 1px solid #2e2e4e; text-align: left; }
  .event-table td { padding: 7px 12px; border: 1px solid #dde; vertical-align: top; }
  .event-table tr:nth-child(even) td { background: #f7f7fc; }
  .event-table tr:hover td { background: #fff3dc; }

  .lynch-table { width:100%; border-collapse: collapse; margin: 12px 0; }
  .lynch-table td { padding:8px; border:1px solid #ddd; }
  .lynch-table td.label { width:30%; background:#f0f0f0; }
  .lynch-callout { background:#eef6fb; border-left:4px solid #4a90d9; padding:12px 16px; margin:16px 0; }
  .lynch-callout h3 { margin-top:0; }
  .lynch-callout p { margin-bottom:0; }

  /* =====================================================================
     .pe-panel — dark "terminal" card used for chart/data-heavy widgets
     (e.g. the TWSE PE-ratio history chart in invest_stock.php). Fully
     scoped under .pe-panel so it never touches page-level body/h1/etc.
     ===================================================================== */

  .pe-panel {
    --bg: #0a0c14;
    --surface: #111420;
    --border: #1e2235;
    --text: #e8e6f0;
    --muted: #6b6d82;
    --accent: #f5a623;
    --accent2: #e05252;
    --accent3: #52b8e0;
    --accent4: #7ed957;
    --line: #f5a623;
    position: relative;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: 'Space Mono', monospace;
    border-radius: 8px;
    margin: 1.5rem 0;
  }
  .pe-panel .noise {
    position: absolute; inset: 0; pointer-events: none; z-index: 0;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  }
  .pe-panel .container {
    position: relative; z-index: 1;
    max-width: 1100px; margin: 0 auto; padding: 40px 24px;
  }
  .pe-panel header {
    margin-bottom: 36px;
    border-left: 3px solid var(--accent);
    padding-left: 16px;
  }
  .pe-panel .title-label {
    font-size: 10px; letter-spacing: 0.25em;
    text-transform: uppercase; color: var(--accent);
    margin-bottom: 8px;
  }
  .pe-panel h1 {
    font-family: 'Noto Serif TC', serif;
    font-size: clamp(22px, 4vw, 34px);
    font-weight: 700; color: var(--text);
    line-height: 1.3;
  }
  .pe-panel .subtitle {
    font-size: 12px; color: var(--muted); margin-top: 8px;
    letter-spacing: 0.05em;
    border-left: none; padding-left: 0;
  }

  .pe-panel .stats-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px; margin-bottom: 28px;
  }
  .pe-panel .stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 14px 16px;
    border-radius: 4px;
    transition: border-color 0.2s;
  }
  .pe-panel .stat-card:hover { border-color: var(--accent); }
  .pe-panel .stat-label { font-size: 9px; letter-spacing: 0.2em; color: var(--muted); text-transform: uppercase; margin-bottom: 4px; }
  .pe-panel .stat-value { font-size: 20px; font-weight: 700; color: var(--accent); }
  .pe-panel .stat-sub { font-size: 10px; color: var(--muted); margin-top: 2px; }

  .pe-panel .chart-wrapper {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 24px 16px 16px;
    margin-bottom: 20px;
    position: relative;
  }
  .pe-panel .chart-title-row {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px; padding: 0 8px;
  }
  .pe-panel .chart-title { font-size: 11px; letter-spacing: 0.15em; color: var(--muted); text-transform: uppercase; }
  .pe-panel .legend {
    display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
  }
  .pe-panel .legend-item {
    display: flex; align-items: center; gap: 6px;
    font-size: 10px; color: var(--muted); cursor: pointer;
    transition: color 0.2s;
  }
  .pe-panel .legend-item:hover { color: var(--text); }
  .pe-panel .legend-dot {
    width: 10px; height: 3px; border-radius: 2px;
  }
  .pe-panel canvas {
    width: 100% !important;
    display: block;
  }

  .pe-panel .tooltip {
    position: absolute;
    background: rgba(10, 12, 20, 0.95);
    border: 1px solid var(--accent);
    padding: 10px 14px;
    border-radius: 4px;
    font-size: 11px;
    pointer-events: none;
    display: none;
    z-index: 100;
    min-width: 160px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  }
  .pe-panel .tooltip-date { color: var(--muted); font-size: 10px; margin-bottom: 6px; }
  .pe-panel .tooltip-row { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 3px; }
  .pe-panel .tooltip-key { color: var(--muted); }
  .pe-panel .tooltip-val { font-weight: 700; }

  .pe-panel .events-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden; margin-bottom: 20px;
  }
  .pe-panel .events-header {
    padding: 12px 18px;
    border-bottom: 1px solid var(--border);
    font-size: 10px; letter-spacing: 0.2em; color: var(--muted);
    text-transform: uppercase;
  }
  .pe-panel .events-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0;
  }
  .pe-panel .event-item {
    padding: 12px 18px;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
  }
  .pe-panel .event-item:hover { background: rgba(245, 166, 35, 0.04); }
  .pe-panel .event-year {
    font-size: 10px; color: var(--accent); font-weight: 700;
    margin-bottom: 3px; letter-spacing: 0.1em;
  }
  .pe-panel .event-desc { font-family: 'Noto Serif TC', serif; font-size: 12px; color: var(--text); line-height: 1.5; }
  .pe-panel .event-pe { font-size: 10px; color: var(--muted); margin-top: 3px; }

  .pe-panel .zones-note {
    font-size: 10px; color: var(--muted);
    padding: 12px 18px;
    border-top: 1px solid var(--border);
    display: flex; gap: 20px; flex-wrap: wrap;
  }
  .pe-panel .zone { display: flex; align-items: center; gap: 6px; }
  .pe-panel .zone-bar { width: 14px; height: 6px; border-radius: 1px; }

  .pe-panel footer {
    text-align: center;
    font-size: 10px; color: var(--muted);
    padding-top: 12px;
    letter-spacing: 0.1em;
  }

/* ==========================================================================
   深色模式 (prefers-color-scheme: dark)
   ========================================================================== */
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e0d8d0;
    --rust: #e07050;
    --warm-bg: #1a1612;
    --paper: #201c18;
    --muted: #9e9088;
    --rule: #3a322a;
    --accent-bg: #0e0a06;
    --gold: #d8a84a;
  }

  html, body {
    background: var(--warm-bg);
    color: var(--ink);
  }

  /* 段落、表格文字 */
  p { color: #c8c0b8; }
  tbody td { color: var(--ink); }
  tbody tr:nth-child(even) { background: #2a2420; }

  /* 色標 tag：深色背景版 */
  .tag-green { background: #14532d; color: #86efac; }
  .tag-amber { background: #78350f; color: #fcd34d; }
  .tag-red   { background: #7f1d1d; color: #fca5a5; }
  .tag-blue  { background: #1e3a5f; color: #93c5fd; }

  /* 彩色提示框 */
  .box-red    { background: #2d1010; border-left-color: #c0392b; }
  .box-green  { background: #0d2a16; border-left-color: #27ae60; }
  .box-blue   { background: #0d1e30; border-left-color: #2980b9; }
  .box-orange { background: #2a1a06; border-left-color: #e67e22; }
  .box-gray   { background: #1e1e1e; border-left-color: #777; }

  /* KPI 卡片 */
  .kpi { background: #252220; }
  .kpi-label { color: #9e9088; }
  .kpi-value { color: #e0d8d0; }
  .kpi-sub { color: #6e6058; }

  /* table.t 通用表格 */
  table.t tr:nth-child(even) td { background: #252220; }
  table.t td { border-color: #3a322a; color: #c8c0b8; }

  /* insight card */
  .insight-card { background: #252220; border-color: #3a322a; }
  .insight-card .verdict { color: var(--ink); }

  /* lynch */
  .lynch-table td.label { background: #252220; }
  .lynch-callout { background: #0d1e30; border-left-color: #4a90d9; }

  /* col-card */
  .col-card { border-color: #3a322a; background: #252220; }

  /* eq */
  .eq { background: #1a1a1a; border-color: #3a322a; color: #c8c0b8; }

  /* event-table */
  .event-table td { border-color: #3a322a; color: #c8c0b8; }
  .event-table tr:nth-child(even) td { background: #252220; }
  .event-table tr:hover td { background: #2a2010; }

  /* note */
  .note { color: #9e9088; border-top-color: #3a322a; }

  /* ---- money/index.php inline <style> blocks (1st & 2nd) ---- */
  /* .article-wrap (block 1, line ~1323) */
  .article-wrap { color: #c8c0b8; }
  .article-wrap h3 { color: #c8c0b8; }
  .article-wrap p { color: #b0a8a0; }
  .article-table th { background: #252220; color: #c8c0b8; }
  .article-table td { border-bottom-color: #3a322a; color: #c8c0b8; }
  .article-note { background: #252220; border-left-color: #777; color: #9e9088; }

  /* .gdp-art-wrap (block 2, line ~1397) */
  .gdp-art-wrap { color: #c8c0b8; }
  .gdp-art-wrap h3 { color: #c8c0b8; }
  .gdp-art-wrap p { color: #b0a8a0; }
  .gdp-art-note { background: #252220; border-left-color: #777; color: #9e9088; }
  .gdp-chart-title { color: #c8c0b8; }
  .gdp-art-table th { background: #252220; color: #c8c0b8; }
  .gdp-art-table td { border-bottom-color: #3a322a; color: #c8c0b8; }
}

/* ==========================================================================
   深色模式支援 (html[data-theme="dark"])
   ========================================================================== */
html[data-theme="dark"] {
  --ink: #e0d8d0;
  --rust: #e07050;
  --warm-bg: #1a1612;
  --paper: #201c18;
  --muted: #9e9088;
  --rule: #3a322a;
  --accent-bg: #0e0a06;
  --gold: #d8a84a;
}
html[data-theme="dark"] body {
  background: var(--warm-bg);
  color: var(--ink);
}
html[data-theme="dark"] p { color: #c8c0b8; }
html[data-theme="dark"] tbody td { color: var(--ink); }
html[data-theme="dark"] tbody tr:nth-child(even) { background: #2a2420; }
html[data-theme="dark"] .tag-green { background: #14532d; color: #86efac; }
html[data-theme="dark"] .tag-amber { background: #78350f; color: #fcd34d; }
html[data-theme="dark"] .tag-red   { background: #7f1d1d; color: #fca5a5; }
html[data-theme="dark"] .tag-blue  { background: #1e3a5f; color: #93c5fd; }
html[data-theme="dark"] .box-red    { background: #2d1010; border-left-color: #c0392b; }
html[data-theme="dark"] .box-green  { background: #0d2a16; border-left-color: #27ae60; }
html[data-theme="dark"] .box-blue   { background: #0d1e30; border-left-color: #2980b9; }
html[data-theme="dark"] .box-orange { background: #2a1a06; border-left-color: #e67e22; }
html[data-theme="dark"] .box-gray   { background: #1e1e1e; border-left-color: #777; }
html[data-theme="dark"] .kpi { background: #252220; }
html[data-theme="dark"] .kpi-label { color: #9e9088; }
html[data-theme="dark"] .kpi-value { color: #e0d8d0; }
html[data-theme="dark"] .kpi-sub { color: #6e6058; }
html[data-theme="dark"] table.t tr:nth-child(even) td { background: #252220; }
html[data-theme="dark"] table.t td { border-color: #3a322a; color: #c8c0b8; }
html[data-theme="dark"] .insight-card { background: #252220; border-color: #3a322a; }
html[data-theme="dark"] .insight-card .verdict { color: var(--ink); }
html[data-theme="dark"] .lynch-table td.label { background: #252220; }
html[data-theme="dark"] .lynch-callout { background: #0d1e30; border-left-color: #4a90d9; }
html[data-theme="dark"] .col-card { border-color: #3a322a; background: #252220; }
html[data-theme="dark"] .eq { background: #1a1a1a; border-color: #3a322a; color: #c8c0b8; }
html[data-theme="dark"] .event-table td { border-color: #3a322a; color: #c8c0b8; }
html[data-theme="dark"] .event-table tr:nth-child(even) td { background: #252220; }
html[data-theme="dark"] .event-table tr:hover td { background: #2a2010; }
html[data-theme="dark"] .note { color: #9e9088; border-top-color: #3a322a; }
html[data-theme="dark"] .article-wrap { color: #c8c0b8; }
html[data-theme="dark"] .article-wrap h3 { color: #c8c0b8; }
html[data-theme="dark"] .article-wrap p { color: #b0a8a0; }
html[data-theme="dark"] .article-table th { background: #252220; color: #c8c0b8; }
html[data-theme="dark"] .article-table td { border-bottom-color: #3a322a; color: #c8c0b8; }
html[data-theme="dark"] .article-note { background: #252220; border-left-color: #777; color: #9e9088; }
html[data-theme="dark"] .gdp-art-wrap { color: #c8c0b8; }
html[data-theme="dark"] .gdp-art-wrap h3 { color: #c8c0b8; }
html[data-theme="dark"] .gdp-art-wrap p { color: #b0a8a0; }
html[data-theme="dark"] .gdp-art-note { background: #252220; border-left-color: #777; color: #9e9088; }
html[data-theme="dark"] .gdp-chart-title { color: #c8c0b8; }
html[data-theme="dark"] .gdp-art-table th { background: #252220; color: #c8c0b8; }
html[data-theme="dark"] .gdp-art-table td { border-bottom-color: #3a322a; color: #c8c0b8; }
