/* ── 卡片 ── */
.card {
  background: linear-gradient(180deg, color-mix(in srgb, var(--surface) 96%, transparent), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  transition: transform .35s var(--ease-out), box-shadow .35s var(--ease-out), border-color .35s;
}
.card-hover:hover { transform: translateY(-4px); border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); box-shadow: var(--shadow), var(--glow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.card-head h2, .card-head h3 { display: flex; align-items: center; gap: 8px; }
a.card { color: inherit; display: block; }
a.card:hover { text-decoration: none; }

/* ── 文字 ── */
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.num { font-variant-numeric: tabular-nums; font-family: var(--font); }
.big-num { font-size: 1.6rem; font-weight: 700; letter-spacing: .01em; font-variant-numeric: tabular-nums; }
.c-red { color: var(--red); }
.c-green { color: var(--green); }
.c-flat { color: var(--flat); }

/* ── 按鈕 ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text);
  cursor: pointer; font-weight: 500; white-space: nowrap;
  transition: transform .15s var(--ease-spring), background .2s, border-color .2s, box-shadow .2s;
}
.btn:hover { border-color: var(--accent); box-shadow: var(--glow); text-decoration: none; }
.btn:active, .icon-btn:active, .seg button:active, .chip:active { transform: scale(.94); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.btn-ghost { background: transparent; }
.btn-danger:hover { border-color: var(--red); box-shadow: 0 0 0 1px color-mix(in srgb, var(--red) 40%, transparent); }
.btn-sm { padding: 5px 10px; font-size: .85rem; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; display: inline-grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--border); cursor: pointer; font-size: 1.05rem;
  transition: transform .15s var(--ease-spring), border-color .2s;
}
.icon-btn:hover { border-color: var(--accent); }
.star { background: none; border: 0; cursor: pointer; font-size: 1.15rem; line-height: 1; padding: 4px; filter: grayscale(1) opacity(.45); transition: transform .2s var(--ease-spring), filter .2s; }
.star[aria-pressed="true"] { filter: none; }
.star:hover { transform: scale(1.2); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── 分段切換（Tabs） ── */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px; }
.seg button {
  border: 0; background: transparent; color: var(--text-2); padding: 5px 12px; border-radius: 8px; cursor: pointer; font-size: .88rem;
  transition: background .2s, color .2s, transform .15s var(--ease-spring);
}
.seg button[aria-selected="true"] { background: var(--surface-3); color: var(--text); box-shadow: inset 0 0 0 1px var(--border-strong); font-weight: 600; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2); font-size: .82rem; cursor: pointer;
  transition: transform .15s var(--ease-spring), border-color .2s, color .2s;
}
.chip[aria-pressed="true"] { color: var(--text); border-color: currentColor; }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
a.chip:hover { text-decoration: none; border-color: var(--accent); }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 99px; font-size: .74rem; font-weight: 600; border: 1px solid var(--border); color: var(--text-2); background: var(--surface-2); white-space: nowrap; }
.badge-warn { color: var(--lv-greed); border-color: color-mix(in srgb, var(--lv-greed) 50%, transparent); }
.badge-bull { color: var(--lv-xgreed); border-color: color-mix(in srgb, var(--lv-xgreed) 45%, transparent); }
.badge-bear { color: var(--lv-xfear); border-color: color-mix(in srgb, var(--lv-xfear) 45%, transparent); }
.badge-ok { color: var(--green); border-color: color-mix(in srgb, var(--green) 45%, transparent); }
.badge-bad { color: var(--red); border-color: color-mix(in srgb, var(--red) 45%, transparent); }
.badge-new { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ── 表單 ── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: .85rem; color: var(--text-2); font-weight: 500; }
.input, .select, .textarea {
  width: 100%; padding: 9px 12px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  transition: border-color .2s, box-shadow .2s;
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--glow); }
.textarea { min-height: 120px; resize: vertical; }
.field-error { color: var(--red); font-size: .8rem; min-height: 1em; }
.radio-row { display: flex; gap: 8px; flex-wrap: wrap; }
.radio-row label { cursor: pointer; }
.radio-row input { position: absolute; opacity: 0; pointer-events: none; }
.radio-row input:checked + .chip { color: var(--text); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--surface-2)); }
.radio-row input:focus-visible + .chip { outline: 2px solid var(--accent); outline-offset: 2px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.toolbar .input { max-width: 260px; }
.toolbar .select { width: auto; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; color: var(--text-2); font-size: .9rem; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ── 情緒儀表 ── */
.gauge-card { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; position: relative; overflow: hidden; }
.gauge-card::before {
  content: ""; position: absolute; inset: -40% -20% auto; height: 70%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--lv-color, var(--accent)) 22%, transparent), transparent);
  pointer-events: none;
}
.gauge { width: 100%; max-width: 340px; overflow: visible; }
.gauge .seg-arc { fill: none; stroke-width: 16; stroke-linecap: round; }
.gauge .needle { transform-box: view-box; transform-origin: 100px 100px; transform: rotate(-90deg); transition: transform 1.8s var(--ease-spring); }
.gauge .needle line { stroke: var(--text); stroke-width: 3.5; stroke-linecap: round; filter: drop-shadow(0 0 6px color-mix(in srgb, var(--text) 40%, transparent)); }
.gauge .hub { fill: var(--surface-3); stroke: var(--text); stroke-width: 3; }
.gauge text { fill: var(--muted); font-size: 9px; font-family: var(--font); }
.gauge-score { font-size: 3rem; font-weight: 800; line-height: 1; margin-top: -2px; font-variant-numeric: tabular-nums; color: var(--lv-color, var(--text)); text-shadow: 0 0 28px color-mix(in srgb, var(--lv-color, var(--accent)) 45%, transparent); }
.gauge-level { font-size: 1.15rem; font-weight: 700; color: var(--lv-color); }
.gauge-meta { color: var(--muted); font-size: .82rem; }

.part-row { display: grid; grid-template-columns: 96px 1fr 40px; gap: 10px; align-items: center; padding: 6px 0; }
.part-bar { height: 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.part-bar i { display: block; height: 100%; border-radius: inherit; background: var(--lv-color, var(--accent)); width: 0; transition: width 1s var(--ease-out); }

/* ── 指數小卡 ── */
.idx-card { display: flex; flex-direction: column; gap: 4px; }
.idx-card .spark { height: 36px; margin-top: 6px; }

.spark polyline { fill: none; stroke: currentColor; stroke-width: 1.6; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.spark path { fill: currentColor; opacity: .12; }

/* ── 表格（觀察名單） ── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: .8rem; padding: 12px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface-2); }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table tbody tr { cursor: pointer; transition: background .2s; }
.table tbody tr:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .r { text-align: right; }
.table .spark { width: 110px; height: 30px; }
.stock-name { display: flex; flex-direction: column; line-height: 1.25; }
.stock-name small { color: var(--muted); font-size: .76rem; }

@media (max-width: 760px) {
  .table-wrap { border: 0; background: none; overflow: visible; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tbody { display: grid; gap: 10px; }
  .table tbody tr {
    display: grid; grid-template-columns: auto 1fr auto; gap: 2px 10px; align-items: center;
    padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  }
  .table td { padding: 0; border: 0; white-space: normal; }
  .table td[data-col="star"] { grid-row: span 2; }
  .table td[data-col="name"] { grid-column: 2; }
  .table td[data-col="close"] { grid-column: 3; text-align: right; font-weight: 700; }
  .table td[data-col="pct"] { grid-column: 3; text-align: right; }
  .table td[data-col="sector"], .table td[data-col="vol"] { display: none; }
  .table td[data-col="spark"] { grid-column: 2; }
  .table td[data-col="senti"] { grid-column: 3; text-align: right; }
  .table .spark { width: 100%; max-width: 180px; }
}

/* ── 個股頁 ── */
.quote-head { display: flex; flex-wrap: wrap; gap: 16px 28px; align-items: flex-end; justify-content: space-between; }
.quote-price { font-size: 2.3rem; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.chart-box { position: relative; width: 100%; height: 440px; }
.chart-box.sub { height: 190px; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .82rem; color: var(--text-2); min-height: 1.4em; font-variant-numeric: tabular-nums; }
.chart-legend b { font-weight: 600; color: var(--muted); margin-right: 3px; }
.ind-readout { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 12px; }
.ind-readout > div { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; }
.ind-readout strong { display: block; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
@media (max-width: 760px) {
  .chart-box { height: 330px; }
  .chart-box.sub { height: 160px; }
  .quote-price { font-size: 1.9rem; }
}

/* ── 筆記 ── */
.note-card { display: flex; flex-direction: column; gap: 10px; }
.note-body { white-space: pre-wrap; word-break: break-word; color: var(--text-2); }
.note-body.clamp { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.predict-box { border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); padding: 10px 12px; font-size: .9rem; display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; background: var(--surface-2); }
.stat-card .big-num { font-size: 1.9rem; }

/* ── 提示橫幅、Toast、回頂端 ── */
.banner {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: 0 0 18px; padding: 12px 16px; border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--lv-color) 55%, transparent);
  background: linear-gradient(90deg, color-mix(in srgb, var(--lv-color) 18%, var(--surface)), var(--surface));
  animation: banner-pulse 2.6s ease-in-out infinite;
}
.banner .emoji { font-size: 1.5rem; }
@keyframes banner-pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--lv-color) 0%, transparent); }
  50% { box-shadow: 0 0 22px 0 color-mix(in srgb, var(--lv-color) 35%, transparent); }
}
#toast-slot { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 460px); }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: var(--radius);
  background: var(--surface-3); border: 1px solid var(--border-strong); box-shadow: var(--shadow), var(--glow);
  animation: toast-in .45s var(--ease-spring);
}
.toast .spacer { flex: 1; }
@keyframes toast-in { from { opacity: 0; transform: translateY(16px) scale(.96); } }
.to-top {
  position: fixed; right: 20px; bottom: 22px; z-index: 50;
  width: 46px; height: 46px; border-radius: 50%; cursor: pointer; font-size: 1.1rem;
  background: var(--surface-3); border: 1px solid var(--border-strong); color: var(--text);
  box-shadow: var(--shadow); transition: transform .25s var(--ease-spring), opacity .25s, box-shadow .2s;
}
.to-top:hover { box-shadow: var(--shadow), var(--glow); transform: translateY(-3px); }
.to-top[hidden] { display: grid; opacity: 0; pointer-events: none; transform: translateY(14px); }

/* ── 彈出視窗 ── */
dialog.modal {
  width: min(94vw, 560px); max-height: 88vh; padding: 0; border-radius: 18px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); box-shadow: var(--shadow), var(--glow);
}
dialog.modal.wide { width: min(94vw, 720px); }
dialog.modal[open] { animation: modal-in .4s var(--ease-spring); }
dialog.modal::backdrop { background: rgba(3, 6, 15, .6); backdrop-filter: blur(3px); }
@keyframes modal-in { from { opacity: 0; transform: translateY(18px) scale(.95); } }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-body { padding: 18px 20px 22px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding-top: 4px; }

/* ── 載入骨架、空狀態 ── */
.skeleton {
  border-radius: var(--radius); min-height: 120px;
  background: linear-gradient(100deg, var(--surface) 30%, var(--surface-3) 50%, var(--surface) 70%);
  background-size: 300% 100%; animation: shimmer 1.4s linear infinite; border: 1px solid var(--border);
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .emoji { font-size: 2.4rem; display: block; margin-bottom: 8px; }

/* ── 動畫：換頁淡入、捲動淡入 ── */
.page-enter { animation: page-in .5s var(--ease-out); }
@keyframes page-in { from { opacity: 0; transform: translateY(10px); } }
.reveal { opacity: 0; transform: translateY(22px); transition: opacity .7s var(--ease-out), transform .7s var(--ease-out); }
.reveal.is-visible { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  .reveal { opacity: 1; transform: none; }
}
