:root {
  --bg: #0b1020;
  --bg2: #111a2e;
  --panel: #151f36;
  --panel2: #1b2947;
  --line: #26375a;
  --text: #e8eefc;
  --muted: #8fa3c8;
  --up: #ff4d5e;
  --down: #16c784;
  --accent: #4f8cff;
  --accent2: #7b61ff;
  --warn: #ffb648;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0,0,0,.28);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: radial-gradient(1200px 600px at 20% -10%, #1b2b52 0%, transparent 60%), var(--bg);
  color: var(--text);
  font-family: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh; font-size: 14px; line-height: 1.6;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 12px; }

/* 按鈕 */
.btn {
  border: 1px solid transparent; border-radius: 10px; padding: 10px 18px;
  font-size: 14px; font-weight: 600; cursor: pointer; transition: .18s;
  font-family: inherit; color: #fff;
}
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); box-shadow: 0 4px 16px rgba(79,140,255,.3); }
.btn.primary:hover { filter: brightness(1.12); transform: translateY(-1px); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.btn.ghost:hover { border-color: var(--accent); color: var(--text); }
.btn.small { padding: 7px 13px; font-size: 12px; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn.danger { background: #b4233a; }
input {
  width: 100%; background: #0e172b; border: 1px solid var(--line); border-radius: 10px;
  color: var(--text); padding: 11px 14px; font-size: 14px; font-family: inherit; outline: none;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,140,255,.15); }

/* 登入閘道 */
.gate { position: fixed; inset: 0; display: grid; place-items: center; padding: 20px; z-index: 50;
  background: radial-gradient(800px 500px at 50% 0%, #1d305c 0%, var(--bg) 70%); }
.gate-card { width: 100%; max-width: 430px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 22px; padding: 36px 30px 26px; box-shadow: var(--shadow); text-align: center; }
.brand-mark { width: 62px; height: 62px; margin: 0 auto 16px; display: grid; place-items: center;
  border-radius: 18px; font-size: 30px; font-weight: 800; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent2)); box-shadow: 0 8px 24px rgba(79,140,255,.4); }
.brand-mark.small { width: 38px; height: 38px; border-radius: 11px; font-size: 19px; margin: 0; }
.gate-card h1 { margin: 0 0 6px; font-size: 23px; letter-spacing: .5px; }
.gate-sub { margin: 0 0 26px; color: var(--muted); font-size: 13px; }
.gate-body { text-align: left; }
.gate-body label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.gate-body input { letter-spacing: 2px; font-size: 16px; text-align: center; font-weight: 600; }
.gate-body .btn { width: 100%; margin-top: 16px; }
.gate-error { color: var(--up); font-size: 12px; min-height: 20px; padding-top: 6px; }
.gate-hint { text-align: center; color: var(--muted); font-size: 11px; margin: 14px 0 0; }
.gate-admin { display: inline-block; margin-top: 22px; color: var(--accent); font-size: 12px; text-decoration: none; }

/* 版面 */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; background: rgba(11,16,32,.88); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line); }
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; }
.brand-title { font-weight: 700; font-size: 16px; line-height: 1.2; }
.brand-sub { font-size: 9px; color: var(--muted); letter-spacing: 1.5px; }
.session-box { display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line);
  padding: 7px 12px; border-radius: 20px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--down); box-shadow: 0 0 8px var(--down); }
.container { width: 100%; max-width: 1240px; margin: 0 auto; padding: 24px; flex: 1; }
.section { margin-bottom: 30px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.section-head h2 { margin: 0; font-size: 17px; font-weight: 700; }
.search-wrap { display: flex; gap: 8px; width: min(320px, 100%); }
.search-wrap input { padding: 8px 12px; font-size: 13px; }

/* 指數卡 */
.index-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }
.index-card { background: linear-gradient(145deg, var(--panel), var(--bg2)); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 20px; position: relative; overflow: hidden; }
.index-card::after { content: ''; position: absolute; right: -30px; top: -40px; width: 130px; height: 130px;
  border-radius: 50%; background: radial-gradient(circle, rgba(79,140,255,.16), transparent 70%); }
.index-name { color: var(--muted); font-size: 12px; }
.index-value { font-size: 30px; font-weight: 800; letter-spacing: -.5px; font-variant-numeric: tabular-nums; margin: 4px 0; }
.index-change { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.index-meta { margin-top: 12px; font-size: 11px; color: var(--muted); display: flex; justify-content: space-between; }
.up { color: var(--up) !important; }
.down { color: var(--down) !important; }
.flat { color: var(--muted) !important; }
.tag { font-size: 10px; padding: 2px 7px; border-radius: 6px; background: var(--panel2); color: var(--muted); }

/* 自選股 */
.watch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.watch-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px;
  cursor: pointer; transition: .18s; position: relative; }
.watch-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.watch-card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(79,140,255,.2) inset; }
.watch-code { font-weight: 700; font-size: 15px; }
.watch-name { color: var(--muted); font-size: 11px; margin-bottom: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.watch-price { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.watch-change { font-size: 12px; font-weight: 600; }

/* 面板 */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.chart-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; flex-wrap: wrap; gap: 8px; }
.chart-legend { display: flex; gap: 14px; font-size: 11px; color: var(--muted); }
.chart-legend span { display: flex; align-items: center; gap: 5px; }
.legend { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }
.legend.up { background: var(--accent); } .legend.ma5 { background: var(--warn); } .legend.ma20 { background: var(--accent2); }
.legend.support { background: var(--down); } .legend.resist { background: var(--up); }
.level-toggle { display: flex; align-items: center; gap: 5px; cursor: pointer; user-select: none; }
.level-toggle input { width: auto; margin: 0; accent-color: var(--accent); }
canvas { width: 100%; display: block; }

/* 支撐壓力面板 */
.level-box { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.level-col { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.level-col.support { border-left: 3px solid var(--down); }
.level-col.resist { border-left: 3px solid var(--up); }
.level-col h4 { margin: 0 0 10px; font-size: 12px; font-weight: 600; }
.level-col.support h4 { color: var(--down); }
.level-col.resist h4 { color: var(--up); }
.level-row { padding: 7px 0; border-top: 1px dashed var(--line); }
.level-row:first-of-type { border-top: 0; }
.level-line { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.level-price { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.level-src { font-size: 10px; color: var(--muted); text-align: right; }
.strength-bar { height: 3px; background: var(--panel2); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.strength-fill { height: 100%; border-radius: 3px; }
.level-empty { font-size: 11px; color: var(--muted); padding: 8px 0; }
.tabs { display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 4px; }
.tab { border: 0; background: transparent; color: var(--muted); padding: 7px 14px; border-radius: 7px;
  font-size: 12px; cursor: pointer; font-family: inherit; }
.tab.active { background: var(--panel2); color: var(--text); font-weight: 600; }

/* 技術指標 */
.tech-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.tech-item { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.tech-label { font-size: 11px; color: var(--muted); }
.tech-value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 4px; }
.tech-desc { font-size: 10px; color: var(--muted); margin-top: 2px; }

/* AI 建議 */
.ai-box { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-bottom: 14px; }
.ai-loading { color: var(--muted); text-align: center; padding: 20px; }
.ai-score { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.score-ring { width: 62px; height: 62px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0;
  background: conic-gradient(var(--accent) var(--p, 50%), var(--panel2) 0); position: relative; }
.score-ring::before { content: ''; position: absolute; inset: 6px; border-radius: 50%; background: var(--bg2); }
.score-ring span { position: relative; font-size: 20px; font-weight: 800; }
.ai-score-text h3 { margin: 0 0 4px; font-size: 16px; }
.ai-block { margin-top: 14px; }
.ai-block h4 { margin: 0 0 6px; font-size: 12px; color: var(--accent); }
.ai-block p { margin: 0; color: #cdd9f0; font-size: 13px; }
.signal-list { display: flex; flex-wrap: wrap; gap: 6px; }
.signal { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 4px 9px; font-size: 11px; color: #cdd9f0; }
.disclaimer { font-size: 11px; color: var(--muted); margin: 12px 0 0; }

.footer { border-top: 1px solid var(--line); padding: 16px 24px; display: flex; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; color: var(--muted); font-size: 11px; }
.skeleton { background: linear-gradient(90deg, var(--panel) 25%, var(--panel2) 50%, var(--panel) 75%);
  background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: var(--radius); min-height: 120px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.toast { position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%); z-index: 99;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 11px 20px;
  font-size: 13px; box-shadow: var(--shadow); max-width: 90vw; text-align: center; }

@media (max-width: 640px) {
  .topbar { padding: 10px 14px; }
  .brand-sub { display: none; }
  .brand-title { font-size: 14px; }
  .session-box { font-size: 10px; padding: 6px 9px; }
  .container { padding: 16px 14px; }
  .section-head h2 { font-size: 15px; }
  .index-value { font-size: 25px; }
  .watch-grid { grid-template-columns: repeat(2, 1fr); }
  .watch-price { font-size: 19px; }
  .tabs { width: 100%; justify-content: space-between; }
  .tab { flex: 1; padding: 7px 4px; }
  .panel { padding: 12px; }
  .level-box { grid-template-columns: 1fr; }
  .chart-legend { gap: 9px; }
  .footer { padding: 14px; }
}
