  :root {
    --bg: #0b0e14; --panel: #131824; --panel2: #1a2030; --line: #252c3d;
    --text: #e6e9ef; --muted: #8a93a6; --accent: #5b8cff;
    --up: #ff4d5e; --down: #19c37d;   /* 預設台灣習慣：紅漲綠跌 */
    --ease: cubic-bezier(.2, .8, .2, 1);
  }
  body.us { --up: #19c37d; --down: #ff4d5e; }
  * { box-sizing: border-box; }
  html { scrollbar-color: var(--line) var(--bg); }
  body { margin: 0; background: var(--bg); color: var(--text); overflow-x: hidden;
    font: 14px/1.5 system-ui, "Microsoft JhengHei", "PingFang TC", sans-serif; }
  body::before { content: ""; position: fixed; inset: -20%; z-index: -1; pointer-events: none;
    background: radial-gradient(40% 40% at 20% 10%, rgba(91,140,255,.12), transparent 70%),
                radial-gradient(35% 35% at 85% 30%, rgba(255,77,94,.07), transparent 70%);
    animation: drift 24s ease-in-out infinite alternate; }
  @keyframes drift { to { transform: translate(4%, 6%) rotate(4deg); } }
  a { color: inherit; text-decoration: none; }
  a:hover { color: var(--accent); }
  .wrap { max-width: 1400px; margin: 0 auto; padding: 16px; }
  header { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
  header h1 { font-size: 20px; margin: 0; letter-spacing: .5px; }
  .badge { font-size: 12px; padding: 2px 9px; border-radius: 99px; background: var(--panel2); color: var(--muted); transition: color .3s; }
  .badge.live { color: var(--text); }
  .badge.live::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
    background: #19c37d; margin-right: 6px; animation: pulse 1.5s infinite; vertical-align: 1px; }
  @keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(25,195,125,.7); } 70% { box-shadow: 0 0 0 7px rgba(25,195,125,0); } 100% { box-shadow: 0 0 0 0 rgba(25,195,125,0); } }
  .spacer { flex: 1; }
  button, input { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line);
    border-radius: 8px; padding: 6px 10px; transition: border-color .2s, background .2s, transform .15s; }
  button { cursor: pointer; }
  button:hover { border-color: var(--accent); }
  button:active { transform: scale(.96); }
  .up { color: var(--up); } .down { color: var(--down); }
  .num { font-variant-numeric: tabular-nums; }
  #refreshBtn.spin svg { animation: rot .8s linear infinite; }
  @keyframes rot { to { transform: rotate(360deg); } }

  /* 市場切換（滑動膠囊） */
  .seg { position: relative; display: inline-flex; background: var(--panel2); border: 1px solid var(--line); border-radius: 99px; padding: 3px; }
  .seg button { position: relative; z-index: 1; border: 0; background: none; border-radius: 99px; padding: 5px 16px; color: var(--muted); }
  .seg button.on { color: #fff; }
  .seg .pill { position: absolute; top: 3px; bottom: 3px; left: 3px; border-radius: 99px; background: var(--accent);
    box-shadow: 0 2px 12px rgba(91,140,255,.45); transition: transform .35s var(--ease), width .35s var(--ease); }

  /* 跑馬燈 */
  .tape { overflow: hidden; border-block: 1px solid var(--line); margin: 0 -16px 16px; padding: 7px 0; background: rgba(19,24,36,.7);
    mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent); }
  .tape .track { display: inline-flex; gap: 34px; white-space: nowrap; animation: marquee 60s linear infinite; padding-left: 34px; }
  .tape:hover .track { animation-play-state: paused; }
  .tape .it { font-size: 13px; cursor: pointer; }
  .tape .it b { margin-right: 6px; font-weight: 600; }
  @keyframes marquee { to { transform: translateX(-50%); } }

  /* 主內容切換市場時淡入 */
  main { transition: opacity .25s, transform .25s var(--ease); }
  main.switching { opacity: 0; transform: translateY(8px); }

  .enter { animation: rise .55s var(--ease) both; animation-delay: calc(var(--i, 0) * 60ms); }
  @keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.98); } }

  /* 指數列 */
  .indices { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; margin-bottom: 18px; }
  .idx { position: relative; overflow: hidden; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; cursor: pointer;
    transition: transform .25s var(--ease), border-color .25s, box-shadow .25s; }
  .idx:hover { transform: translateY(-3px); border-color: var(--accent); box-shadow: 0 8px 24px rgba(0,0,0,.35); }
  .idx .n { color: var(--muted); font-size: 12px; }
  .idx .p { font-size: 19px; font-weight: 650; }
  .idx .c { font-size: 13px; }
  .idx svg { position: absolute; right: 8px; bottom: 8px; opacity: .85; }

  h2 { font-size: 16px; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
  h2 small { color: var(--muted); font-weight: 400; font-size: 12px; }

  /* 今日焦點 */
  .focus { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 12px; margin-bottom: 22px; }
  .card { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px;
    display: flex; flex-direction: column; gap: 8px; transition: transform .3s var(--ease), box-shadow .3s, border-color .3s; }
  .card:hover { transform: translateY(-4px); box-shadow: 0 12px 30px rgba(0,0,0,.4); }
  .card.hot { border-color: color-mix(in srgb, var(--c) 55%, var(--line)); animation: glow 2.4s ease-in-out infinite; }
  .card.hot.enter { animation: rise .55s var(--ease) both, glow 2.4s ease-in-out .6s infinite; animation-delay: calc(var(--i, 0) * 60ms), calc(var(--i, 0) * 60ms + .6s); }
  @keyframes glow { 50% { box-shadow: 0 0 22px -4px color-mix(in srgb, var(--c) 60%, transparent); } }
  .card .q { font-size: 16px; font-weight: 600; }
  .card .q .pct { font-size: 19px; }
  .card .meta { color: var(--muted); font-size: 12px; }
  .card ul { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
  .card li { padding: 8px 10px; background: var(--panel2); border-radius: 8px; transition: background .2s, transform .2s; }
  .card li:hover { background: #222a3d; transform: translateX(3px); }
  .card li .src { color: var(--muted); font-size: 12px; }
  .card li:first-child { border-left: 3px solid var(--accent); }
  .tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px; margin-left: 6px; vertical-align: 2px; color: #fff; }
  .tag.lu { background: var(--up); } .tag.ld { background: var(--down); }
  .nonews { color: var(--muted); font-style: italic; }

  .grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 16px; align-items: start; }
  @media (max-width: 960px) { .grid { grid-template-columns: 1fr; } }
  .col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
  .panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; min-width: 0; }
  .scroll { overflow-x: auto; }

  table { width: 100%; border-collapse: collapse; }
  th, td { padding: 7px 6px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; font-variant-numeric: tabular-nums; }
  th { color: var(--muted); font-weight: 500; font-size: 12px; }
  th:first-child, td:first-child { text-align: left; }
  td .sym { font-weight: 600; }
  td .nm { color: var(--muted); font-size: 12px; max-width: 170px; overflow: hidden; text-overflow: ellipsis; display: block; }
  tr.row { cursor: pointer; transition: background .2s; }
  tr.row:hover td { background: var(--panel2); }
  tbody.enter-rows tr { animation: rise .4s var(--ease) both; animation-delay: calc(var(--i, 0) * 25ms); }
  .flash-up td { animation: fu 1.2s; } .flash-down td { animation: fd 1.2s; }
  @keyframes fu { from { background: color-mix(in srgb, var(--up) 30%, transparent); } }
  @keyframes fd { from { background: color-mix(in srgb, var(--down) 30%, transparent); } }
  .sparkcell { position: relative; }
  .sparkcell svg { display: block; margin-left: auto; transition: transform .25s var(--ease); transform-origin: right center; }
  tr.row:hover .sparkcell svg { transform: scale(1.12); }
  .sparkcell::after { content: "🔍"; position: absolute; left: -2px; top: 50%; transform: translateY(-50%) scale(.6); opacity: 0; font-size: 12px; transition: .2s; }
  tr.row:hover .sparkcell::after { opacity: 1; transform: translateY(-50%) scale(1); }
  .x { color: var(--muted); background: none; border: 0; padding: 0 4px; }
  .x:hover { color: var(--up); transform: rotate(90deg); }
  tr.removing { animation: out .3s forwards; }
  @keyframes out { to { opacity: 0; transform: translateX(30px); } }
  .tabs { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
  .tabs button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
  .tabs .sep { width: 1px; background: var(--line); margin: 0 4px; }
  .addrow { display: flex; gap: 6px; margin-bottom: 10px; }
  .addrow input { flex: 1; min-width: 0; text-transform: uppercase; }
  .addrow input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91,140,255,.2); }

  .news { list-style: none; margin: 0; padding: 0; }
  .news li { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); transition: transform .2s; }
  .news li:hover { transform: translateX(4px); }
  .news img { width: 60px; height: 60px; border-radius: 8px; object-fit: cover; flex: none; background: var(--panel2); }
  .news .src { color: var(--muted); font-size: 12px; }
  .tick { display: inline-block; font-size: 11px; padding: 0 6px; margin-right: 4px; border-radius: 4px; background: var(--panel2); color: var(--accent); }

  /* 骨架載入動畫 */
  .sk { border-radius: 10px; min-height: 90px; background: linear-gradient(90deg, var(--panel) 25%, var(--panel2) 50%, var(--panel) 75%);
    background-size: 200% 100%; animation: shimmer 1.3s infinite; border: 1px solid var(--line); }
  @keyframes shimmer { to { background-position: -200% 0; } }

  /* 放大走勢圖 */
  dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 16px; width: min(980px, 96vw);
    max-height: 92vh; padding: 18px; overflow-y: auto; }
  dialog[open] { animation: pop .35s var(--ease); }
  dialog::backdrop { background: rgba(3,6,12,.7); backdrop-filter: blur(4px); }
  @keyframes pop { from { opacity: 0; transform: translateY(20px) scale(.96); } }
  .dh { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
  .dh .t { font-size: 22px; font-weight: 700; }
  .dh .bigp { font-size: 30px; font-weight: 700; }
  .chartbox { position: relative; margin: 10px 0 6px; user-select: none; touch-action: pan-y; }
  .chartbox svg text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
  .chartbox .grid line { stroke: var(--line); }
  .chartbox .line { fill: none; stroke-width: 2; stroke-linejoin: round; }
  .chartbox .line.draw { transition: stroke-dashoffset 1.1s var(--ease); }
  .chartbox .area { transition: opacity .9s .3s; }
  .chartbox .cross { pointer-events: none; opacity: 0; transition: opacity .15s; }
  .chartbox:hover .cross, .chartbox.touch .cross { opacity: 1; }
  .tip { position: absolute; top: 0; pointer-events: none; background: rgba(10,13,20,.92); border: 1px solid var(--line); border-radius: 8px;
    padding: 6px 9px; font-size: 12px; white-space: nowrap; opacity: 0; transition: opacity .15s; font-variant-numeric: tabular-nums; }
  .chartbox:hover .tip, .chartbox.touch .tip { opacity: 1; }
  .stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; margin: 10px 0 16px; }
  .stats div { background: var(--panel2); border-radius: 8px; padding: 6px 10px; }
  .stats span { display: block; color: var(--muted); font-size: 11px; }
  .loadingbar { height: 2px; background: linear-gradient(90deg, transparent, var(--accent), transparent); background-size: 50% 100%;
    background-repeat: no-repeat; animation: lb 1s linear infinite; visibility: hidden; }
  .loadingbar.on { visibility: visible; }
  @keyframes lb { from { background-position: -50% 0; } to { background-position: 150% 0; } }
  .muted { color: var(--muted); }
  footer { color: var(--muted); font-size: 12px; margin-top: 20px; text-align: center; }

  /* 翻譯 / 摘要 */
  .acts { display: flex; gap: 6px; margin-top: 4px; }
  .acts button { font-size: 11px; padding: 1px 8px; border-radius: 99px; color: var(--muted); background: transparent; }
  .acts button:hover { color: var(--text); }
  .acts button.on { color: var(--accent); border-color: var(--accent); }
  .zh { color: #b9c3d9; font-size: 13px; margin-top: 2px; animation: rise .35s var(--ease) both; }
  .zh::before { content: "譯｜"; color: var(--accent); font-size: 11px; }
  .xbox:empty { display: none; }
  .xbox { margin-top: 8px; padding: 9px 11px; border-radius: 10px; background: rgba(91,140,255,.07); border: 1px solid rgba(91,140,255,.25);
    font-size: 13px; animation: rise .35s var(--ease) both; }
  .xbox ul { margin: 4px 0 0; padding-left: 18px; list-style: disc; display: block; }
  .xbox li { padding: 2px 0 !important; background: none !important; border: 0 !important; display: list-item !important; transform: none !important; }
  .xbox .hd { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); }
  .xbox .hd b { color: var(--accent); font-weight: 600; }
  .xbox .err { color: var(--muted); font-style: italic; }
  .xbox .zhsum { margin-top: 8px; padding-top: 6px; border-top: 1px dashed var(--line); color: #b9c3d9; }
  .dots::after { content: "…"; animation: dots 1s steps(3) infinite; display: inline-block; width: 1.2em; overflow: hidden; vertical-align: bottom; }
  @keyframes dots { from { width: 0; } }
  #trBtn.on { background: var(--accent); border-color: var(--accent); color: #fff; }

  .fab { position: fixed; right: 20px; bottom: 20px; z-index: 50; width: 54px; height: 54px; border-radius: 50%; font-size: 24px; padding: 0;
    background: var(--accent); border: 0; color: #fff; box-shadow: 0 8px 24px rgba(91,140,255,.45); transition: transform .3s var(--ease); }
  .fab:hover { transform: scale(1.08) rotate(-12deg); }
  .drawer { position: fixed; top: 0; right: 0; bottom: 0; z-index: 60; width: min(440px, 100vw); background: var(--panel); border-left: 1px solid var(--line);
    padding: 16px; display: flex; flex-direction: column; gap: 10px; transform: translateX(105%); transition: transform .4s var(--ease);
    box-shadow: -20px 0 50px rgba(0,0,0,.45); overflow-y: auto; }
  .drawer.open { transform: none; }
  .drawer textarea { width: 100%; min-height: 150px; resize: vertical; font: inherit; color: var(--text); background: var(--panel2);
    border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
  .drawer textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91,140,255,.2); }
  .drawer select { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 6px; }
  .drawer .row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
  .drawer .out { white-space: pre-wrap; background: var(--panel2); border-radius: 10px; padding: 10px 12px; min-height: 60px; }
  .drawer .out:empty::before { content: "結果會顯示在這裡"; color: var(--muted); }
  .drawer .primary { background: var(--accent); border-color: var(--accent); color: #fff; }
  .selbub { position: absolute; z-index: 70; padding: 4px 10px; font-size: 12px; border-radius: 99px; background: var(--accent); border: 0; color: #fff;
    box-shadow: 0 4px 14px rgba(0,0,0,.4); animation: pop .2s var(--ease); }
  .selpop { position: absolute; z-index: 70; max-width: 380px; background: var(--panel2); border: 1px solid var(--accent); border-radius: 10px;
    padding: 8px 11px; font-size: 13px; box-shadow: 0 10px 30px rgba(0,0,0,.5); animation: pop .25s var(--ease); }

  @media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

  /* 代號搜尋（全站） */
  .search { position: relative; }
  .search input { width: 240px; padding-left: 30px; background: var(--panel2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238a93a6' stroke-width='2.5'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 10px center; }
  .search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91,140,255,.2); }
  .search .dd { position: absolute; top: calc(100% + 6px); left: 0; z-index: 80; min-width: 320px; background: var(--panel2); border: 1px solid var(--line);
    border-radius: 10px; box-shadow: 0 14px 40px rgba(0,0,0,.5); overflow: hidden; animation: pop .2s var(--ease); }
  .search .dd a { display: flex; gap: 10px; align-items: baseline; padding: 8px 12px; }
  .search .dd a.on, .search .dd a:hover { background: rgba(91,140,255,.15); color: var(--text); }
  .search .dd b { min-width: 80px; }
  .search .dd span { color: var(--muted); font-size: 12px; margin-left: auto; white-space: nowrap; }
  @media (max-width: 640px) { .search input { width: 100%; } .search { flex: 1 1 100%; } }
  a.btn { display: inline-block; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); transition: border-color .2s; }
  a.btn:hover { border-color: var(--accent); color: var(--text); }
  a.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
