:root {
  color-scheme: light;
  --ink: #1c1b19;
  --muted: #6f6a62;
  --paper: #f3f0e8;
  --card: #fffcf8;
  --line: #e3ddd2;
  --soft: #f7f4ee;
  --bad: #8d3b32;
  --gap: 12px;
}
* { box-sizing: border-box; }
html, body { max-width: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Noto Sans CJK SC", "Noto Sans SC", sans-serif;
  color: var(--ink);
  background: var(--paper);
  line-height: 1.45;
}
.skip { position: absolute; left: 12px; top: -40px; background: #fff; padding: 8px; }
.skip:focus { top: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.shell { width: min(1040px, 100%); margin: 0 auto; padding: 12px 16px 32px; min-width: 0; }
.top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: var(--gap); padding: 8px 0 4px; min-width: 0; }
h1 { font-size: clamp(1.25rem, 5vw, 1.45rem); line-height: 1.15; margin: 0; font-weight: 650; letter-spacing: -0.02em; }
.kicker, .hint, .fine, small, legend, .result-kicker { color: var(--muted); }
.kicker { margin: 0 0 4px; font-size: 0.78rem; }
button, input, .choice { font: inherit; max-width: 100%; touch-action: manipulation; }
button {
  min-height: 44px;
  min-width: 44px;
  border: 0;
  border-radius: 10px;
  padding: 10px 16px;
  background: var(--ink);
  color: var(--card);
  font-weight: 650;
  white-space: nowrap;
}
button.text { background: transparent; color: var(--ink); min-height: 44px; padding: 8px 12px; }
button:disabled { opacity: 0.4; }
.login-card, .panel, #calc-form, .balances {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
}
.login-card { width: min(400px, calc(100% - 32px)); margin: 8vh auto 0; padding: 28px 22px 24px; }
.login-card form { display: flex; flex-direction: column; }
.login-card button[type="submit"] { align-self: center; min-width: 148px; margin-top: 18px; }
#calc-form { padding: 16px; min-width: 0; }
form.logout { background: none; border: 0; padding: 0; margin: 0; flex: 0 0 auto; }
.balances {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1.3fr) auto;
  gap: 8px var(--gap);
  align-items: center;
  padding: 14px 16px;
  margin: 12px 0;
  min-width: 0;
}
.balances span, .balances small { display: block; color: var(--muted); font-size: 0.75rem; }
.balances strong, .balances time {
  display: block;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  overflow-wrap: anywhere;
  white-space: normal;
}
.balances .refresh {
  justify-self: end;
  min-width: 72px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}
label, legend { display: block; font-size: 0.78rem; margin: 12px 0 6px; }
fieldset { border: 0; margin: 12px 0 0; padding: 0; min-width: 0; }
legend { padding: 0; }
input[type="text"], input[type="password"], input:not([type]) {
  width: 100%;
  min-height: 44px;
  border: 1px solid #d9d2c6;
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
  font-size: 16px;
}
.combo { position: relative; }
#symbol-list {
  list-style: none;
  margin: 4px 0 0;
  padding: 4px;
  position: absolute;
  z-index: 2;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  max-height: 240px;
  overflow: auto;
}
#symbol-list li { min-height: 44px; display: flex; align-items: center; padding: 0 12px; border-radius: 8px; }
#symbol-list li.active { background: var(--soft); }
.side, .risk { display: grid; gap: 8px; }
.side { grid-template-columns: 1fr 1fr; margin-top: 12px; }
.risk { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.choice {
  position: relative;
  margin: 0;
  min-width: 0;
  min-height: 44px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
}
.choice span { white-space: nowrap; line-height: 1.2; }
.choice input {
  appearance: none;
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
}
.choice:has(input:checked) { background: var(--ink); color: var(--card); border-color: var(--ink); }
.side .choice.long { color: #0b6b38; border-color: #0b6b38; background: #fff; }
.side .choice.short { color: #9f1d1d; border-color: #9f1d1d; background: #fff; }
.side .choice.long:has(input:checked) { background: #0b6b38; color: #fff; border-color: #0b6b38; }
.side .choice.short:has(input:checked) { background: #9f1d1d; color: #fff; border-color: #9f1d1d; }
.choice:focus-within { outline: 2px solid var(--ink); outline-offset: 2px; }
.actions { margin-top: 16px; }
.actions button { width: 100%; }
.badge { margin: 8px 0 0; color: #6a4b16; font-size: 0.85rem; }
.alert { background: #f8ece8; color: var(--bad); border-radius: 10px; padding: 10px 12px; }
.alert ul { margin: 0; padding-left: 1.1rem; }
.split { display: grid; grid-template-columns: 1fr; gap: 8px; }
.advanced { margin-top: 16px; }
.layout { padding-bottom: 8px; }
.result { padding: 18px; }
.result-kicker { margin: 0; font-size: 0.78rem; }
.qty { margin: 2px 0 12px; font-size: 2.6rem; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -0.03em; overflow-wrap: anywhere; }
.result dl, .result dt, .result dd { margin: 0; padding: 0; }
.result dt { float: none; }
.result dl div { display: flex; justify-content: space-between; align-items: baseline; gap: var(--gap); padding: 8px 0; border-top: 1px solid var(--line); }
.result dt { color: var(--muted); }
.result dd { font-variant-numeric: tabular-nums; font-weight: 650; text-align: right; overflow-wrap: anywhere; }
.margin { color: var(--bad); }
.fine, #liq-verdict { margin: 8px 0 0; color: var(--muted); font-size: 0.82rem; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
@media (min-width: 720px) {
  .split { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 960px) {
  .layout.has-result { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
  .result-col { position: sticky; top: 16px; }
}
@media (max-width: 719px) {
  .balances { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .balances .clock, .balances .refresh { grid-column: 1 / -1; }
  .balances .refresh { width: 100%; justify-self: stretch; }
  .actions { position: sticky; bottom: 0; background: var(--card); padding-bottom: 8px; }
}
@media (max-width: 359px) {
  .shell { padding-left: 12px; padding-right: 12px; }
  .login-card { padding: 22px 16px 18px; }
  .risk { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto; }
}
