/* ============================================================
   Tide clone — styles
   Theme via [data-theme] (light|dark), colour convention via
   [data-color] (tw=red-up | us=green-up), font via [data-font].
   ============================================================ */

:root {
  --c-gold: #E4B125;
  --c-bull: #E03B3B;     /* red  */
  --c-bear: #16A06A;     /* green */
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 6px 24px rgba(0,0,0,.08);
  --font: "PingFang TC","Microsoft JhengHei",system-ui,-apple-system,"Segoe UI",sans-serif;
  --fs: 1;               /* font scale */
}

/* Up/down colour convention */
body[data-color="tw"] { --c-up: var(--c-bull); --c-down: var(--c-bear); }
body[data-color="us"] { --c-up: var(--c-bear); --c-down: var(--c-bull); }

/* Light theme */
body[data-theme="light"] {
  --bg: #F6F6F4; --surface: #FFFFFF; --surface-2: #F1F1EE;
  --line: #E4E4DF; --text: #141519; --text-2: #5C5F66; --text-3: #8E929B;
  --brand: #0F6B4F; --brand-soft: #E6F2EC; --tooltip-bg: #1A1C20;
}
/* Dark theme */
body[data-theme="dark"] {
  --bg: #0B0E0C; --surface: #141815; --surface-2: #1B201C;
  --line: #262C27; --text: #ECEFEA; --text-2: #A7AEA6; --text-3: #6E756C;
  --brand: #3FC79A; --brand-soft: #11231C; --tooltip-bg: #05110C;
  --shadow: 0 6px 28px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font);
  background: var(--bg); color: var(--text);
  font-size: calc(15px * var(--fs));
  -webkit-font-smoothing: antialiased; overflow: hidden;
}
body[data-font="large"] { --fs: 1.18; }
b { font-weight: 700; }
.muted { color: var(--text-2); }
.small { font-size: .8em; }
.up { color: var(--c-up); }
.down { color: var(--c-down); }
.flat { color: var(--text-3); }

/* ---- buttons ---- */
.btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 7px 14px; font-size: .9em; cursor: pointer;
  font-family: inherit; white-space: nowrap; transition: .15s;
}
.btn:hover { border-color: var(--brand); }
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); font-weight: 600; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-block { display: block; width: 100%; margin-top: 10px; padding: 11px; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 4px 10px; font-size: .82em; }
.btn-google { background: #fff; color: #1f1f1f; display: flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid #dadce0; }
.btn-google img { width: 18px; height: 18px; }
.icon-btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 50%;
  width: 36px; height: 36px; cursor: pointer; font-size: 1em; color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; transition: .15s;
}
.icon-btn:hover { border-color: var(--brand); }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px; border-bottom: 1px solid var(--line);
  background: var(--surface); height: 56px;
}
.topbar-left { font-size: .82em; color: var(--text-2); white-space: nowrap; }
.topbar-left .sep { margin: 0 8px; color: var(--text-3); }
.topbar-disclaimer {
  flex: 1; font-size: .68em; color: var(--text-3); line-height: 1.35;
  max-height: 2.7em; overflow: hidden;
}
.topbar-right { display: flex; align-items: center; gap: 8px; }
.search { position: relative; }
.search input {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  border-radius: 999px; padding: 8px 14px 8px 32px; width: 210px; font-family: inherit;
  font-size: .88em; outline: none;
}
.search input:focus { border-color: var(--brand); }
.search-ico { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); font-size: .85em; opacity: .6; }
.search-results {
  position: absolute; top: 42px; left: 0; right: 0; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow);
  max-height: 320px; overflow: auto; z-index: 60;
}
.sr-item { padding: 9px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.sr-item:hover { background: var(--surface-2); }
.sr-item .code { color: var(--text-3); font-variant-numeric: tabular-nums; }

/* ---- layout ---- */
.layout {
  display: grid; grid-template-columns: 132px 1fr 260px; gap: 14px;
  padding: 14px 18px; height: calc(100vh - 56px - 44px);
}
.rail { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.rail-right { overflow: auto; }

/* tide cards */
.tide-card {
  border: 1px solid var(--line); border-left: 4px solid var(--line);
  border-radius: var(--radius-sm); padding: 10px 12px; background: var(--surface);
  cursor: pointer; transition: .15s;
}
.tide-card:hover { transform: translateX(2px); }
.tide-card.dim { opacity: .4; }
.tide-card .tide-label { font-weight: 700; font-size: .95em; }
.tide-card .tide-count { font-size: 1.9em; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tide-card .tide-sub { font-size: .72em; color: var(--text-2); }
.tide-card[data-tide="rising"]   { border-left-color: var(--c-up);   }
.tide-card[data-tide="rising"]   .tide-label, .tide-card[data-tide="rising"]   .tide-count { color: var(--c-up); }
.tide-card[data-tide="rotating"] { border-left-color: var(--c-gold); }
.tide-card[data-tide="rotating"] .tide-label, .tide-card[data-tide="rotating"] .tide-count { color: var(--c-gold); }
.tide-card[data-tide="watching"] { border-left-color: var(--text-3); }
.tide-card[data-tide="watching"] .tide-count { color: var(--text-2); }
.tide-card[data-tide="ebbing"]   { border-left-color: var(--c-down); }
.tide-card[data-tide="ebbing"]   .tide-label, .tide-card[data-tide="ebbing"]   .tide-count { color: var(--c-down); }

/* center */
.center { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.center-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; gap: 2px; }
.seg-btn {
  border: 0; background: transparent; color: var(--text-2); cursor: pointer;
  border-radius: 999px; padding: 6px 14px; font-size: .86em; font-family: inherit; transition: .15s;
}
.seg-btn.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.08); font-weight: 600; }
.seg-sm .seg-btn { padding: 5px 10px; font-size: .8em; }
.market-pill { font-size: .85em; color: var(--text-2); font-weight: 600; }

.view { display: none; flex: 1; min-height: 0; flex-direction: column; }
.view.active { display: flex; }

/* chart */
.chart-hint { font-size: .72em; color: var(--text-3); margin-bottom: 6px; }
.chart-wrap { position: relative; flex: 1; min-height: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
#bubble-canvas { display: block; width: 100%; height: 100%; cursor: grab; }
#bubble-canvas:active { cursor: grabbing; }
.chart-reset { position: absolute; top: 10px; right: 10px; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; width: 32px; height: 32px; cursor: pointer; color: var(--text); }
.tooltip {
  position: absolute; pointer-events: none; z-index: 40; background: var(--tooltip-bg);
  color: #fff; padding: 9px 11px; border-radius: 9px; font-size: .8em; max-width: 240px;
  box-shadow: 0 8px 24px rgba(0,0,0,.35); line-height: 1.5;
}
.tooltip .tt-title { font-weight: 700; margin-bottom: 3px; }
.tooltip .tt-row { display: flex; justify-content: space-between; gap: 14px; }
.tooltip .tt-row span:first-child { opacity: .7; }

/* leaderboard */
.view-leaderboard { overflow: hidden; }
.lb-controls { margin-bottom: 8px; }
#leaderboard { overflow: auto; flex: 1; }
.lb-row {
  display: grid; grid-template-columns: 30px 1fr 96px 96px 70px; align-items: center;
  gap: 8px; padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: .9em;
}
.lb-row.head { position: sticky; top: 0; background: var(--surface); color: var(--text-3); font-size: .78em; border-bottom: 1px solid var(--line); }
.lb-row .rank { color: var(--text-3); font-variant-numeric: tabular-nums; }
.lb-row .name { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.lb-row .grp { font-size: .7em; color: var(--text-3); border: 1px solid var(--line); border-radius: 6px; padding: 1px 5px; }
.lb-row .num { text-align: right; font-variant-numeric: tabular-nums; }
.lb-bar { height: 6px; border-radius: 4px; background: var(--surface-2); position: relative; overflow: hidden; }
.lb-bar i { position: absolute; top: 0; bottom: 0; }
.tide-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* right rail */
.rail-head { display: flex; align-items: center; justify-content: space-between; font-weight: 700; margin-bottom: 6px; }
.watch-item { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: .9em; }
.watch-item .wname { font-weight: 600; }
.watch-item .wcode { color: var(--text-3); font-size: .82em; margin-left: 4px; }
.watch-item .wflow { font-variant-numeric: tabular-nums; font-size: .85em; }
.watch-rm { border: 0; background: transparent; color: var(--text-3); cursor: pointer; font-size: 1.1em; }
.rail-suggest { margin-top: 14px; }
.suggest-title { font-size: .76em; color: var(--text-2); margin-bottom: 8px; }
.suggest-item { display: flex; align-items: center; justify-content: space-between; padding: 7px 0; font-size: .88em; border-bottom: 1px solid var(--line); }
.add-btn { border: 1px solid var(--brand); color: var(--brand); background: transparent; border-radius: 50%; width: 24px; height: 24px; cursor: pointer; }

/* votebar */
.votebar {
  position: fixed; bottom: 0; left: 0; right: 0; height: 44px; display: flex; align-items: center;
  gap: 12px; padding: 0 18px; background: var(--surface); border-top: 1px solid var(--line); font-size: .85em;
}
.vote-btn { border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px; padding: 5px 14px; cursor: pointer; font-family: inherit; color: var(--text); }
.vote-btn.bull:hover { border-color: var(--c-bull); color: var(--c-bull); }
.vote-btn.bear:hover { border-color: var(--c-bear); color: var(--c-bear); }
.vote-note { color: var(--text-3); }
.vote-result { font-weight: 600; }

/* ---- modals ---- */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 100; }
.modal {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%);
  width: min(540px, 92vw); max-height: 86vh; overflow: auto; background: var(--surface);
  border-radius: 18px; padding: 24px; z-index: 110; box-shadow: var(--shadow);
}
.modal-sm { width: min(380px, 92vw); text-align: center; }
.modal-x { position: absolute; top: 12px; right: 14px; border: 0; background: transparent; font-size: 1.5em; color: var(--text-3); cursor: pointer; }
.modal h2 { margin: 6px 0 12px; }
.modal h3 { margin: 0 0 14px; }
.modal p { color: var(--text-2); line-height: 1.6; }
.onboard-emoji { font-size: 2.4em; }
.onboard-dots { display: flex; gap: 6px; justify-content: center; margin: 16px 0; }
.onboard-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.onboard-dots i.on { background: var(--brand); width: 20px; border-radius: 4px; }

.sentiment { background: var(--surface-2); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.sentiment-row { display: flex; justify-content: space-between; margin-bottom: 8px; }
.gauge { height: 8px; border-radius: 999px; background: linear-gradient(90deg,#16A06A,#E4B125,#E03B3B); position: relative; }
.gauge-knob { position: absolute; top: 50%; width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 2px solid var(--text); transform: translate(-50%,-50%); }
.gauge-ends { display: flex; justify-content: space-between; font-size: .75em; color: var(--text-2); margin-top: 6px; }
.brief-block { margin: 12px 0; }
.brief-block h4 { margin: 0 0 6px; font-size: .9em; }
.brief-chip { display: inline-block; background: var(--surface-2); border-radius: 8px; padding: 3px 9px; margin: 0 5px 5px 0; font-size: .85em; }

.record-big { text-align: center; margin: 10px 0; }
.record-big b { font-size: 2.6em; display: block; color: var(--brand); }
.record-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; text-align: center; margin: 14px 0; }
.record-grid b { font-size: 1.6em; display: block; }
.record-grid span, .record-big span { font-size: .78em; color: var(--text-2); }

.set-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); gap: 12px; }
.set-row.col { flex-direction: column; align-items: stretch; }
.set-row > label { font-weight: 600; font-size: .9em; }
.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 7px 0; font-size: .86em; color: var(--text-2); }
.sector-toggles { display: flex; flex-wrap: wrap; gap: 6px; max-height: 150px; overflow: auto; }
.sector-toggles label { font-size: .76em; border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; cursor: pointer; }
.sector-toggles input { margin-right: 4px; }

.field { display: block; margin: 12px 0; }
.field span { display: block; font-size: .82em; color: var(--text-2); margin-bottom: 5px; }
.field input, .field select, .field textarea, #wp-search {
  width: 100%; border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  border-radius: 9px; padding: 9px 11px; font-family: inherit; font-size: .9em;
}
.ok { color: var(--brand); }
.wp-results { max-height: 320px; overflow: auto; margin-top: 10px; }

/* spinner */
.loading { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 12px; color: var(--text-2); background: var(--bg); z-index: 200; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* responsive */
@media (max-width: 900px) {
  .topbar-disclaimer, .topbar-left { display: none; }
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: calc(100vh - 56px - 44px); }
  .rail-left { flex-direction: row; overflow-x: auto; }
  .rail-left .tide-card { min-width: 110px; }
  .rail-right { display: none; }
  .search input { width: 140px; }
}
