/* ==========================================================================
   PolyTail — dark trading console
   Tokens first, then layout, components, and a mobile layer at the bottom.
   ========================================================================== */

:root {
  color-scheme: dark;

  --bg: #070b10;
  --bg-soft: #0b1119;
  --surface: #101924;
  --surface-2: #141f2c;
  --surface-3: #1a2837;
  --border: #203044;
  --border-soft: #182433;
  --border-strong: #2b3f58;

  --text: #e9f0f9;
  --muted: #93a6bd;
  --faint: #62758d;

  --accent: #35dbaa;
  --accent-strong: #23c694;
  --accent-dim: rgba(53, 219, 170, 0.12);
  --danger: #f2675c;
  --danger-dim: rgba(242, 103, 92, 0.12);
  --warn: #f3b84b;
  --warn-dim: rgba(243, 184, 75, 0.12);
  --blue: #5aa7ff;
  --blue-dim: rgba(90, 167, 255, 0.12);

  --up: #35dbaa;
  --down: #f2675c;

  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;

  --radius-sm: 9px;
  --radius: 14px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.025) inset,
    0 10px 28px rgba(0, 0, 0, 0.35);
  --ring: 0 0 0 3px rgba(53, 219, 170, 0.16);

  --topbar-h: 60px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(1000px 560px at 12% -12%, rgba(53, 219, 170, 0.09), transparent 62%),
    radial-gradient(900px 620px at 88% -18%, rgba(90, 167, 255, 0.09), transparent 62%),
    linear-gradient(180deg, #060a0f 0%, #070b10 30%, #070b10 100%);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: rgba(53, 219, 170, 0.25); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

.layout {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 28px 72px;
}

/* ── top bar ─────────────────────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(7, 11, 16, 0.78);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border-bottom: 1px solid var(--border-soft);
}

.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 28px;
  display: flex;
  align-items: center;
  gap: 26px;
  height: var(--topbar-h);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  font-weight: 650;
  letter-spacing: 0.1px;
  white-space: nowrap;
}
.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(145deg, #46e9b8, #179e77);
  display: grid;
  place-items: center;
  color: #03120c;
  font-weight: 800;
  font-size: 14px;
  box-shadow: 0 0 20px rgba(53, 219, 170, 0.28);
}
.brand small {
  color: var(--faint);
  font-weight: 450;
  font-size: 12px;
  margin-left: 2px;
}

.nav { display: flex; gap: 4px; flex: 1; min-width: 0; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 13px;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 500;
  font-size: 13px;
  white-space: nowrap;
  transition: background 0.16s ease, color 0.16s ease;
}
.nav-link svg { width: 16px; height: 16px; flex: none; opacity: 0.85; }
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.active {
  background: var(--surface-2);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--border);
}
.nav-link.active svg { color: var(--accent); opacity: 1; }

.topbar-right { display: flex; align-items: center; gap: 9px; }

/* ── page scaffolding ───────────────────────────────────────────────── */

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding: 30px 0 20px;
}
.page-head h1 {
  margin: 0;
  font-size: 23px;
  font-weight: 650;
  letter-spacing: -0.3px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.page-head p { margin: 5px 0 0; color: var(--muted); font-size: 13px; max-width: 760px; }
.page-head .btn-row { flex: none; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: 1.35fr 1fr; }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.strategy-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.card {
  position: relative;
  background: linear-gradient(180deg, #111a25 0%, #0d141d 100%);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  min-width: 0;
}
.card.tight { padding: 14px 16px; }
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.card-title {
  font-size: 11.5px;
  font-weight: 650;
  color: var(--muted);
  letter-spacing: 0.55px;
  text-transform: uppercase;
}
.card-title.plain {
  text-transform: none;
  font-size: 14.5px;
  font-weight: 650;
  color: var(--text);
  letter-spacing: 0;
}

.hr { height: 1px; background: var(--border-soft); margin: 16px 0; }

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.pos { color: var(--up); }
.neg { color: var(--down); }
.hidden { display: none !important; }

/* ── badges / tags ──────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.15px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge.green { background: var(--accent-dim); color: var(--accent); border-color: rgba(53, 219, 170, 0.25); }
.badge.red { background: var(--danger-dim); color: var(--danger); border-color: rgba(242, 103, 92, 0.25); }
.badge.amber { background: var(--warn-dim); color: var(--warn); border-color: rgba(243, 184, 75, 0.25); }
.badge.blue { background: var(--blue-dim); color: var(--blue); border-color: rgba(90, 167, 255, 0.25); }
.badge.gray { background: var(--surface-2); color: var(--muted); border-color: var(--border); }

.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.dot.pulse { animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.28; } }

.tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 650;
  line-height: 1.5;
}
.tag.enter, .tag.won { background: var(--accent-dim); color: var(--accent); }
.tag.lost { background: var(--danger-dim); color: var(--danger); }
.tag.open { background: var(--blue-dim); color: var(--blue); }
.tag.error { background: var(--warn-dim); color: var(--warn); }
.tag.skip { background: var(--surface-3); color: var(--muted); }

/* ── buttons ────────────────────────────────────────────────────────── */

.btn {
  appearance: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 15px;
  font-size: 13px;
  font-weight: 550;
  font-family: inherit;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}
.btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(180deg, #40e0ae, #23b98d);
  color: #04140e;
  border-color: rgba(53, 219, 170, 0.55);
  box-shadow: 0 6px 16px rgba(53, 219, 170, 0.16);
}
.btn.primary:hover { background: linear-gradient(180deg, #4be9ba, #28c697); }
.btn.danger { background: var(--danger-dim); color: var(--danger); border-color: rgba(242, 103, 92, 0.35); }
.btn.danger:hover { background: rgba(242, 103, 92, 0.2); }
.btn.ghost { background: transparent; border-color: var(--border-soft); color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--surface-2); }
.btn.small { min-height: 30px; padding: 0 11px; font-size: 12px; border-radius: 8px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* segmented control */
.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: 11px;
}
.segmented button {
  appearance: none;
  cursor: pointer;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 550;
  padding: 6px 13px;
  border-radius: 8px;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}
.segmented button:hover { color: var(--text); }
.segmented button.active {
  background: linear-gradient(180deg, #40e0ae, #23b98d);
  color: #04140e;
  box-shadow: 0 4px 12px rgba(53, 219, 170, 0.16);
}

/* ── forms ──────────────────────────────────────────────────────────── */

input[type="text"], input[type="number"], input[type="password"], select, textarea {
  width: 100%;
  min-height: 38px;
  background: #0a1017;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 11px;
  font-size: 13px;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input[type="number"] { font-family: var(--mono); }
input:hover, select:hover { border-color: var(--border-strong); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}
input::placeholder { color: var(--faint); }
select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 52%, calc(100% - 11px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
}

label.field { display: block; }
label.field > span.label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 550;
}
label.field > span.help {
  display: block;
  font-size: 11.5px;
  color: var(--faint);
  margin-top: 6px;
  line-height: 1.45;
}

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px 18px; }
.form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.form-actions { display: flex; gap: 12px; align-items: center; margin-top: 20px; flex-wrap: wrap; }

/* ── stat tiles ─────────────────────────────────────────────────────── */

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.028), transparent 70%),
    var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 13px 15px;
  min-width: 0;
}
.stat .k { font-size: 11.5px; color: var(--muted); letter-spacing: 0.2px; }
.stat .v {
  font-family: var(--mono);
  font-size: 21px;
  font-weight: 600;
  margin-top: 4px;
  letter-spacing: -0.5px;
  line-height: 1.2;
}
.stat .s { font-size: 11.5px; color: var(--faint); margin-top: 3px; }
.stats.compact { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.stats.compact .stat { padding: 9px 11px; border-radius: 10px; }
.stats.compact .stat .k { font-size: 10.5px; }
.stats.compact .stat .v { font-size: 16px; margin-top: 2px; letter-spacing: -0.3px; }
.stats.compact .stat .s { font-size: 10.5px; }

/* ── strategy card ──────────────────────────────────────────────────── */

.strategy-card { display: flex; flex-direction: column; }
.strategy-card .card-head { margin-bottom: 10px; }
.window-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.countdown {
  font-family: var(--mono);
  font-size: 44px;
  font-weight: 650;
  letter-spacing: -2.2px;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}
.countdown small {
  font-size: 12px;
  color: var(--faint);
  letter-spacing: 0;
  font-weight: 450;
  margin-left: 8px;
  vertical-align: 2px;
}
.strategy-card .countdown { font-size: 36px; letter-spacing: -1.8px; }

.progress {
  height: 6px;
  background: var(--surface-3);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 14px;
}
.progress > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #2a7ea6, var(--accent));
  border-radius: 99px;
  transition: width 0.45s linear;
}
.progress.warnbar > i { background: linear-gradient(90deg, #b28a2e, var(--warn)); }

.phase-steps { display: flex; align-items: center; margin-top: 16px; }
.step {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--faint);
  font-size: 11.5px;
  white-space: nowrap;
}
.step .bullet {
  width: 17px;
  height: 17px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 9px;
  flex: none;
  transition: all 0.2s ease;
}
.step.done { color: var(--accent); }
.step.done .bullet { border-color: var(--accent); background: var(--accent-dim); }
.step.current { color: var(--text); }
.step.current .bullet {
  border-color: var(--accent);
  background: var(--accent);
  color: #04140e;
  box-shadow: 0 0 0 4px rgba(53, 219, 170, 0.12);
}
.step-line { width: 26px; height: 1px; background: var(--border); flex: none; }

.side-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.side {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent), var(--surface-2);
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.side.up { border-color: rgba(53, 219, 170, 0.22); }
.side.down { border-color: rgba(242, 103, 92, 0.22); }
.side.up.active { box-shadow: 0 0 0 1px var(--accent) inset, 0 0 28px rgba(53, 219, 170, 0.1); }
.side.down.active { box-shadow: 0 0 0 1px var(--down) inset, 0 0 28px rgba(242, 103, 92, 0.1); }
.side .side-label {
  font-size: 11.5px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.side .side-price {
  font-family: var(--mono);
  font-size: 29px;
  font-weight: 650;
  letter-spacing: -1.1px;
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}
.strategy-card .side-price { font-size: 26px; }
.side .side-bar { height: 4px; border-radius: 99px; background: var(--surface-3); margin-top: 10px; overflow: hidden; }
.side .side-bar > i { display: block; height: 100%; border-radius: 99px; transition: width 0.3s ease; }
.side.up .side-bar > i { background: var(--up); }
.side.down .side-bar > i { background: var(--down); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; font-size: 13px; }
.kv .k { color: var(--muted); min-width: 0; }
.kv .v {
  text-align: right;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  min-width: 0;
  overflow-wrap: anywhere;
}

/* ── tables ─────────────────────────────────────────────────────────── */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 10px;
}
table.data, .card table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12.5px;
}
table.data th, .card table th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.45px;
  text-transform: uppercase;
  padding: 9px 11px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data td, .card table td {
  padding: 9px 11px;
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
}
table.data tbody tr:last-child td, .card table tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover td, .card table tbody tr:hover td { background: rgba(255, 255, 255, 0.02); }
table.data td.num, table.data th.num,
.card table td.num, .card table th.num {
  text-align: right;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

/* ── log ────────────────────────────────────────────────────────────── */

.log { font-family: var(--mono); font-size: 11.5px; max-height: 260px; overflow-y: auto; }
.log-row {
  display: grid;
  grid-template-columns: 62px 52px 1fr;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px dashed var(--border-soft);
}
.log-row .t { color: var(--faint); }
.log-row .l { font-weight: 650; }
.log-row .l.INFO { color: var(--blue); }
.log-row .l.WARNING { color: var(--warn); }
.log-row .l.ERROR { color: var(--danger); }
.log-row .e { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }

/* ── charts ─────────────────────────────────────────────────────────── */

.chart { width: 100%; height: 170px; display: block; }
.chart text { fill: var(--faint); font-size: 10px; font-family: var(--mono); }
.chart .grid-line { stroke: var(--border-soft); stroke-width: 1; }
.chart .zero { stroke: var(--border); stroke-width: 1; stroke-dasharray: 3 3; }

/* ── alerts / notes ─────────────────────────────────────────────────── */

.alert {
  padding: 11px 14px;
  border-radius: 10px;
  font-size: 12.5px;
  border: 1px solid;
  margin-bottom: 14px;
  line-height: 1.55;
}
.alert.error { background: var(--danger-dim); border-color: rgba(242, 103, 92, 0.3); color: #ffb8b1; }
.alert.ok { background: var(--accent-dim); border-color: rgba(53, 219, 170, 0.3); color: #a5f2da; }
.alert.warn { background: var(--warn-dim); border-color: rgba(243, 184, 75, 0.3); color: #f8dfa0; }
.alert.info { background: var(--blue-dim); border-color: rgba(90, 167, 255, 0.25); color: #b4d4ff; }

/* ── login ──────────────────────────────────────────────────────────── */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
  overflow: hidden;
}
.login-wrap::before {
  content: "";
  position: absolute;
  width: 720px;
  height: 720px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(53, 219, 170, 0.12), transparent 62%);
  top: -260px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
}
.login-card {
  width: 100%;
  max-width: 400px;
  padding: 28px;
  position: relative;
  z-index: 1;
  border-radius: var(--radius-lg);
}
.login-card .brand { margin-bottom: 6px; }
.login-card h1 { font-size: 22px; margin: 18px 0 6px; letter-spacing: -0.3px; }
.login-card p { color: var(--muted); font-size: 13px; margin: 0 0 20px; }
.login-card form { margin-top: 4px; }

/* ── markdown report ────────────────────────────────────────────────── */

.md { font-size: 13px; line-height: 1.7; color: var(--text); }
.md h1 { font-size: 18px; margin: 18px 0 10px; }
.md h2 {
  font-size: 15px;
  margin: 20px 0 8px;
  border-bottom: 1px solid var(--border-soft);
  padding-bottom: 7px;
}
.md h3 { font-size: 13.5px; margin: 15px 0 6px; }
.md p { margin: 7px 0; }
.md ul { padding-left: 20px; margin: 8px 0; }
.md li { margin: 4px 0; }
.md table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 12.5px; }
.md th, .md td { border-bottom: 1px solid var(--border-soft); padding: 7px 9px; text-align: left; }
.md th { color: var(--muted); font-weight: 650; }
.md blockquote {
  margin: 12px 0;
  padding: 9px 13px;
  border-left: 3px solid var(--warn);
  background: var(--warn-dim);
  color: #f8dfa0;
  border-radius: 0 8px 8px 0;
}
.md code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--surface-3);
  padding: 1px 5px;
  border-radius: 5px;
}
.md pre {
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 13px;
  overflow-x: auto;
}

/* ── misc ───────────────────────────────────────────────────────────── */

.spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
  display: inline-block;
  vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 60;
  max-width: min(420px, calc(100vw - 44px));
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 12px 16px;
  border-radius: 11px;
  box-shadow: var(--shadow);
  font-size: 13px;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.22s ease, transform 0.22s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { border-color: rgba(242, 103, 92, 0.4); color: #ffb8b1; }
.toast.ok { border-color: rgba(53, 219, 170, 0.4); color: #a5f2da; }

.mode-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.mode-bar select { width: auto; min-width: 190px; }

.empty {
  padding: 22px;
  text-align: center;
  color: var(--muted);
  font-size: 12.5px;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 1240px) {
  .stats { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 1180px) {
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  .strategy-grid { grid-template-columns: 1fr; }
  .stats.compact { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 980px) {
  .layout { padding: 0 18px 72px; }
  .topbar-inner { padding: 0 18px; gap: 14px; }
  .nav-link span { display: none; }
  .nav-link { padding: 8px 10px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .form-grid.cols-3 { grid-template-columns: repeat(2, 1fr); }
  .page-head { padding-top: 22px; }
}

/* phone */
@media (max-width: 760px) {
  body { font-size: 14px; }

  /* The sticky blur creates a containing block for fixed children, so the
     bottom nav only works with a solid topbar on phones. */
  .topbar { backdrop-filter: none; -webkit-backdrop-filter: none; background: #080d13; }
  .topbar-inner { height: 54px; padding: 0 14px; gap: 10px; }
  .brand { font-size: 14px; }
  .brand-mark { width: 27px; height: 27px; border-radius: 8px; font-size: 12px; }
  .brand small { display: none; }
  .topbar-right { margin-left: auto; gap: 6px; }
  .topbar-right .badge { display: none; }
  .topbar-right #clock { font-size: 11px; }

  /* bottom tab bar */
  .nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 2px;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: rgba(8, 13, 19, 0.97);
    border-top: 1px solid var(--border);
    box-shadow: 0 -12px 30px rgba(0, 0, 0, 0.35);
  }
  .nav-link {
    flex-direction: column;
    gap: 3px;
    padding: 7px 4px;
    font-size: 10.5px;
    font-weight: 550;
    border-radius: 9px;
    text-align: center;
  }
  .nav-link span { display: inline; }
  .nav-link svg { width: 18px; height: 18px; }
  .nav-link.active { background: var(--accent-dim); color: var(--accent); box-shadow: none; }

  .layout { padding: 0 14px 96px; }

  .page-head {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 18px 0 14px;
  }
  .page-head h1 { font-size: 20px; }
  .page-head p { font-size: 12.5px; }
  .page-head .btn-row .btn { flex: 0 0 auto; }

  .card { padding: 15px; border-radius: 13px; }
  .card.tight { padding: 12px; }
  .card-head { margin-bottom: 12px; }

  .stats { gap: 9px; }
  .stat { padding: 11px 12px; }
  .stat .v { font-size: 18px; }
  .stats.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
  .stats.compact .stat .v { font-size: 15px; }

  .window-top { gap: 10px; }
  .countdown, .strategy-card .countdown { font-size: 30px; letter-spacing: -1.4px; }
  .phase-steps { margin-top: 13px; }
  .step { font-size: 10.5px; gap: 5px; }
  .step-line { width: 10px; }
  .side-row { gap: 9px; }
  .side { padding: 11px 12px; }
  .side .side-price, .strategy-card .side-price { font-size: 23px; letter-spacing: -0.9px; }

  .kv { font-size: 12.5px; gap: 7px 10px; }

  .form-grid, .form-grid.cols-3 { grid-template-columns: 1fr; }
  .form-actions { flex-direction: column; align-items: stretch; }
  .form-actions .btn { width: 100%; }

  .segmented { width: 100%; display: flex; }
  .segmented button { flex: 1 1 0; padding: 8px 6px; }

  .btn { min-height: 42px; }
  .btn.small { min-height: 34px; }
  input[type="text"], input[type="number"], input[type="password"], select {
    min-height: 42px;
    font-size: 16px; /* prevents iOS zoom-on-focus */
  }

  .table-wrap { margin: 0 -6px; padding: 0 6px; }
  table.data, .card table { font-size: 12px; }
  table.data th, .card table th { font-size: 10px; padding: 8px 9px; }
  table.data td, .card table td { padding: 8px 9px; }

  .md { font-size: 12.5px; }
  .md table { display: block; overflow-x: auto; }

  .toast { left: 14px; right: 14px; bottom: calc(78px + env(safe-area-inset-bottom)); max-width: none; }

  .mode-bar { align-items: center; }
  .mode-bar select { width: auto; flex: 1 1 150px; min-width: 0; }
  .mode-bar .btn { width: auto; flex: 0 0 auto; }
}

@media (max-width: 420px) {
  .stats, .stats.compact { grid-template-columns: 1fr 1fr; }
  .stat .v, .stats.compact .stat .v { font-size: 16px; }
  .countdown, .strategy-card .countdown { font-size: 26px; }
  .side .side-price, .strategy-card .side-price { font-size: 20px; }
  .step .bullet { width: 15px; height: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
