:root {
  --bg: #0f1217;
  --card: #161a21;
  --line: #2a303b;
  --text: #edeae3;
  --muted: #9ca1aa;
  --field: #1c212a;
  --accent: #f2b544;
  --buy: #4c9ee8;
  --buy-ink: #06131f;
  --sell: #ef8a5a;
  --sell-ink: #1e0d05;
  --bad: #f4906f;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
.bar {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
.brand svg { color: var(--accent); }
.nav { display: flex; gap: 4px; margin-right: auto; margin-left: 12px; }
.nav a { display: inline-flex; align-items: center; height: 36px; padding: 0 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 15px; }
.nav a:hover { color: var(--text); background: var(--field); }
.nav a[aria-current="page"] { color: var(--text); background: var(--field); }
.acct { font-size: 14px; color: var(--muted); text-align: right; }
.acct strong { color: var(--text); font-family: var(--mono); font-weight: 500; }
.badge { display: inline-block; margin-left: 8px; padding: 2px 8px; border-radius: 99px; background: #3a2f14; color: var(--accent); font-size: 12px; font-weight: 600; }

main { max-width: 520px; margin: 0 auto; padding: 20px 16px 48px; display: flex; flex-direction: column; gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 20px; display: flex; flex-direction: column; gap: 16px; }

.row { display: flex; gap: 12px; align-items: flex-end; }
.grow { flex: 1; min-width: 0; }
.field { display: flex; flex-direction: column; gap: 6px; }
label { font-size: 13px; color: var(--muted); }
input[type=number], input:not([type]), select {
  width: 100%; height: 48px; padding: 0 14px; border-radius: 10px;
  background: var(--field); border: 1px solid var(--line); color: var(--text);
  font: 500 18px var(--mono);
}
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, #9ca1aa 50%), linear-gradient(135deg, #9ca1aa 50%, transparent 50%); background-position: calc(100% - 20px) 21px, calc(100% - 14px) 21px; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; cursor: pointer; }
input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.rr { width: 96px; }

.quote { display: flex; gap: 14px; font-family: var(--mono); font-size: 15px; padding-bottom: 12px; }
.quote .k { color: var(--muted); font-family: inherit; font-size: 12px; }

fieldset { border: 0; margin: 0; padding: 0; display: flex; }
fieldset input { position: absolute; opacity: 0; pointer-events: none; }
fieldset label {
  flex: 1; display: grid; place-items: center; height: 48px; cursor: pointer;
  background: var(--field); border: 1px solid var(--line); color: var(--text); font-size: 16px; font-weight: 600;
}
fieldset label:first-of-type { border-radius: 10px 0 0 10px; }
fieldset label:last-of-type { border-radius: 0 10px 10px 0; border-left: 0; }
fieldset input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 1px; }
.side label { height: 52px; font-size: 18px; }
#side-buy:checked + label { background: var(--buy); border-color: var(--buy); color: var(--buy-ink); }
#side-sell:checked + label { background: var(--sell); border-color: var(--sell); color: var(--sell-ink); }
.unit label { width: 52px; flex: none; }
.unit input:checked + label { background: #2f3642; border-color: #4a5261; }

.plan { background: #11151b; border: 1px solid var(--line); border-radius: 10px; padding: 16px; min-height: 96px; }
.plan .hint { margin: 0; color: var(--muted); }
.plan .err { margin: 0; color: var(--bad); }
.plan .vol { display: flex; align-items: baseline; gap: 8px; margin-bottom: 12px; }
.plan .vol b { font: 600 34px var(--mono); }
.plan .vol span { color: var(--muted); }
.plan dl { margin: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 16px; }
.plan dt { font-size: 12px; color: var(--muted); }
.plan dd { margin: 2px 0 0; font: 500 16px var(--mono); }
.plan .warn { margin: 12px 0 0; padding: 0; list-style: none; color: var(--accent); font-size: 14px; }

.place {
  height: 58px; border: 0; border-radius: 12px; cursor: pointer;
  font-family: inherit; font-size: 18px; font-weight: 700; background: var(--buy); color: var(--buy-ink);
}
.place.sell { background: var(--sell); color: var(--sell-ink); }
.place:disabled { background: #2a303b; color: #8b909a; cursor: not-allowed; }
.fine { margin: -6px 0 0; font-size: 13px; color: var(--muted); text-align: center; }

.log h2 { margin: 0; font-size: 15px; color: var(--muted); font-weight: 600; }
.log ol { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.log li { font-family: var(--mono); }
.log li.empty { font-family: inherit; color: var(--muted); }
.log .ok { color: var(--text); } .log .fail { color: var(--bad); }

.sim { margin: -6px 0 0; padding: 8px 12px; border-radius: 8px; background: #3a2f14; color: var(--accent); font-size: 14px; }
.sim code { font-family: var(--mono); font-size: 13px; }
select.acct-select { width: auto; height: 36px; padding: 0 30px 0 12px; font: 500 14px -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; background-position: calc(100% - 16px) 15px, calc(100% - 10px) 15px; }

@media (max-width: 640px) {
  .bar { flex-wrap: wrap; row-gap: 8px; padding: 10px 16px; }
  .bar .nav { margin-left: 4px; }
  .acct { width: 100%; text-align: left; font-size: 13px; }
  .acct br { display: none; }
}
.sim a { color: #ffd88a; font-weight: 600; }

/* ---- stop guard ---- */
.guard h2 { margin: 0; font-size: 17px; }
.guard h3 { margin: 4px 0 0; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.guard-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.gstate { display: inline-flex; align-items: center; gap: 6px; height: 28px; white-space: nowrap; flex-shrink: 0; padding: 0 12px; border-radius: 99px; font-size: 13px; font-weight: 700; background: var(--field); border: 1px solid var(--line); }
.gstate::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #8b909a; }
.gstate.on::before { background: #36ad69; }
.gstate.pending::before { background: var(--accent); }
.gstate.error::before { background: #f4906f; }
.guard-rule { margin: -4px 0 0; font-size: 14px; color: var(--muted); line-height: 1.5; }
.guard .note { margin: 0; font-size: 14px; color: var(--accent); }
.guard .err { margin: 0; font-size: 14px; color: #f4a58a; }
.guard-controls { display: flex; flex-direction: column; gap: 12px; }
.guard-controls .field { min-width: 0; }
#gDelayField select { width: 170px; font-size: 15px; font-family: inherit; }
.guard-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.gbtn { height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--field); color: var(--text); font-family: inherit; font-size: 15px; font-weight: 700; cursor: pointer; }
.gbtn.on { background: #36ad69; border-color: #36ad69; color: #06170d; }
.gbtn:disabled { opacity: .6; cursor: wait; }
.gpos, .gevents { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.gpos li { display: flex; justify-content: space-between; gap: 10px; font-family: var(--mono); }
.gpos .lk { color: var(--muted); font-family: inherit; }
.gpos .lk.bad { color: #f4a58a; }
.gevents li { line-height: 1.4; }
.gevents time { color: var(--muted); font-family: var(--mono); font-size: 12px; margin-right: 6px; }
.gevents .k-restore, .gevents .k-set { color: #ffd88a; }
.gevents .k-close, .gevents .k-error { color: #f4a58a; }
.muted { color: var(--muted); }
@media (max-width: 640px) { .guard-controls .row { flex-direction: column; align-items: stretch; } #gDelayField select { width: 100%; } }

[hidden] { display: none !important; }

/* ---- challenge rules + hard mode ---- */
.rules-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.rules h2 { margin: 0; font-size: 17px; }
.rules a { color: var(--accent); }
.meters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.meter { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.meter .mk { font-size: 13px; color: var(--muted); }
.meter .mv { font: 600 16px var(--mono); }
.meter .mv small { font: 400 12px var(--mono); color: var(--muted); }
.gauge { height: 8px; border-radius: 99px; background: #262c36; overflow: hidden; }
.gauge > i { display: block; height: 100%; border-radius: 99px; background: #4c9ee8; }
.gauge.low > i { background: #cf4238; }
.gauge.mid > i { background: var(--accent); }
.gauge.goal > i { background: #36ad69; }
.hard { display: flex; flex-direction: column; gap: 12px; border-top: 1px solid var(--line); padding-top: 14px; }
.hard label { font-size: 13px; color: var(--muted); }
.hard .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.hard select { width: auto; flex: 1; min-width: 180px; font-size: 15px; font-family: inherit; }
.hard .hint { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.5; }
.hard .err { margin: 0; font-size: 14px; color: #f4a58a; }
.gbtn.danger-on { background: #8e2a22; border-color: #8e2a22; color: #fff; }
.hard-day { display: flex; flex-direction: column; gap: 4px; font-size: 15px; }
.hard-day .big { font-size: 17px; font-weight: 700; }
.hard-day .blocked { color: #f4a58a; font-weight: 700; }
.hard-day .ok { color: #7fd4a0; font-weight: 700; }
.linkish { background: none; border: 0; padding: 0; color: var(--muted); font-family: inherit; font-size: 13px; text-decoration: underline; cursor: pointer; align-self: flex-start; }
.phrase { margin: 0; padding: 10px 12px; background: var(--field); border-radius: 8px; font-family: var(--mono); font-size: 13px; user-select: none; -webkit-user-select: none; }
#phraseInput { font-size: 14px; }
.gstate.is-hard::before { background: #cf4238; }
.plan .limit { margin: 12px 0 0; font-size: 14px; color: #ffd88a; }
@media (max-width: 640px) { .meters { grid-template-columns: minmax(0, 1fr); } }
.nav a.logout { margin-left: auto; }
