@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&family=Space+Mono:wght@400;700&display=swap');

:root {
  --bg: #0a0f14;
  --surface: #0a0f14;
  --panel: #0d1520;
  --border: #1a2a3c;
  --border2: #1f3048;
  --accent: #00eeff;
  --accent2: #ff7a1a;
  --green: #00ff88;
  --red: #ff3355;
  --yellow: #ffd600;
  --text: #dde8f0;
  --muted: #6a8498;
  --muted2: #2a3a4a;
  --font-display: 'Orbitron', 'Arial Black', sans-serif;
  --font-mono: 'Space Mono', 'Courier New', monospace;
}

canvas { display: block; max-width: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 15px;
  min-height: 100vh;
  overflow-x: hidden;
}

.header {
  padding: 2rem 2rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding-bottom: 1.2rem;
  flex-wrap: wrap;
  gap: 1rem;
}
.logo { display:flex; flex-direction:column; gap:.55rem; }
.logo-title {
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 3vw, 2rem);
  font-weight: 900;
  letter-spacing: .12em;
  color: var(--accent);
  line-height:1;
  text-shadow: 0 0 30px rgba(0,238,255,0.5);
}
.logo-sub {
  font-size: .65rem;
  letter-spacing: .3em;
  color: var(--muted);
  text-transform: uppercase;
}

.app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem 2rem 3rem;
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 1.5rem;
}

/* ── Tablet (portrait iPad etc) ── */
@media(max-width:900px) {
  .app { grid-template-columns: 1fr; padding: 1rem 1rem 2rem; }
  .onboard { padding: .8rem 1rem 0; }
  .header { padding: 1.2rem 1rem 0; }
  .header-inner { padding-bottom: .9rem; }
}

/* ── Phone ── */
@media(max-width:520px) {
  .app { padding: .6rem .6rem 2rem; gap: .8rem; }
  .onboard { padding: .6rem .6rem 0; }
  .header { padding: .9rem .6rem 0; }
  .logo-title { font-size: 1.2rem; letter-spacing: .08em; }
  .logo-sub { font-size: .55rem; letter-spacing: .18em; }
  .section-body { padding: .75rem .75rem; gap: .6rem; }
  .section-header { padding: .6rem .75rem; }
  .results-grid { grid-template-columns: 1fr 1fr; gap: .5rem; }
  .result-card { padding: .75rem .85rem; }
  .result-value { font-size: 1.7rem; }
  .chart-card { padding: .9rem .9rem; }
  .breakdown-card { padding: .9rem .9rem; }
  .range-card { padding: .9rem .9rem; }
  .onboard-body { padding: .9rem .9rem; gap: .75rem; }
  .run-btn { font-size: .68rem; padding: .9rem .75rem; }
  .save-btn { font-size: .55rem; }
}

.sidebar { display:flex; flex-direction:column; gap:1rem; }
.sidebar-sticky { margin-top:.5rem; padding-top:.8rem; border-top: 1px solid var(--border); }

.section-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.section-header {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .7rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}
.section-header:hover { background: #141c24; }
.section-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink:0;
  box-shadow: 0 0 6px currentColor;
}
.section-title {
  font-family: var(--font-display);
  font-size: .65rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--text);
  flex:1;
}
.section-arrow {
  font-size: .7rem;
  color: var(--muted);
  transition: transform .2s;
}
.section-arrow.open { transform: rotate(90deg); }

.section-body { padding: 1rem; display:flex; flex-direction:column; gap:.7rem; }
.section-body.collapsed { display:none; }

.input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: .5rem;
}
.input-row label {
  font-size: .72rem;
  color: var(--text);
  letter-spacing: .03em;
  line-height: 1.3;
}
.input-row label span {
  display: block;
  font-size: .6rem;
  color: #7a9ab0;
  margin-top:.1rem;
}
.input-wrap {
  display:flex;
  align-items:center;
  gap:.3rem;
}
input[type=number], select {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 3px;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: .8rem;
  padding: .35rem .5rem;
  width: 80px;
  text-align: right;
  outline: none;
  transition: border-color .15s;
  /* Ensure adequate touch target height */
  min-height: 36px;
}
@media(max-width:520px) {
  input[type=number] { width: 68px; font-size: .75rem; min-height: 40px; }
  .input-row label { font-size: .68rem; }
  .unit { font-size: .6rem; width: 22px; }
}
input[type=number]:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(0,212,255,0.1);
}
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button { opacity: 1; }
select { width: auto; text-align:left; cursor:pointer; }
.unit {
  font-size: .65rem;
  color: var(--muted);
  white-space: nowrap;
  width: 28px;
}

.input-full { display:flex; flex-direction:column; gap:.3rem; }
.input-full label { font-size:.7rem; color:var(--muted); }
.input-full select { width:100%; text-align:left; }

.divider { border:none; border-top:1px solid var(--border); margin:.2rem 0; }

@keyframes card-pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.03); }
  100% { transform: scale(1); }
}
.run-btn {
  width: 100%;
  padding: 1rem 1rem .85rem;
  background: #e8002d;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-family: var(--font-display);
  font-size: .75rem;
  font-weight: 900;
  letter-spacing: .2em;
  cursor: pointer;
  transition: filter .15s, transform .1s;
  box-shadow: 0 0 18px rgba(232,0,45,0.3);
}
.run-btn:hover { filter: brightness(1.1); transform: translateY(-1px); }
.run-btn:active { transform: scale(.98); filter: brightness(.95); }
.result-card.pop { animation: card-pop .35s ease-out; }

.main { display:flex; flex-direction:column; gap:1.2rem; }

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: .8rem;
}
.result-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.1rem;
  position:relative;
  overflow:hidden;
  transition: border-color .3s;
}
.result-card::before {
  content:'';
  position:absolute; top:0; left:0; right:0;
  height: 3px;
  transition: opacity .3s;
}
.rc-cyan::before   { background: var(--accent); }
.rc-orange::before { background: var(--accent2); }
.rc-red::before    { background: var(--red); }

.result-label {
  font-size: .6rem;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: .4rem;
}
.result-value {
  font-family: var(--font-display);
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1;
  transition: color .3s;
}
.rc-cyan   .result-value { color: var(--accent); text-shadow: 0 0 20px rgba(0,238,255,0.4); }
.rc-orange .result-value { color: var(--accent2); text-shadow: 0 0 20px rgba(255,122,26,0.4); }
.rc-red    .result-value { color: var(--red); text-shadow: 0 0 20px rgba(255,51,85,0.4); }
.result-unit { font-size: .65rem; color: var(--muted); margin-top:.25rem; }

.chart-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.2rem 1.4rem;
  position:relative;
  min-height: 280px;
}
.chart-card::before {
  content:'';
  position:absolute; top:0; left:0; right:0;
  height:3px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  box-shadow: 0 0 12px rgba(0,238,255,0.3);
}
.chart-header {
  display:flex; justify-content:space-between; align-items:center;
  margin-bottom:1rem; flex-wrap:wrap; gap:.5rem;
}
@media(max-width:520px) {
  .chart-header { margin-bottom: .7rem; }
  .chart-legend { gap: .6rem; }
  .legend-item { font-size: .58rem; }
}
.chart-title { font-size:.62rem; letter-spacing:.2em; color:var(--muted); text-transform:uppercase; }
.chart-legend { display:flex; gap:1rem; }
.legend-item { display:flex; align-items:center; gap:.4rem; font-size:.65rem; color:var(--muted); }
.legend-dot { width:8px; height:8px; border-radius:50%; }

.range-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.1rem 1.4rem;
}
.range-note { font-size:.65rem; color:#7a9ab0; line-height:1.6; }

.empty-state {
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  height:200px; color:var(--muted2); gap:.8rem;
  position:absolute; top:0; left:0; right:0; bottom:0;
  pointer-events:none;
}
.chart-card, .breakdown-card, .range-card {
  position: relative;
}
.empty-icon { font-size:2.5rem; opacity:.4; }
.empty-text { font-size:.75rem; letter-spacing:.1em; }

::-webkit-scrollbar { width:6px; }
::-webkit-scrollbar-track { background:var(--bg); }
::-webkit-scrollbar-thumb { background:var(--border2); border-radius:3px; }

.onboard {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.2rem 2rem 0;
}
.onboard-inner {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.onboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .7rem 1.1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}
.onboard-header:hover { background: #141c24; }
.onboard-tag {
  font-family: var(--font-display);
  font-size: .58rem;
  letter-spacing: .2em;
  color: var(--accent);
  text-transform: uppercase;
}
.onboard-toggle { font-size: .65rem; color: var(--muted); }
.onboard-body {
  padding: 1.1rem 1.4rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}
.onboard-body.hidden { display: none; }
.step { display: flex; gap: .8rem; align-items: flex-start; }
.step-num {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 900;
  color: var(--accent);
  opacity: .3;
  line-height: 1;
  flex-shrink: 0;
  width: 24px;
}
.step-title { font-size: .7rem; color: var(--text); font-weight: 600; margin-bottom: .2rem; letter-spacing: .05em; }
.step-desc { font-size: .65rem; color: var(--muted); line-height: 1.6; }
.step-tool {
  display: inline-block;
  font-size: .58rem;
  color: var(--accent);
  border: 1px solid rgba(0,212,255,.3);
  border-radius: 2px;
  padding: .1rem .4rem;
  margin-top: .3rem;
  letter-spacing: .08em;
}
.onboard-note {
  grid-column: 1 / -1;
  font-size: .63rem;
  color: #7a9ab0;
  border-top: 1px solid var(--border);
  padding-top: .8rem;
  line-height: 1.7;
}

.save-bar { display:flex; flex-direction:column; gap:.4rem; margin-top:.5rem; }
.save-input {
  flex:1; background:var(--surface); border:1px solid var(--border2);
  color:var(--text); font-family:var(--font-mono); font-size:.65rem;
  padding:.45rem .7rem; border-radius:3px; outline:none;
}
.save-input:focus { border-color:var(--accent); }
.save-input::placeholder { color:var(--muted); }
.save-btn {
  font-family:var(--font-display); font-size:.58rem; letter-spacing:.1em;
  padding:.45rem .9rem; border-radius:6px; cursor:pointer; white-space:nowrap;
  border:1px solid var(--accent); background:transparent; color:var(--accent);
  transition:all .2s;
  box-shadow: 0 0 8px rgba(0,238,255,0.15);
}
.save-btn:hover { background:var(--accent); color:#000; box-shadow: 0 0 16px rgba(0,238,255,0.4); transform: translateY(-1px); }
.mini-btn {
  font-family:var(--font-display); font-size:.52rem; letter-spacing:.08em;
  padding:.3rem .6rem; border-radius:3px; cursor:pointer;
  border:1px solid var(--border2); background:transparent; color:#7a9ab0;
  transition:all .15s;
  min-height: 36px;
  white-space: nowrap;
}
.mini-btn:hover { border-color:var(--accent); color:var(--accent); }
.mini-btn.danger { border-color:var(--border2); color:var(--muted); }
.mini-btn.danger:hover { border-color:var(--red); color:var(--red); }

.run-row {
  display:grid; grid-template-columns:auto 1fr auto auto auto;
  align-items:center; gap:.5rem;
  padding:.45rem .5rem; border-bottom:1px solid var(--border);
  font-size:.65rem;
}
@media(max-width:520px) {
  .run-row { grid-template-columns: auto 1fr auto auto; font-size:.6rem; gap:.3rem; }
  .run-time { font-size:.65rem; }
}
.run-row:last-child { border-bottom:none; }
.run-dot { width:10px; height:10px; border-radius:50%; flex-shrink:0; }
.run-name { color:var(--text); font-weight:600; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.run-time { color:var(--accent); font-weight:700; white-space:nowrap; }
.run-delta { font-size:.62rem; font-weight:700; white-space:nowrap; }
.run-delta.faster { color:var(--green); }
.run-delta.slower { color:var(--red); }
.run-del { cursor:pointer; color:var(--muted); font-size:.7rem; padding:.1rem .3rem; }
.run-del:hover { color:var(--red); }

.input-wrap input.invalid { border-color:var(--red) !important; }

#validation-banner {
  display:none; background:rgba(255,51,85,0.12);
  border:1px solid rgba(255,51,85,0.4);
  border-radius:3px; padding:.6rem .9rem;
  font-size:.65rem; color:#ff8899; line-height:1.6;
  margin-bottom:.5rem;
}
#validation-banner.visible { display:block; }

.tip-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #1e2a38;
  border: 1px solid #2a3a4a;
  color: #7a9ab0;
  font-size: 10px;
  font-family: Arial, sans-serif;
  font-weight: 700;
  cursor: pointer;
  margin-left: 5px;
  vertical-align: middle;
  flex-shrink: 0;
  padding: 0; line-height: 0; letter-spacing: 0;
}
.tip-btn:focus { outline: none; }
.tip-box {
  display: none;
  background: #0d1117;
  border: 1px solid #1e2a38;
  border-radius: 4px;
  padding: .6rem .8rem;
  font-size: .63rem;
  color: #c8d8e8;
  line-height: 1.6;
  margin-top: .4rem;
  width: 100%;
  box-sizing: border-box;
}
.tip-box.open { display: block; }

.pill-group {
  display: flex; gap: 0;
  border: 1px solid var(--border2);
  border-radius: 6px;
  overflow: hidden;
  width: 100%;
}
.pill-opt {
  flex: 1;
  padding: .5rem .4rem;
  font-family: var(--font-mono);
  font-size: .63rem;
  color: var(--muted);
  background: var(--surface);
  border: none;
  border-right: 1px solid var(--border2);
  cursor: pointer;
  text-align: center;
  transition: background .15s, color .15s;
  line-height: 1.3;
  min-height: 44px;  /* touch target */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.pill-opt:last-child { border-right: none; }
.pill-opt:hover { background: #151e2a; color: var(--text); }
.pill-opt.active {
  background: rgba(0,238,255,0.18);
  color: var(--accent);
  font-weight: 700;
  border-bottom: 2px solid var(--accent);
}

.styled-select-wrap {
  position: relative;
  width: 100%;
}
.styled-select-wrap::after {
  content: '▾';
  position: absolute;
  right: .7rem; top: 50%;
  transform: translateY(-50%);
  color: var(--accent);
  font-size: .7rem;
  pointer-events: none;
}
.styled-select {
  width: 100%;
  appearance: none; -webkit-appearance: none;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: .65rem;
  padding: .5rem 2rem .5rem .75rem;
  cursor: pointer; outline: none;
  transition: border-color .15s;
  min-height: 40px;
}
.styled-select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(0,212,255,0.1); }
.styled-select option { background: #0d1117; color: var(--text); }

.breakdown-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.1rem 1.4rem;
}
.breakdown-title { font-size:.62rem; letter-spacing:.2em; color:var(--muted); text-transform:uppercase; margin-bottom:.9rem; }
.breakdown-row {
  display:flex; align-items:center; gap:.8rem;
  padding:.35rem 0; border-bottom:1px solid var(--border);
  font-size:.72rem;
}
.breakdown-row:last-child { border-bottom:none; }
.bd-label { color:var(--muted); flex:1; }
.bd-bar-wrap { flex:2; height:4px; background:var(--surface); border-radius:2px; overflow:hidden; }
.bd-bar { height:100%; border-radius:2px; transition: width .5s; }
.bd-val { display: none; }

/* Light mode */
body.light {
  --bg: #f0f4f8;
  --surface: #ffffff;
  --panel: #ffffff;
  --border: #d0dae6;
  --border2: #b8c8d8;
  --accent: #0088bb;
  --accent2: #d44800;
  --green: #008844;
  --red: #cc1133;
  --yellow: #aa8800;
  --text: #1a2a3a;
  --muted: #5a7080;
  --muted2: #c0d0dc;
}
body.light .header { border-bottom-color: var(--border); }
body.light input[type=number], body.light .styled-select { color: var(--text); }
body.light .rc-cyan .result-value,
body.light .rc-orange .result-value,
body.light .rc-red .result-value { text-shadow: none; }
body.light .chart-card::before { box-shadow: none; }

.theme-toggle {
  background: none;
  border: 1px solid var(--border2);
  border-radius: 20px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: .6rem;
  padding: .3rem .7rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: .4rem;
  transition: border-color .15s, color .15s;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }

#r-delta.faster { background:rgba(0,255,136,0.15); color:var(--green); }
#r-delta.slower { background:rgba(255,51,85,0.15); color:var(--red); }

#replay-canvas { background: #0a0f14 !important; border: 1px solid var(--border); border-radius: 6px; }
body.light #replay-canvas { background: #a8b8c8 !important; border: 1px solid #000 !important; }