:root {
  --panel-sunk: rgba(6, 9, 13, 0.72);
  --accent-soft: rgba(99, 214, 255, 0.16);
  --accent-line: rgba(99, 214, 255, 0.5);
  --danger-soft: rgba(255, 122, 82, 0.14);
  --danger-line: rgba(255, 122, 82, 0.5);
  --ok: #6ee7a0;
  --ok-soft: rgba(110, 231, 160, 0.14);
  --ok-line: rgba(110, 231, 160, 0.45);
}

html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; min-height: 100%; overflow-x: hidden; }

body {
  color: var(--text);
  font: 14px/1.5 var(--font-main);
  padding: calc(var(--nav-h) + 1rem) 0 3rem;
}

.container { max-width: 1000px; margin: 0 auto; padding: 1.5rem 1.25rem; }

.card {
  background: var(--panel);
  border: 1px solid var(--edge);
  padding: 1.1rem 1.15rem;
  margin-bottom: 1.1rem;
}
.card h2 {
  margin: 0 0 0.9rem;
  font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--muted); font-weight: 600;
}
.card-head {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline;
  gap: 0.3rem 1rem; margin: 0 0 0.9rem;
}
.card-head h2 { margin: 0; }
.sub-heading {
  margin: 0 0 0.6rem;
  font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--muted); font-weight: 600;
}
.hint { color: var(--muted); font-size: 12px; margin: 0; }
.is-hidden { display: none !important; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

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

.tab-bar {
  display: flex; gap: 0.25rem; flex-wrap: wrap;
  border-bottom: 1px solid var(--edge);
  margin-bottom: 1.1rem;
}
.tab-btn {
  background: none; border: none; border-bottom: 2px solid transparent; margin-bottom: -1px;
  color: var(--muted); font: inherit; font-size: 12px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase;
  padding: 0.55rem 0.9rem; cursor: pointer;
}
.tab-btn:hover { color: var(--text); background: rgba(90, 120, 150, 0.1); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-bar.sub-tab-bar { margin-bottom: 1rem; }
.tab-bar.sub-tab-bar .tab-btn { font-size: 11px; padding: 0.45rem 0.75rem; }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fade-in 0.2s ease; }
@keyframes fade-in { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

label { font-size: 10.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); font-weight: 600; }

input[type="number"], input[type="text"] {
  font: inherit; font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  color: var(--text); background: var(--panel-sunk);
  border: 1px solid var(--edge);
  padding: 0.45rem 0.55rem; width: 100%;
}
input[type="number"]:hover, input[type="text"]:hover { border-color: var(--edge-strong); }
input[type="number"]:focus, input[type="text"]:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 2px var(--accent-soft); }
input:disabled { opacity: 0.35; cursor: not-allowed; }
input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }

button { font: inherit; cursor: pointer; }
.btn {
  color: var(--text); background: rgba(90, 120, 150, 0.16);
  border: 1px solid var(--edge);
  padding: 0.45rem 0.85rem; font-size: 12px; font-weight: 600;
  letter-spacing: 0.04em;
}
.btn:hover:not(:disabled) { background: var(--accent-soft); border-color: var(--accent-line); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: var(--accent-soft); border-color: var(--accent-line); color: #eaf9ff; }
.btn.primary:hover:not(:disabled) { background: rgba(99, 214, 255, 0.28); border-color: var(--accent); }
.btn.ghost { background: none; color: var(--muted); }
.btn.ghost:hover:not(:disabled) { color: var(--text); background: rgba(90, 120, 150, 0.12); border-color: var(--edge-strong); }
.btn.dashed { background: none; border-style: dashed; color: var(--accent); }
.btn.dashed:hover:not(:disabled) { background: var(--accent-soft); border-style: solid; }

.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0.9rem; }
.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field > label { display: flex; align-items: center; }

.dice-panel { display: flex; flex-direction: column; gap: 0.7rem; }
.dice-list { display: flex; flex-direction: column; gap: 0.5rem; }
.dice-row { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.dice-row .dg-count { width: 74px; flex: 0 0 auto; }
.dice-row .dg-sides { width: 84px; flex: 0 0 auto; }
.dg-d { color: var(--muted); font-family: var(--font-mono); font-size: 13px; }
.dg-remove {
  width: 30px; height: 30px; flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: 1px solid var(--edge);
  color: var(--muted); font-size: 15px; line-height: 1;
}
.dg-remove:hover:not(:disabled) { color: var(--danger); border-color: var(--danger-line); background: var(--danger-soft); }
.dg-remove:disabled { opacity: 0.3; cursor: not-allowed; }

.crit-row { padding-top: 0.55rem; border-top: 1px dashed var(--edge); margin-top: 0.1rem; }
.crit-toggle {
  display: inline-flex; align-items: center; gap: 0.45rem; cursor: pointer;
  border: 1px solid var(--edge);
  padding: 0.35rem 0.6rem; margin-left: auto;
  font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; font-weight: 600; color: var(--muted);
  user-select: none;
}
.crit-toggle:hover { border-color: var(--edge-strong); color: var(--text); }
.crit-toggle:has(input:checked) { color: var(--accent); border-color: var(--accent-line); background: var(--accent-soft); }
.crit-toggle:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

.formula {
  font-family: var(--font-mono); font-size: 12.5px; color: var(--accent);
  background: var(--panel-sunk); border: 1px solid var(--edge);
  padding: 0.5rem 0.65rem; overflow-x: auto; white-space: nowrap;
}
.formula .dim { color: var(--muted); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.65rem; }
.stat {
  background: var(--panel-sunk); border: 1px solid var(--edge);
  padding: 0.7rem 0.8rem; display: flex; flex-direction: column; gap: 0.25rem;
}
.stat-label { font-size: 10px; letter-spacing: 0.11em; text-transform: uppercase; color: var(--muted); font-weight: 600; display: flex; align-items: center; }
.stat-value { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 23px; line-height: 1.1; color: var(--text); }
.stat-sub { font-size: 11px; color: var(--muted); font-family: var(--font-mono); }
.stat.ok { border-color: var(--ok-line); background: var(--ok-soft); }
.stat.ok .stat-value { color: var(--ok); }
.stat.bad { border-color: var(--danger-line); background: var(--danger-soft); }
.stat.bad .stat-value { color: var(--danger); }
.stat.key .stat-value { color: var(--accent); }

.chart-footer { display: flex; flex-wrap: wrap; gap: 0.4rem 1.25rem; font-size: 11.5px; color: var(--muted); font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.chart-footer b { color: var(--text); font-weight: 600; }

.chart {
  display: flex; align-items: flex-end; gap: 2px;
  height: 150px; margin: 0.9rem 0 1.9rem;
  border-bottom: 1px solid var(--edge); padding-bottom: 1px;
}
.bar-container { flex: 1; min-width: 2px; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; cursor: crosshair; }
.bar { width: 100%; min-height: 1px; background: var(--accent); transition: height 0.3s ease, filter 0.15s; }
.bar-container:hover .bar { filter: brightness(1.5); }
.bar.danger { background: var(--danger); }
.bar-label { position: absolute; bottom: -1.35rem; font-size: 10px; color: var(--muted); font-family: var(--font-mono); }

.table-wrap { overflow: auto; max-height: 420px; border: 1px solid var(--edge); }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th, td { padding: 0.42rem 0.7rem; text-align: right; border-bottom: 1px solid var(--edge); white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
th { background: var(--panel-sunk); color: var(--muted); font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; font-weight: 600; position: sticky; top: 0; }
td { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { text-align: left; }
td:first-child { color: var(--muted); font-family: var(--font-main); }
tbody tr:hover td { background: rgba(90, 120, 150, 0.08); }
.na { color: var(--edge-strong); }
.row-fail td { background: var(--danger-soft); color: var(--danger); }
.row-fail td:first-child { color: var(--danger); }
.cascade-tables { display: flex; flex-direction: column; gap: 1.1rem; }

.summary-line { font-family: var(--font-mono); font-size: 13px; color: var(--text); }
.summary-line b { color: var(--accent); font-weight: 600; }
.summary-line .sep { color: var(--muted); margin: 0 0.4rem; }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; }
.actions .field { flex-direction: row; align-items: center; gap: 0.5rem; }
.actions .field input { width: 92px; }

.heat-meter-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin-bottom: 0.35rem; }
.heat-meter-head .mono { font-size: 13px; letter-spacing: 0; color: var(--text); }
.heat-meter { height: 7px; background: var(--panel-sunk); border: 1px solid var(--edge); overflow: hidden; }
.heat-meter-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.3s ease, background 0.3s; }
.heat-meter-fill.over { background: var(--danger); }

.wave-label { margin: 1rem 0 0.55rem; font-family: var(--font-mono); font-size: 11.5px; letter-spacing: 0.08em; color: var(--muted); }
.dice-stage { display: flex; flex-direction: column; gap: 0.7rem; min-height: 66px; }
.dice-group { display: flex; flex-direction: column; gap: 0.3rem; }
.dice-group.fading { opacity: 0; transition: opacity 0.25s ease; }
.dice-group-label { font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); font-family: var(--font-mono); }
.dice-group-label.crit { color: var(--accent); }
.dice-tray { display: flex; flex-wrap: wrap; gap: 4px; }
.die {
  width: 30px; height: 30px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--edge);
  background: var(--panel-sunk);
  font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 13px; color: var(--text);
}
.die.crit { border-style: dashed; }
.die.rolling { color: var(--muted); animation: die-spin 0.45s linear infinite; }
@keyframes die-spin { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
.die.trigger { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
.die.safe { color: var(--muted); opacity: 0.5; }

.verdict { margin-top: 0.9rem; padding: 0.6rem 0.8rem; font-family: var(--font-mono); font-size: 13px; display: none; }
.verdict.show { display: block; }
.verdict.stable { border: 1px solid var(--ok-line); background: var(--ok-soft); color: var(--ok); }
.verdict.stress { border: 1px solid var(--danger-line); background: var(--danger-soft); color: var(--danger); }

.log { background: var(--panel-sunk); border: 1px solid var(--edge); padding: 0.6rem 0.75rem; max-height: 260px; overflow-y: auto; font-family: var(--font-mono); font-size: 11.5px; line-height: 1.65; scroll-behavior: smooth; }
.log-line { color: var(--text); }
.log-line.standby { color: var(--muted); }
.log-line.trigger { color: var(--danger); }
.log-line.stable { color: var(--ok); }
.log-line.stress { color: var(--danger); font-weight: 600; }

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

@media (max-width: 620px) {
  body { padding-top: calc(var(--nav-h) + 0.7rem); font-size: 13.5px; }
  .container { padding: 1rem 0.85rem; }
  .card { padding: 0.9rem; }
  .tab-bar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .tab-bar::-webkit-scrollbar { display: none; }
  .stat-value { font-size: 20px; }
  .crit-toggle { margin-left: 0; }
}
.card-head-note { float: right; font-size: 11.5px; color: var(--muted); font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-weight: 400; text-transform: none; letter-spacing: 0; }
