:root {
  --bg: #0b1117;
  --bg-soft: #121a22;
  --surface: #162130;
  --surface-border: #27364a;
  --text: #f3f7ff;
  --text-muted: #a9bbd4;
  --muted-line: #2c3d53;
  --accent: #5aa2ff;
  --accent-weak: #24466c;
  --green: #6ccf90;
  --chart-shape: #9eb0c7;
  --chart-output: #6ccf90;
  --chart-trig: #ff9d4f;

  --radius: 14px;
  --gap: 12px;
  --font: Inter, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  width: 100%;
}

html {
  height: 100%;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  min-height: 100svh;
  padding: 8px 10px 10px;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.app-shell {
  max-width: 1100px;
  margin: 0 auto;
  display: grid;
  gap: 14px;
  min-height: 100%;
  width: 100%;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.app-header h1 {
  margin: 0;
  font-size: 1.3rem;
  line-height: 1.2;
}

.subtitle {
  margin: 4px 0 0;
  color: var(--text-muted);
  max-width: 780px;
  font-size: 0.95rem;
}

.badge {
  border: 1px solid var(--surface-border);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.panel {
  background: var(--bg-soft);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius);
  padding: 12px;
  width: 100%;
}

.app-shell,
.panel,
.chart {
  min-width: 0;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 1rem;
  line-height: 1.3;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--gap);
}

.field {
  display: grid;
  gap: 8px;
  font-size: 0.92rem;
  color: var(--text-muted);
  min-width: 0;
}

.field span {
  display: flex;
  gap: 6px;
  align-items: baseline;
  justify-content: space-between;
  min-width: 0;
}

.field span > strong {
  margin-left: auto;
  flex: 0 0 auto;
  max-width: 46%;
  text-align: right;
  overflow-wrap: anywhere;
}

.field input,
.field select {
  width: 100%;
  background: #0e1620;
  border: 1px solid var(--surface-border);
  border-radius: 10px;
  color: var(--text);
  padding: 10px;
  font-size: 0.95rem;
  outline: none;
  min-height: 44px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-appearance: auto;
  appearance: auto;
}

.field input[type=range] {
  padding: 9px 4px;
}

.field strong {
  justify-self: end;
  font-size: 0.92rem;
  color: var(--text);
  min-height: 18px;
}

.info-grid {
  margin-top: 12px;
  display: grid;
  gap: var(--gap);
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.card {
  border-radius: 12px;
  border: 1px solid var(--surface-border);
  background: #101a24;
  padding: 10px;
}

.card p {
  margin: 0 0 8px;
  color: var(--text-muted);
}

.card strong {
  display: block;
  margin-bottom: 4px;
  font-size: 1.06rem;
}

.icon-grid,
.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(86px, 1fr));
  gap: 10px;
}

.icon-btn {
  background: #101a24;
  color: var(--text);
  border: 1px solid var(--surface-border);
  border-radius: 12px;
  padding: 10px;
  cursor: pointer;
  min-height: 74px;
  display: grid;
  align-content: start;
  justify-items: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  pointer-events: auto;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.icon-btn[aria-pressed="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(90, 162, 255, 0.35) inset;
  background: #152f47;
  transform: translateY(1px);
  z-index: 1;
  position: relative;
}

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

.icon-btn svg {
  width: 100%;
  height: auto;
  pointer-events: none;
}

.icon-caption {
  margin-top: 6px;
  text-align: center;
  display: block;
  font-size: 0.72rem;
  color: #c7d8ed;
}

.help-text {
  margin: 8px 0 0;
  color: var(--text-muted);
}

.chart-wrap {
  width: 100%;
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid var(--surface-border);
  background: #0d141f;
}

.chart {
  display: block;
  width: 100%;
  height: 390px;
  min-height: 230px;
}

.dt2-gridline {
  stroke: var(--muted-line);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.dt2-zero {
  stroke: #5f7895;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.dt2-shape {
  fill: none;
  stroke: var(--chart-shape);
  stroke-width: 1.8;
  stroke-dasharray: 4 4;
  vector-effect: non-scaling-stroke;
}

.dt2-output {
  fill: none;
  stroke: var(--chart-output);
  stroke-width: 2.5;
  vector-effect: non-scaling-stroke;
}

.dt2-trigger {
  stroke: var(--chart-trig);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

.dt2-axis-text,
.dt2-label {
  fill: #9eb0c7;
  font-size: 11px;
}

.dt2-trigger-text {
  fill: var(--text);
  font-size: 11px;
}

.window-switch {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  position: relative;
  z-index: 2;
}

.window-switch .btn {
  flex: 1;
  white-space: nowrap;
  min-height: 38px;
}

.btn {
  border: 1px solid var(--surface-border);
  background: #101a24;
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  pointer-events: auto;
  -webkit-appearance: none;
  appearance: none;
}

.btn-primary {
  background: var(--accent);
  color: #07111d;
  border-color: #77b2ff;
}

.legend {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.legend .line {
  width: 16px;
  height: 2px;
  display: inline-block;
  vertical-align: middle;
  margin-right: 6px;
}

.line-main {
  background: var(--chart-output);
}

.line-shape {
  background: var(--chart-shape);
}

.status {
  display: block;
  margin-top: 8px;
  color: var(--text-muted);
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
  overscroll-behavior: contain;
  border-radius: 10px;
  border: 1px solid var(--surface-border);
  background: #101a24;
  padding: 2px;
}

#speed-table {
  border-collapse: collapse;
  min-width: 100%;
  width: 100%;
}

#speed-table th,
#speed-table td {
  border: 1px solid var(--surface-border);
  padding: 4px;
  text-align: center;
  white-space: nowrap;
}

.table-cell {
  background: #101a24;
  min-width: 44px;
  border-radius: 0;
  padding: 5px 1px 4px;
  border: 0;
  color: var(--text);
  cursor: pointer;
  min-height: 36px;
  width: 100%;
  display: block;
  user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  pointer-events: auto;
  -webkit-appearance: none;
  appearance: none;
  font-size: 0.78rem;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.table-cell.selected,
.table-cell[aria-pressed="true"] {
  background: var(--accent);
  color: #091220;
  font-weight: 700;
  box-shadow: inset 0 0 0 2px rgba(11, 17, 29, 0.25);
}

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

.table-cell small {
  color: #9eb0c7;
}

.wave-wave {
  fill: none;
  stroke: var(--text);
  stroke-width: 2;
}

.wave-axis {
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 1;
}

.wave-label {
  fill: var(--text-muted);
  font-size: 7px;
  font-family: var(--font);
  font-weight: 600;
}

.wave-trigger {
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 1;
  stroke-dasharray: 2 2;
}

strong {
  color: var(--text);
}

@media (max-width: 760px) {
  html,
  body {
    overflow-y: auto;
  }

  .app-shell {
    gap: 8px;
  }

  .info-grid {
    grid-template-columns: 1fr;
  }

  .app-header {
    align-items: center;
    flex-direction: column;
    gap: 4px;
  }

  .app-header h1 {
    font-size: 1rem;
    text-align: center;
  }

  .subtitle {
    text-align: center;
    font-size: 0.8rem;
    margin: 0;
  }

  .controls-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .field {
    gap: 6px;
    font-size: 0.82rem;
  }

  .field strong {
    font-size: 0.84rem;
  }

  .field input,
  .field select {
    min-height: 38px;
    font-size: 0.88rem;
  }

  .panel {
    padding: 8px;
  }

  .panel h2 {
    font-size: 0.93rem;
    margin-bottom: 8px;
  }

  .card {
    padding: 8px;
  }

  .card p {
    margin-bottom: 6px;
    font-size: 0.8rem;
  }

  .card strong {
    margin-bottom: 2px;
    font-size: 0.96rem;
  }

  .info-grid {
    margin-top: 8px;
  }

  #speed-table th,
  #speed-table td {
    padding: 4px 1px;
    font-size: 11px;
  }

  .table-cell {
    min-width: 42px;
    padding: 4px 1px;
    font-size: 0.72rem;
  }

  #speed-table th:first-child {
    white-space: nowrap;
    text-align: center;
    min-width: 36px;
  }

  .table-wrap {
    padding: 0;
    border: 0;
    border-radius: 8px;
  }

  .status {
    font-size: 0.76rem;
  }

  .panel-title,
  .viz-controls,
  .window-switch,
  .legend,
  .status,
  .icon-caption {
    overflow-wrap: anywhere;
  }

  .help-text {
    display: none;
  }

  .chart {
    height: 252px;
  }

  .controls-grid {
    gap: 8px;
  }

  .icon-grid,
  .mode-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }

  .icon-btn {
    min-height: 56px;
    padding: 6px 4px 8px;
    border-radius: 10px;
  }

  .icon-btn svg {
    width: 80%;
  }

  .icon-caption {
    font-size: 0.67rem;
    margin-top: 4px;
  }

  .btn,
  .field select,
  .field input[type=range],
  .table-cell {
    min-height: 36px;
  }

  .window-switch {
    flex-wrap: nowrap;
  }

  .btn {
    padding: 8px 8px;
    flex: 1;
  }

  .badge {
    margin-top: 2px;
    font-size: 0.74rem;
  }
}

@media (max-width: 390px) {
  body {
    padding-left: 6px;
    padding-right: 6px;
  }

  .icon-grid,
  .mode-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 5px;
  }

  .icon-btn {
    min-height: 52px;
  }

  .panel {
    border-radius: 12px;
  }

  .chart {
    height: 208px;
  }

  .app-header h1 {
    font-size: 0.96rem;
  }

  .subtitle {
    font-size: 0.74rem;
  }

  .table-cell {
    min-width: 38px;
    font-size: 0.68rem;
  }
}
