:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #222636;
  --border: #2e3347;
  --accent: #4f8ef7;
  --accent2: #7c5cfc;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #f59e0b;
  --text: #e2e8f0;
  --muted: #8892a4;
  --card-radius: 12px;
  --notice-height: 0px;
}

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

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

button,
input,
select {
  font-family: inherit;
}

#mobile-topbar,
#mobile-nav-backdrop {
  display: none;
}

/* ── Sidebar ── */
#sidebar {
  width: 220px;
  min-width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0;
}

.sidebar-brand {
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-brand h2 {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.4;
}
.sidebar-brand p {
  font-size: 10px;
  color: var(--muted);
  margin-top: 3px;
}

nav { padding: 12px 8px; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  transition: all 0.15s;
  margin-bottom: 4px;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: rgba(79,142,247,0.15); color: var(--accent); }
.nav-icon { font-size: 16px; }

/* ── Main content ── */
#main {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 28px;
  background: var(--bg);
  min-width: 0;
  overscroll-behavior: contain;
}

.page { display: none; }
.page.active { display: block; }

h1 { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.subtitle { font-size: 13px; color: var(--muted); margin-bottom: 24px; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  padding: 20px;
  margin-bottom: 20px;
  min-width: 0;
}
.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 16px;
}

/* ── Metric cards ── */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  padding: 18px 20px;
}
.metric-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}
.metric-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}
.metric-unit {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

/* ── Status badges ── */
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
}
.badge-green { background: rgba(34,197,94,0.15); color: var(--green); }
.badge-yellow { background: rgba(245,158,11,0.15); color: var(--yellow); }
.badge-red { background: rgba(239,68,68,0.15); color: var(--red); }
.badge-blue { background: rgba(79,142,247,0.15); color: var(--accent); }

/* ── Data source status ── */
.source-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.source-item {
  background: var(--surface2);
  border-radius: 8px;
  padding: 14px;
  border: 1px solid var(--border);
}
.source-name { font-size: 12px; font-weight: 600; margin-bottom: 6px; }
.source-detail { font-size: 11px; color: var(--muted); line-height: 1.6; }

/* ── Charts ── */
.chart-wrap {
  position: relative;
  height: 280px;
}
.chart-wrap-tall {
  position: relative;
  height: 340px;
}

.analysis-insights {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}

.analysis-insight {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
}

.heatmap-scroll {
  overflow-x: auto;
  padding-bottom: 4px;
}

.heatmap-table {
  border-collapse: separate;
  border-spacing: 2px;
  min-width: 980px;
  width: 100%;
}

.heatmap-table th,
.heatmap-table td {
  font-size: 10px;
  text-align: center;
  padding: 5px 4px;
  border-radius: 4px;
}

.heatmap-table th {
  color: var(--muted);
  font-weight: 600;
  background: var(--surface2);
}

.heatmap-cell {
  color: #fff;
  min-width: 34px;
}

.factor-table {
  width: 100%;
  border-collapse: collapse;
}

.factor-table th,
.factor-table td {
  border-bottom: 1px solid var(--border);
  padding: 8px 6px;
  font-size: 12px;
  text-align: left;
}

.factor-table th {
  color: var(--muted);
  font-weight: 600;
}

/* ── Controls / Form ── */
.control-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.control-group { display: flex; flex-direction: column; gap: 5px; }
.control-group label { font-size: 11px; color: var(--muted); }
input[type="date"], input[type="number"], select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}
input[type="date"]:focus,
input[type="number"]:focus,
select:focus { border-color: var(--accent); }

/* ── Buttons ── */
.btn {
  padding: 8px 18px;
  border-radius: 7px;
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { opacity: 0.85; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { border-color: var(--accent); }

/* ── Optimizer input panel ── */
.param-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}
.param-item { display: flex; flex-direction: column; gap: 6px; }
.param-item label { font-size: 12px; color: var(--muted); }
.param-item.disabled { opacity: 0.4; pointer-events: none; }
.disabled-note {
  font-size: 11px;
  color: var(--yellow);
  background: rgba(245,158,11,0.08);
  border: 1px solid rgba(245,158,11,0.2);
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 16px;
}

/* ── Schedule chart legend ── */
.legend { display: flex; gap: 16px; margin-bottom: 12px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.legend-dot { width: 12px; height: 12px; border-radius: 3px; }

/* ── Revenue summary ── */
.revenue-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
.rev-card {
  background: var(--surface2);
  border-radius: 8px;
  padding: 16px;
  border: 1px solid var(--border);
  text-align: center;
}
.rev-label { font-size: 11px; color: var(--muted); margin-bottom: 8px; }
.rev-value { font-size: 22px; font-weight: 700; }
.rev-green { color: var(--green); }
.rev-blue { color: var(--accent); }

/* ── Report page ── */
.report-section { margin-bottom: 24px; }
.report-section h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.report-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 11px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
}
.report-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(46,51,71,0.5);
}
.risk-box {
  border-radius: 8px;
  padding: 14px 16px;
  font-size: 13px;
  line-height: 1.6;
}
.risk-low { background: rgba(34,197,94,0.08); border: 1px solid rgba(34,197,94,0.2); }
.risk-mid { background: rgba(245,158,11,0.08); border: 1px solid rgba(245,158,11,0.2); }
.risk-high { background: rgba(239,68,68,0.08); border: 1px solid rgba(239,68,68,0.2); }
.notes-list { list-style: none; }
.notes-list li {
  padding: 8px 0;
  font-size: 12px;
  color: var(--muted);
  border-bottom: 1px solid rgba(46,51,71,0.4);
  padding-left: 16px;
  position: relative;
}
.notes-list li::before { content: "※"; position: absolute; left: 0; }

/* ── Loading ── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--muted);
  font-size: 14px;
  gap: 10px;
}
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-msg {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: 8px;
  padding: 14px;
  color: #fca5a5;
  font-size: 13px;
}

/* ── Forecast pattern analyst ── */
.pattern-panel { padding: 16px 18px; }
.pattern-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.pattern-panel .card-title { margin-bottom: 4px; }
.pattern-panel-sub {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}
.pattern-empty {
  color: var(--muted);
  font-size: 13px;
  padding: 8px 0 2px;
}
.pattern-rec-grid {
  display: grid;
  grid-template-columns: minmax(190px, 1.2fr) repeat(3, minmax(120px, 1fr));
  gap: 10px;
}
.pattern-rec-main,
.pattern-metric {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}
.pattern-rec-label,
.pattern-metric-label {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.pattern-rec-model {
  color: var(--accent);
  font-size: 24px;
  font-weight: 700;
  line-height: 1.05;
}
.pattern-rec-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 8px;
}
.pattern-metric-value {
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
}
.pattern-reasons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.pattern-reason {
  background: rgba(79,142,247,0.10);
  border: 1px solid rgba(79,142,247,0.22);
  border-radius: 999px;
  color: var(--text);
  font-size: 11px;
  padding: 4px 9px;
}

@media (max-width: 900px) {
  .pattern-rec-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 560px) {
  .pattern-panel-head { flex-direction: column; }
  .pattern-rec-grid { grid-template-columns: 1fr; }
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Language switcher ── */
.lang-switcher {
  display: flex;
  gap: 4px;
  padding: 12px 10px;
  border-top: 1px solid var(--border);
  justify-content: center;
}
.lang-btn {
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--muted);
  border-radius: 5px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.lang-btn:hover { border-color: var(--accent); color: var(--text); }
.lang-btn.active { background: rgba(79,142,247,0.15); color: var(--accent); border-color: var(--accent); }

/* ── Compare table wrapper ── */
.compare-table-wrap { overflow-x: auto; }

/* ── Chart wrap extra tall ── */
.chart-wrap-xl { position: relative; height: 420px; }

/* ── Strategy: preset buttons ── */
.preset-btns { display: flex; gap: 6px; }
.btn-preset {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-preset:hover { border-color: var(--accent); color: var(--text); }
.btn-preset.active { background: rgba(79,142,247,0.2); color: var(--accent); border-color: var(--accent); }

/* ── Strategy: sliders ── */
.slider-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  margin-top: 16px;
}
.slider-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.slider-item label {
  font-size: 12px;
  color: var(--muted);
}
.slider-item label span:first-child { margin-right: 4px; }
input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

/* ── Strategy: sensitivity heatmap ── */
.heat-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.heat-table th {
  padding: 6px 10px;
  font-size: 11px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  text-align: center;
}
.heat-label {
  padding: 6px 10px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
  border-bottom: 1px solid rgba(46,51,71,0.4);
}
.heat-cell {
  padding: 6px 8px;
  text-align: center;
  font-size: 11px;
  border-bottom: 1px solid rgba(46,51,71,0.3);
  border-radius: 3px;
  font-weight: 600;
}

/* ── Strategy: arbitrage cards ── */
.arb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}
.arb-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
}
.arb-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.arb-date {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}
.arb-type { font-size: 10px; }
.arb-spread { font-size: 11px; }
.arb-detail {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}

/* ── Backtest: progress bar ── */
.bt-progress-bg {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.bt-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.4s ease;
}

/* ── Backtest: calendar heatmap ── */
.cal-table {
  border-collapse: collapse;
  font-size: 11px;
}
.cal-table th {
  padding: 3px 4px;
  color: var(--muted);
  font-size: 10px;
  text-align: center;
}
.cal-table td {
  padding: 2px 3px;
}
.cal-dot {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  margin: auto;
}
.cal-dot-profit { background: rgba(34,197,94,0.45); }
.cal-dot-loss   { background: rgba(239,68,68,0.45); }
.cal-dot-empty  { background: var(--border); opacity: 0.3; }

/* ── Data center tabs ── */
.data-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}
.data-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  padding: 8px 16px;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}
.data-tab:hover { color: var(--text); }
.data-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* ── Collapsible info panels ── */
.info-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  margin-bottom: 12px;
  overflow: hidden;
}
.info-panel-toggle {
  width: 100%;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  gap: 8px;
  padding: 12px 16px;
  text-align: left;
}
.info-panel-toggle:hover { background: rgba(255,255,255,0.03); }
.info-panel-arrow {
  color: var(--muted);
  font-size: 11px;
  flex-shrink: 0;
  transition: transform 0.25s;
}
.info-panel.open .info-panel-arrow { transform: rotate(90deg); }
.info-panel-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s ease;
}
.info-panel-body-inner {
  border-top: 1px solid var(--border);
  padding: 16px;
}
.info-panel-body-inner h3 {
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  margin: 14px 0 6px;
  text-transform: uppercase;
}
.info-panel-body-inner h3:first-child { margin-top: 0; }
.info-panel-body-inner p,
.info-panel-body-inner li { font-size: 12px; line-height: 1.7; color: var(--text); }
.info-panel-body-inner ul { padding-left: 18px; margin: 4px 0; }
.info-panel-body-inner strong { color: var(--accent2); }
.info-section { margin-bottom: 12px; }
.info-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  margin: 6px 0;
}
.info-table th {
  background: var(--surface2);
  color: var(--muted);
  font-weight: 600;
  padding: 5px 10px;
  text-align: left;
}
.info-table td { border-top: 1px solid var(--border); padding: 5px 10px; }
.info-table tr:hover td { background: rgba(255,255,255,0.02); }
.info-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 8px;
}
@media (max-width: 700px) { .info-grid-2 { grid-template-columns: 1fr; } }
.info-box {
  background: var(--surface2);
  border-radius: 8px;
  padding: 12px;
}
.info-box h4 { color: var(--accent); font-size: 12px; margin-bottom: 6px; }
.info-note {
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.2);
  border-radius: 6px;
  color: var(--yellow);
  font-size: 11px;
  margin-top: 8px;
  padding: 8px 12px;
}

/* ── Modal ── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}
.modal-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--card-radius); width: 460px; max-width: 95vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  font-size: 14px; font-weight: 700;
}
.modal-close {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 16px; line-height: 1; padding: 2px 6px;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.modal-footer {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 12px 18px; border-top: 1px solid var(--border);
}

/* ── Calendar heatmap ── */
.cal-month { margin-bottom: 20px; }
.cal-month-title { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 32px); gap: 3px; }
.cal-dow { text-align: center; font-size: 10px; color: var(--muted); padding-bottom: 4px; }
.cal-cell {
  width: 32px; height: 32px; border-radius: 4px; cursor: default;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; color: rgba(255,255,255,0.7);
  transition: transform 0.1s;
}
.cal-cell:hover { transform: scale(1.2); z-index: 1; position: relative; }
.cal-cell-empty { width: 32px; height: 32px; }
.cal-legend {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--muted); margin-top: 8px;
}
.cal-legend-bar {
  display: flex; gap: 2px;
}
.cal-legend-seg { width: 20px; height: 12px; border-radius: 2px; }

/* ── Output page KPI adjustments ── */
#out-kpi-grid { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { #out-kpi-grid { grid-template-columns: repeat(2, 1fr); } }

/* ── Update notification banner ── */
#update-banner {
  background: #fef3c7;
  border-bottom: 1px solid #f59e0b;
  color: #78350f;
  font-size: 13px;
  padding: 8px 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  z-index: 100;
}
#update-banner.banner-error {
  background: rgba(239,68,68,0.12);
  border-color: #ef4444;
  color: #fca5a5;
}
.banner-btn {
  background: #f59e0b;
  border: none;
  border-radius: 4px;
  color: #fff;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
}
.banner-btn:hover { background: #d97706; }
.banner-close {
  background: none;
  border: none;
  color: #92400e;
  cursor: pointer;
  font-size: 14px;
  margin-left: auto;
  opacity: 0.6;
  padding: 0 4px;
}
.banner-close:hover { opacity: 1; }

/* ===== Japan Market Rules Page ===== */

/* Rules page layout */
.rules-layout {
  display: flex;
  gap: 0;
  min-height: 100%;
}
.rules-toc {
  width: 190px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  margin-right: 24px;
  overflow: hidden;
}
.rules-toc-hd {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--muted);
  text-transform: uppercase;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}
.rules-toc-nav { padding: 8px 0; }
.rtoc-link {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 7px 16px;
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
  border-left: 3px solid transparent;
  line-height: 1.35;
  transition: color .15s, border-color .15s, background .15s;
}
.rtoc-link:hover { color: var(--text); background: rgba(255,255,255,.03); }
.rtoc-link.active { color: var(--accent); border-left-color: var(--accent); font-weight: 600; }
.rtoc-num {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
  width: 14px;
}
.rules-body { flex: 1; min-width: 0; }

/* Chapter sections */
.rs-chapter { margin-bottom: 52px; scroll-margin-top: 8px; }
.rs-h2 {
  font-size: 19px;
  font-weight: 700;
  margin: 0 0 18px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--accent);
  color: var(--text);
}
.rs-h3 {
  font-size: 14px;
  font-weight: 600;
  margin: 18px 0 8px;
  color: var(--text);
}
.rs-text {
  font-size: 13px;
  line-height: 1.75;
  color: var(--muted);
  margin-bottom: 10px;
}

/* KPI row */
.rs-kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.rs-kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  padding: 16px;
  text-align: center;
}
.rs-kpi-val {
  font-size: 21px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.1;
  margin-bottom: 6px;
}
.rs-kpi-lbl { font-size: 11px; color: var(--muted); }

/* Vertical timeline */
.rs-timeline { position: relative; padding-left: 26px; margin: 12px 0; }
.rs-timeline::before {
  content: '';
  position: absolute;
  left: 7px; top: 0; bottom: 0;
  width: 2px;
  background: var(--border);
}
.tl-item { position: relative; margin-bottom: 16px; }
.tl-dot {
  position: absolute;
  left: -22px; top: 4px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
}
.tl-item.tl-key .tl-dot { background: var(--yellow); }
.tl-year { font-size: 12px; font-weight: 700; color: var(--accent); margin-bottom: 2px; }
.tl-item.tl-key .tl-year { color: var(--yellow); }
.tl-desc { font-size: 12px; color: var(--muted); line-height: 1.5; }

/* Institution cards */
.rs-org-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin: 12px 0;
}
.rs-org-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  padding: 18px;
}
.rs-org-name { font-size: 18px; font-weight: 800; color: var(--accent); margin-bottom: 2px; }
.rs-org-fullname { font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.rs-org-link { font-size: 11px; color: var(--accent); text-decoration: none; display: block; margin-bottom: 10px; }
.rs-org-link:hover { text-decoration: underline; }
.rs-org-role { font-size: 12px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.rs-org-desc { font-size: 12px; color: var(--muted); line-height: 1.5; margin-bottom: 10px; }
.rs-org-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.rs-tag {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 9px;
  background: rgba(79,142,247,.12);
  color: var(--accent);
  border: 1px solid rgba(79,142,247,.25);
}

/* Tables */
.rs-table-wrap { overflow-x: auto; margin: 10px 0 0; -webkit-overflow-scrolling: touch; }
.rs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  min-width: 480px;
}
.rs-table th {
  background: rgba(79,142,247,.1);
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}
.rs-table td {
  border: 1px solid var(--border);
  padding: 7px 10px;
  color: var(--muted);
  vertical-align: middle;
}
.rs-table tr:hover td { background: rgba(255,255,255,.02); }

/* Hz badges */
.hz50 { display:inline-block; font-size:10px; font-weight:700; padding:1px 6px; border-radius:4px; background:rgba(59,130,246,.2); color:#60a5fa; }
.hz60 { display:inline-block; font-size:10px; font-weight:700; padding:1px 6px; border-radius:4px; background:rgba(234,179,8,.2);  color:#fbbf24; }

/* Warning/note box */
.rs-warn {
  background: rgba(234,179,8,.08);
  border: 1px solid rgba(234,179,8,.35);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 12px;
  color: #fbbf24;
  margin: 10px 0;
  line-height: 1.5;
}

/* Collapsible */
.rs-coll { margin: 8px 0; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.rs-coll-btn {
  width: 100%;
  text-align: left;
  background: rgba(255,255,255,.02);
  border: none;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.rs-coll-btn:hover { background: rgba(255,255,255,.05); }
.rs-coll-arrow { transition: transform .2s; display: inline-block; }
.rs-coll-btn.open .rs-coll-arrow { transform: rotate(180deg); }
.rs-coll-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height .28s ease;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.65;
}
.rs-coll-body.open { max-height: 400px; padding: 10px 14px 14px; }

/* Trend cards */
.rs-trend-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin: 12px 0;
}
.rs-trend-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--card-radius);
  padding: 20px;
}
.rs-trend-icon { font-size: 26px; margin-bottom: 10px; }
.rs-trend-title { font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.rs-trend-body { font-size: 12px; color: var(--muted); line-height: 1.65; }

/* Source note at top */
.rs-source-note {
  background: rgba(79,142,247,.07);
  border: 1px solid rgba(79,142,247,.2);
  border-radius: 6px;
  padding: 9px 14px;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 28px;
  line-height: 1.5;
}
.rs-source-note::before { content: '📌 '; }

/* Responsive */
@media (max-width: 860px) {
  .rules-layout { flex-direction: column; }
  .rules-toc { width: 100%; position: relative; margin-right: 0; margin-bottom: 16px; }
  .rules-toc-nav { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px; }
  .rtoc-link { border-left: none; border-bottom: 2px solid transparent; padding: 5px 10px; }
  .rtoc-link.active { border-bottom-color: var(--accent); border-left-color: transparent; }
  .rs-kpi-row { grid-template-columns: repeat(2, 1fr); }
  .rs-org-row, .rs-trend-row { grid-template-columns: 1fr; }
}

/* Guide Agent */
.guide-agent {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 1200;
  pointer-events: none;
}
.guide-agent-toggle,
.guide-agent-panel {
  pointer-events: auto;
}
.guide-agent-toggle {
  position: relative;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 1px solid rgba(79,142,247,.55);
  background: linear-gradient(145deg, #4f8ef7, #22c55e);
  color: white;
  cursor: pointer;
  box-shadow: 0 14px 36px rgba(0,0,0,.36);
  display: flex;
  align-items: center;
  justify-content: center;
}
.guide-agent-toggle-icon {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: .02em;
}
.guide-agent-badge {
  position: absolute;
  right: -3px;
  top: -5px;
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  background: var(--yellow);
  color: #111827;
  font-size: 12px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg);
}
.guide-agent-panel {
  position: absolute;
  right: 0;
  bottom: 72px;
  width: min(380px, calc(100vw - 28px));
  max-height: min(640px, calc(100vh - 120px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.guide-agent-panel[hidden] {
  display: none;
}
.guide-agent-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.guide-agent-title {
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
}
.guide-agent-subtitle {
  margin-top: 2px;
  font-size: 11px;
  color: var(--muted);
}
.guide-agent-close {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}
.guide-agent-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: grid;
  gap: 10px;
}
.guide-msg {
  max-width: 92%;
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-line;
}
.guide-msg-agent {
  justify-self: start;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
}
.guide-msg-user {
  justify-self: end;
  background: rgba(79,142,247,.18);
  border: 1px solid rgba(79,142,247,.35);
  color: var(--text);
}
.guide-agent-suggestions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 0 14px 12px;
}
.guide-chip {
  border: 1px solid var(--border);
  background: rgba(255,255,255,.02);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 11px;
  cursor: pointer;
}
.guide-chip:hover {
  color: var(--text);
  border-color: var(--accent);
}
.guide-agent-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  background: rgba(255,255,255,.02);
}
.guide-agent-form input {
  min-width: 0;
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  padding: 9px 10px;
  font-size: 12px;
}
.guide-agent-form button {
  border: none;
  border-radius: 7px;
  background: var(--accent);
  color: white;
  padding: 0 13px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
@media (max-width: 720px) {
  .guide-agent {
    right: 14px;
    bottom: 14px;
  }
  .guide-agent-panel {
    right: -6px;
    bottom: 68px;
    max-height: min(560px, calc(100vh - 96px));
  }
}

/* ── Full-site responsive shell ───────────────────────────────────────── */
:where(button, input, select, a):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (max-width: 900px) {
  html,
  body {
    width: 100%;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
  }

  body {
    display: block;
  }

  #update-banner {
    z-index: 1600 !important;
    max-height: 35dvh;
    padding: 8px 12px !important;
    gap: 8px !important;
    flex-wrap: wrap;
    line-height: 1.4;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  #update-banner .banner-btn,
  #update-banner button {
    min-height: 36px;
  }

  #sidebar {
    position: fixed;
    z-index: 1400;
    top: var(--notice-height);
    bottom: 0;
    left: 0;
    width: min(84vw, 320px);
    min-width: 0;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: 18px 0 48px rgba(0, 0, 0, 0.45);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-bottom: env(safe-area-inset-bottom);
  }

  body.mobile-nav-open #sidebar {
    transform: translateX(0);
  }

  #sidebar nav {
    flex: none;
    padding-bottom: 12px;
  }

  .sidebar-brand {
    padding: 16px 18px 14px;
  }

  .sidebar-brand h2 br {
    display: none;
  }

  .nav-item {
    min-height: 46px;
    margin-bottom: 3px;
    padding: 11px 12px;
    font-size: 14px;
  }

  .nav-icon {
    width: 24px;
    text-align: center;
  }

  #mobile-nav-backdrop {
    display: block;
    position: fixed;
    z-index: 1350;
    inset: var(--notice-height) 0 0 0;
    width: 100%;
    height: auto;
    border: 0;
    background: rgba(3, 7, 18, 0.66);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
  }

  body.mobile-nav-open #mobile-nav-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  body.mobile-nav-open #main {
    overflow: hidden;
  }

  #main {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    padding: calc(var(--notice-height) + 64px) 0 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  #mobile-topbar {
    display: flex;
    position: fixed;
    z-index: 1100;
    top: var(--notice-height);
    right: 0;
    left: 0;
    min-height: 58px;
    align-items: center;
    gap: 12px;
    padding: 8px max(14px, env(safe-area-inset-right)) 8px max(14px, env(safe-area-inset-left));
    border-bottom: 1px solid var(--border);
    background: rgba(26, 29, 39, 0.96);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.24);
    backdrop-filter: blur(14px);
  }

  #mobile-menu-button {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface2);
    color: var(--text);
    cursor: pointer;
    font-size: 22px;
    line-height: 1;
  }

  .mobile-topbar-copy {
    display: flex;
    min-width: 0;
    flex: 1;
    flex-direction: column;
    gap: 2px;
  }

  .mobile-topbar-copy strong {
    color: var(--accent);
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  #mobile-page-title {
    overflow: hidden;
    color: var(--text);
    font-size: 15px;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #mobile-access-dot {
    width: 9px;
    height: 9px;
    flex: 0 0 9px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.12);
  }

  #main > .page {
    width: 100%;
    min-width: 0;
    padding: 20px 20px calc(96px + env(safe-area-inset-bottom));
  }

  h1 {
    font-size: 21px;
    line-height: 1.3;
  }

  .subtitle {
    margin-bottom: 18px;
    line-height: 1.55;
  }

  .card {
    max-width: 100%;
    padding: 17px;
    overflow-wrap: anywhere;
  }

  .metrics-grid,
  #out-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .metric-card {
    min-width: 0;
    padding: 15px;
  }

  .metric-value {
    font-size: clamp(20px, 6.4vw, 26px);
    overflow-wrap: anywhere;
  }

  .source-grid,
  .param-grid,
  .slider-grid,
  .arb-grid,
  .revenue-grid {
    grid-template-columns: 1fr;
  }

  .control-row,
  .card > div[style*="align-items:flex-end"] {
    align-items: stretch !important;
  }

  .control-group {
    width: 100%;
    min-width: 0;
  }

  .control-group :where(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), select),
  #out-station-select {
    width: 100%;
    min-width: 0 !important;
    min-height: 44px;
    padding: 9px 10px !important;
    font-size: 16px !important;
  }

  input[type="checkbox"],
  input[type="radio"] {
    width: 18px;
    height: 18px;
  }

  input[type="range"] {
    min-height: 44px;
  }

  .btn,
  .btn-preset,
  .tab-btn,
  .data-tab,
  .lang-btn,
  .info-panel-toggle,
  .rs-coll-btn,
  .guide-chip {
    min-height: 44px;
  }

  #main button,
  #rpt-open-link {
    min-height: 44px;
  }

  #rpt-open-link {
    display: inline-flex;
    align-items: center;
    padding: 6px 4px;
  }

  .ov-region-label,
  #f3-region-checkboxes label,
  #page-output label[style*="cursor:pointer"] {
    min-height: 44px;
    padding-top: 10px !important;
    padding-bottom: 10px !important;
  }

  .data-tabs-scroll,
  .data-tabs {
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
  }

  .data-tabs-scroll .tab-btn,
  .data-tabs .data-tab {
    flex: 0 0 auto !important;
    min-width: 118px;
    padding: 10px 14px !important;
    scroll-snap-align: start;
    white-space: nowrap;
  }

  .preset-row,
  .strategy-actions,
  .legend {
    flex-wrap: wrap;
  }

  .preset-row > span {
    width: 100%;
    margin-bottom: 2px;
  }

  .preset-row .btn-preset,
  .strategy-actions > button {
    flex: 1 1 110px;
  }

  #btn-forecast3,
  #btn-compare,
  #btn-pattern-refresh,
  #btn-analysis-run,
  #btn-backtest,
  #btn-rpt-generate,
  #btn-out-predict,
  #btn-out-add-station,
  #btn-latest-update-top,
  #btn-latest-status-top,
  #btn-weather-apply,
  #btn-lng-apply {
    min-height: 44px;
  }

  .chart-wrap {
    height: 260px;
  }

  .chart-wrap-tall {
    height: 320px;
  }

  .chart-wrap-xl {
    height: 360px;
  }

  .chart-wrap canvas,
  .chart-wrap-tall canvas,
  .chart-wrap-xl canvas {
    max-width: 100% !important;
  }

  .heatmap-scroll,
  .compare-table-wrap,
  .rs-table-wrap,
  [style*="overflow-x:auto"] {
    max-width: 100%;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
  }

  .report-table,
  .factor-table,
  .info-table,
  .heat-table,
  .cal-table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .report-table th,
  .report-table td,
  .factor-table th,
  .factor-table td,
  .info-table th,
  .info-table td {
    white-space: nowrap;
  }

  .rules-toc {
    position: static;
    margin-bottom: 14px;
  }

  .rules-toc-hd {
    padding-bottom: 8px;
  }

  .rules-toc-nav {
    display: flex;
    flex-wrap: nowrap;
    max-width: 100%;
    gap: 4px;
    padding: 6px 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .rtoc-link {
    min-height: 44px;
    flex: 0 0 auto;
    align-items: center;
    padding: 7px 10px;
    white-space: nowrap;
  }

  .rs-chapter {
    margin-bottom: 38px;
    scroll-margin-top: calc(70px + var(--notice-height));
  }

  .rs-kpi-row {
    gap: 9px;
  }

  .rules-body [style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  #modal-add-station {
    align-items: flex-start !important;
    padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
    overflow-y: auto;
  }

  #modal-add-station > div {
    width: 100% !important;
    max-width: 520px !important;
    max-height: none;
    padding: 20px !important;
  }

  #modal-add-station [style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  #modal-add-station :where(input, select) {
    min-height: 44px;
    font-size: 16px !important;
  }

  #rpt-preview-frame {
    height: min(68dvh, 560px) !important;
  }

  #rpt-history-list {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  #page-settings .card > div > div[style*="display:flex"] {
    flex-wrap: wrap;
    gap: 8px 16px;
  }

  .guide-agent {
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
  }

  .guide-agent-panel {
    right: -4px;
    width: calc(100vw - 20px);
    max-height: calc(100dvh - var(--notice-height) - 96px);
  }
}

@media (max-width: 600px) {
  #main > .page {
    padding: 16px 14px calc(92px + env(safe-area-inset-bottom));
  }

  .card {
    padding: 15px;
    margin-bottom: 14px;
    border-radius: 10px;
  }

  .card > div[style*="align-items:flex-end"],
  .card > div[style*="align-items:center"][style*="flex-wrap:wrap"] {
    flex-direction: column;
    align-items: stretch !important;
  }

  .card > div[style*="align-items:center"][style*="flex-wrap:wrap"] > button,
  #btn-forecast3,
  #btn-compare,
  #btn-pattern-refresh,
  #btn-analysis-run,
  #btn-backtest,
  #btn-rpt-generate,
  #btn-out-predict,
  #btn-out-add-station,
  #btn-latest-update-top,
  #btn-latest-status-top,
  #btn-weather-apply,
  #btn-lng-apply {
    width: 100%;
    margin-top: 0 !important;
  }

  #rpt-range-wrap > div {
    flex-direction: column;
  }

  .metric-label {
    font-size: 10px;
  }

  .rev-value {
    font-size: 20px;
  }

  .rs-kpi-card,
  .rs-org-card,
  .rs-trend-card {
    padding: 14px;
  }

  .rs-h2 {
    font-size: 18px;
  }

  .guide-agent-toggle {
    width: 52px;
    height: 52px;
  }

  .guide-agent-panel {
    bottom: 62px;
  }
}

@media (max-width: 340px) {
  .metrics-grid,
  #out-kpi-grid,
  .rs-kpi-row {
    grid-template-columns: 1fr;
  }
}

@media (hover: none) and (pointer: coarse) {
  .nav-item,
  .lang-btn,
  .data-tab,
  .tab-btn,
  .btn,
  .btn-preset,
  .guide-chip,
  .banner-btn,
  .banner-close {
    min-height: 44px;
  }

  .nav-item:hover,
  .info-panel-toggle:hover,
  .rs-coll-btn:hover {
    background: inherit;
  }
}

@media (prefers-reduced-motion: reduce) {
  #sidebar,
  #mobile-nav-backdrop {
    transition: none;
  }
}

/* ── Installable mobile app shell (2026-08-19) ────────────────────────── */
#mobile-bottom-nav {
  display: none;
}

#mobile-topbar svg,
#mobile-bottom-nav svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#mobile-bottom-nav .mobile-tab:first-child svg {
  fill: currentColor;
  stroke: none;
}

.source-icon {
  display: inline-grid;
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  margin-right: 8px;
  place-items: center;
  color: var(--muted);
}

.source-icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.android-download-link {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  margin-top: 16px;
  text-decoration: none;
}

@media (max-width: 600px) {
  .android-download-link {
    width: 100%;
  }
}

@media (max-width: 900px) {
  :root {
    --mobile-nav-height: 70px;
  }

  #mobile-topbar {
    min-height: 64px;
    gap: 10px;
    padding: 8px max(14px, env(safe-area-inset-right)) 8px max(14px, env(safe-area-inset-left));
    background: rgba(11, 16, 27, 0.97);
    box-shadow: none;
  }

  #mobile-menu-button {
    border: 0;
    background: transparent;
  }

  #mobile-menu-button svg {
    width: 28px;
    height: 28px;
  }

  .mobile-brand-mark {
    display: grid;
    width: 28px;
    height: 36px;
    flex: 0 0 28px;
    place-items: center;
    color: var(--accent);
  }

  .mobile-brand-mark svg {
    width: 27px;
    height: 31px;
    fill: currentColor;
    stroke: none;
  }

  .mobile-topbar-copy strong {
    overflow: hidden;
    color: var(--text);
    font-size: 14px;
    letter-spacing: 0;
    text-overflow: ellipsis;
    text-transform: none;
    white-space: nowrap;
  }

  #mobile-page-title {
    color: var(--muted);
    font-size: 10px;
    font-weight: 600;
  }

  #mobile-language-button {
    display: flex;
    min-width: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
  }

  #mobile-language-button svg {
    width: 20px;
    height: 20px;
  }

  #mobile-access-dot {
    width: 7px;
    height: 7px;
    flex-basis: 7px;
  }

  #mobile-bottom-nav {
    position: fixed;
    z-index: 1250;
    right: 0;
    bottom: 0;
    left: 0;
    display: grid;
    min-height: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom));
    grid-template-columns: repeat(5, minmax(0, 1fr));
    padding: 7px max(6px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(6px, env(safe-area-inset-left));
    border-top: 1px solid rgba(46, 51, 71, 0.94);
    background: rgba(13, 18, 30, 0.97);
    box-shadow: 0 -12px 34px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(18px);
  }

  .mobile-tab {
    position: relative;
    display: flex;
    min-width: 0;
    min-height: 56px;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 3px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 10px;
    font-weight: 700;
  }

  .mobile-tab.active {
    color: var(--accent);
  }

  .mobile-tab.active::before {
    position: absolute;
    width: 28px;
    height: 2px;
    margin-top: -58px;
    border-radius: 999px;
    background: var(--accent);
    content: '';
  }

  .mobile-tab svg {
    width: 23px;
    height: 23px;
  }

  #main > .page {
    padding-bottom: calc(var(--mobile-nav-height) + 34px + env(safe-area-inset-bottom));
  }

  #page-overview > h1 {
    font-size: 28px;
    letter-spacing: -0.02em;
  }

  #page-overview > .card:first-of-type {
    border-color: rgba(245, 158, 11, 0.25);
    background: rgba(245, 158, 11, 0.055);
  }

  #page-overview > .card:first-of-type > div:first-child {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 10px !important;
  }

  #page-overview > .card:first-of-type > div:first-child > div:first-child {
    grid-column: 1 / -1;
  }

  #page-overview #btn-latest-update-top,
  #page-overview #btn-latest-status-top {
    width: auto !important;
    min-height: 48px;
    margin: 0 !important;
    padding: 9px 12px !important;
  }

  #page-overview .metrics-grid {
    gap: 0;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
  }

  #page-overview .metric-card {
    min-height: 116px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    border: 0;
    border-radius: 0;
    background: transparent;
    text-align: center;
  }

  #page-overview .metric-card:nth-child(odd) {
    border-right: 1px solid var(--border);
  }

  #page-overview .metric-card:nth-child(-n + 2) {
    border-bottom: 1px solid var(--border);
  }

  #page-overview .metric-label {
    order: 2;
    margin: 9px 0 0;
    letter-spacing: 0;
    text-transform: none;
  }

  #page-overview .metric-value {
    color: var(--accent);
    font-size: clamp(27px, 9vw, 38px);
  }

  #page-overview .metric-unit {
    order: 3;
    font-size: 10px;
  }

  #page-overview .source-grid {
    gap: 0;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface2);
  }

  #page-overview .source-item {
    min-height: 68px;
    display: flex;
    justify-content: center;
    flex-direction: column;
    border: 0;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    background: transparent;
  }

  #page-overview .source-item:last-child {
    border-bottom: 0;
  }

  #page-overview .source-name {
    display: flex;
    align-items: center;
  }

  #page-overview .source-name .badge {
    margin-left: auto !important;
  }

  .guide-agent {
    bottom: calc(var(--mobile-nav-height) + 10px + env(safe-area-inset-bottom));
  }

  .guide-agent-panel {
    bottom: 64px;
    max-height: calc(100dvh - var(--notice-height) - var(--mobile-nav-height) - 86px);
  }
}

@media (max-width: 600px) {
  #sidebar {
    top: auto;
    right: 0;
    bottom: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom));
    left: 0;
    width: 100%;
    max-height: min(76dvh, 650px);
    border-top: 1px solid var(--border);
    border-right: 0;
    border-radius: 22px 22px 0 0;
    transform: translateY(110%);
    transition: transform 0.22s ease;
    box-shadow: 0 -24px 60px rgba(0, 0, 0, 0.55);
  }

  body.mobile-nav-open #sidebar {
    transform: translateY(0);
  }

  #sidebar::before {
    width: 42px;
    height: 4px;
    flex: 0 0 4px;
    align-self: center;
    margin-top: 9px;
    border-radius: 999px;
    background: var(--border);
    content: '';
  }

  #sidebar nav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    padding: 10px 12px 18px;
  }

  #sidebar .nav-item {
    min-height: 50px;
    margin: 0;
  }

  #mobile-language-button span {
    display: none;
  }

  #mobile-nav-backdrop {
    bottom: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom));
  }
}
