:root {
  --bg: #161616;
  --bg-2: #1c1c1c;
  --fg: #d0d0d0;
  --fg-dim: #9a9a9a;
  --fg-faint: #666666;
  --accent: #e2e2e2;
  /* accents saturated but balanced for dark bg */
  --amber: #e0a94a;
  --red: #e25656;
  --pos: #6db870;
  --muted: #2a2a2a;
  --border: #2a2a2a;
  --border-bright: #3a3a3a;
  /* typography scale */
  --fs-xs: 11px;
  --fs-sm: 12px;
  --fs-base: 14px;
  --fs-md: 15px;
  --fs-lg: 16px;
  --fs-xl: 18px;
}

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

html, body {
  background: var(--bg);
  color: var(--fg);
  font-family: 'JetBrains Mono', 'Roboto Mono', 'Fira Code', 'Consolas', 'Courier New', monospace;
  font-size: var(--fs-base);
  line-height: 1.5;
  min-height: 100vh;
  letter-spacing: 0.02em;
  -webkit-font-smoothing: none;
  font-feature-settings: "liga" 0;
}

body {
  padding: 10px 14px;
  overflow-x: hidden;
}

/* very subtle scanlines — nearly invisible, for texture only */
body::before {
  content: "";
  position: fixed; inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255,255,255,0.008) 0px,
    rgba(255,255,255,0.008) 1px,
    transparent 1px,
    transparent 4px
  );
  pointer-events: none;
  z-index: 100;
}

.wrap {
  max-width: 1100px;
  margin: 0 auto;
}

.header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-bright);
  padding-bottom: 5px;
  margin-bottom: 10px;
  flex-wrap: wrap;
  gap: 8px;
}
.logo {
  font-weight: 700;
  font-size: var(--fs-lg);
  letter-spacing: 0.08em;
}
.logo .blink { animation: blink 1.1s steps(2, end) infinite; }
.logo .dim { color: var(--fg-dim); }
@keyframes blink { 50% { opacity: 0; } }

.status-bar {
  color: var(--fg-dim);
  font-size: var(--fs-sm);
  display: flex; gap: 14px; flex-wrap: wrap;
}
.status-bar span::before { content: "["; color: var(--fg-faint); }
.status-bar span::after  { content: "]"; color: var(--fg-faint); }

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
@media (max-width: 820px) { .grid { grid-template-columns: 1fr; } }

.panel {
  border: 1px solid var(--border-bright);
  background: var(--bg-2);
  position: relative;
}
.panel-head {
  padding: 4px 10px;
  border-bottom: 1px solid var(--border-bright);
  color: var(--accent);
  font-size: var(--fs-sm);
  letter-spacing: 0.12em;
  display: flex; justify-content: space-between; align-items: center;
}
.panel-head .idx { color: var(--fg-dim); }
.panel-body { padding: 8px 10px; }

label.row {
  display: grid;
  grid-template-columns: 130px 1fr;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
}
label.row .k {
  color: var(--fg-dim);
  font-size: var(--fs-sm);
  letter-spacing: 0.05em;
}
label.row .k::before { content: "> "; color: var(--fg-faint); }

input[type="number"], input[type="text"] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-bright);
  color: var(--fg);
  font: inherit;
  padding: 4px 8px;
  outline: none;
  text-align: right;
  caret-color: var(--accent);
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; }

input:focus {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
input.pulse { animation: pulse 0.5s ease-out; }
@keyframes pulse {
  0%   { background: rgba(255,255,255,0.08); }
  100% { background: var(--bg); }
}

.side-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--border-bright);
}
.side-toggle button {
  background: var(--bg);
  border: none;
  padding: 5px;
  color: var(--fg-dim);
  font: inherit;
  cursor: pointer;
  letter-spacing: 0.1em;
  transition: background 0.12s;
}
.side-toggle button:hover { background: #252525; }
.side-toggle button.active.long {
  background: #2e2e2e;
  color: var(--fg);
  box-shadow: inset 0 -2px 0 var(--accent);
}
.side-toggle button.active.short {
  background: #2e2e2e;
  color: var(--fg);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.lev-slider {
  display: grid;
  grid-template-columns: 1fr 60px;
  gap: 8px;
  align-items: center;
}
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  width: 100%;
  height: 18px;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 2px; background: var(--border-bright);
}
input[type="range"]::-moz-range-track {
  height: 2px; background: var(--border-bright);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 10px; height: 16px;
  background: var(--accent); cursor: pointer;
  margin-top: -7px;
  border: none;
}
input[type="range"]::-moz-range-thumb {
  width: 10px; height: 16px;
  background: var(--accent); cursor: pointer; border: none; border-radius: 0;
}

.risk-chips {
  display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px;
}
.chip {
  font: inherit;
  background: var(--bg);
  border: 1px solid var(--border-bright);
  color: var(--fg-dim);
  padding: 2px 8px;
  cursor: pointer;
  font-size: var(--fs-sm);
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.chip:hover { border-color: var(--fg-dim); color: var(--fg); }
.chip.active { background: #2e2e2e; color: var(--fg); border-color: var(--accent); }

/* Output panel */
.out-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  padding: 3px 0;
  border-bottom: 1px dotted var(--border);
  gap: 8px;
}
.out-row:last-child { border-bottom: none; }
.out-row .k {
  color: var(--fg-dim);
  font-size: var(--fs-sm);
  letter-spacing: 0.05em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.out-row .k::before { content: "» "; color: var(--fg-faint); }
.out-row .v {
  font-size: var(--fs-md);
  font-weight: 700;
  text-align: right;
  word-break: break-all;
}
.v.amber { color: var(--amber); }
.v.red { color: var(--red); }
.v.pos { color: var(--pos); }
.v.big { font-size: var(--fs-xl); }
.v small { font-size: var(--fs-sm); color: var(--fg-dim); font-weight: 400; display: block; margin-top: 1px; }

.notice {
  margin-top: 6px;
  padding: 5px 10px;
  border-left: 2px solid var(--amber);
  background: rgba(224,169,74,0.10);
  font-size: var(--fs-sm);
  color: var(--amber);
}
.notice.danger {
  border-color: var(--red);
  background: rgba(226,86,86,0.12);
  color: var(--red);
}
.notice.ok {
  border-color: var(--fg-dim);
  background: rgba(255,255,255,0.02);
  color: var(--fg-dim);
}
.notice::before { content: "! "; opacity: 0.8; }

.bar {
  height: 6px;
  background: var(--bg);
  border: 1px solid var(--border-bright);
  position: relative;
  margin-top: 4px;
  overflow: hidden;
}
.bar .fill {
  position: absolute;
  top: 0; left: 0; bottom: 0;
  background: var(--fg-dim);
  transition: width 0.15s ease-out, background 0.15s;
}
.bar .fill.warn { background: var(--amber); }
.bar .fill.danger { background: var(--red); }

.footer {
  margin-top: 8px;
  text-align: center;
  color: var(--fg-faint);
  font-size: var(--fs-xs);
  letter-spacing: 0.1em;
}

.help {
  cursor: help;
  color: var(--fg-faint);
  font-size: var(--fs-xs);
}
.help:hover { color: var(--fg); }

/* Ascii divider */
.ascii-div {
  color: var(--fg-faint);
  font-size: var(--fs-xs);
  white-space: pre;
  line-height: 1;
  margin: 3px 0;
  user-select: none;
}

/* Inline hints beneath inputs */
.hint {
  font-size: var(--fs-xs);
  color: var(--fg-faint);
  margin-left: 138px;
  margin-top: -4px;
}
.hint-info {
  font-size: var(--fs-sm);
  color: var(--fg-dim);
  margin-left: 138px;
  margin-top: -2px;
}
/* R:R is a key metric — bolder + threshold color */
.hint-info.rr {
  font-weight: 700;
  letter-spacing: 0.05em;
}
.hint-info.rr.red   { color: var(--red); }
.hint-info.rr.amber { color: var(--amber); }
.hint-info.rr.pos   { color: var(--pos); }

@media (max-width: 520px) {
  body { padding: 10px; font-size: var(--fs-sm); }
  label.row { grid-template-columns: 110px 1fr; margin-bottom: 6px; }
  .out-row { padding: 4px 0; }
  .out-row .v { font-size: var(--fs-base); }
  .out-row .v.big { font-size: var(--fs-md); }
  .hint, .hint-info { margin-left: 118px; }
  .panel-body { padding: 10px 8px; }
  /* iOS Safari auto-zooms when input font-size < 16px on focus. Force 16px on touch viewports. */
  input[type="number"], input[type="text"] { font-size: 16px; padding: 5px 6px; }
}

/* recent entries — terminal-style inline chips below entry input */
.recent-chip {
  color: var(--fg-dim);
  text-decoration: none;
  border-bottom: 1px dotted var(--fg-faint);
  margin-right: 10px;
  cursor: pointer;
  font-size: var(--fs-xs);
}
.recent-chip:hover { color: var(--fg); border-bottom-color: var(--fg-dim); }
.recent-chip.recent-clear {
  border-bottom: none;
  opacity: 0.5;
  margin-left: 4px;
}
.recent-chip.recent-clear:hover { opacity: 1; }
