:root {
  color-scheme: dark;
  --bg: #061522;
  --bg-deep: #04101a;
  --panel: #0b1b2a;
  --panel-raised: #0d2233;
  --panel-hover: #102b3e;
  --line: #19374b;
  --line-strong: #28536b;
  --muted: #8ca2b4;
  --muted-bright: #b9c8d2;
  --text: #f1f7fb;
  --cyan: #16c8ff;
  --cyan-soft: #0b617e;
  --focus: #7ce3ff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg-deep);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    radial-gradient(circle at 18% 0%, rgba(20, 57, 79, 0.56), transparent 34rem),
    linear-gradient(rgba(24, 67, 88, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(24, 67, 88, 0.055) 1px, transparent 1px);
  background-size: auto, 32px 32px, 32px 32px;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
  cursor: pointer;
}

.site-header {
  display: flex;
  align-items: center;
  gap: 13px;
  min-height: 56px;
  padding: 0 22px;
  border-bottom: 1px solid rgba(25, 55, 75, 0.9);
  background: rgba(3, 15, 25, 0.82);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  font-size: 14px;
  font-weight: 650;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 27px;
  height: 27px;
  place-items: center;
  border: 1px solid var(--cyan);
  border-radius: 7px;
  color: var(--cyan);
  font-size: 20px;
  line-height: 1;
}

.divider {
  height: 19px;
  border-left: 1px solid #385063;
}

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
}

.help-button {
  margin-left: auto;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(8, 26, 39, 0.8);
  color: var(--muted-bright);
  font-size: 11px;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease;
}

.help-button:hover,
.help-button:focus-visible {
  border-color: var(--cyan-soft);
  background: var(--panel-hover);
  color: var(--text);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 240px;
  gap: 12px;
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 12px;
}

.workspace-panel,
.panel,
.tip-bar {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(145deg, rgba(14, 34, 49, 0.97), rgba(7, 23, 35, 0.98));
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.12);
}

.workspace-panel {
  min-width: 0;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1.38;
  min-height: 430px;
  overflow: hidden;
  border-radius: 7px;
}

.canvas-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: none;
}

.canvas-wrap canvas:focus-visible {
  box-shadow: inset 0 0 0 2px var(--focus);
}

.canvas-hint {
  position: absolute;
  bottom: 18px;
  left: 0;
  width: 100%;
  padding: 0 12px;
  color: #a4b4c0;
  font-size: 11px;
  text-align: center;
  pointer-events: none;
}

.canvas-hint span,
.tip-icon {
  color: var(--cyan);
  font-size: 17px;
  vertical-align: middle;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.panel {
  padding: 15px 13px;
}

.eyebrow {
  margin: 0 0 7px;
  color: #abb9c4;
  font-size: 9px;
  font-weight: 650;
  letter-spacing: 0.12em;
}

.angle-readout {
  display: block;
  font-size: clamp(34px, 4vw, 46px);
  font-weight: 700;
  letter-spacing: -0.05em;
  line-height: 1.12;
  text-align: center;
}

.mode-label {
  margin: 5px 0 15px;
  color: var(--cyan);
  font-size: 11px;
  text-align: center;
}

.angle-glyph {
  font-size: 16px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.segment {
  min-height: 32px;
  padding: 6px 4px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #122334;
  color: #9baab5;
  font-size: 10px;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease;
}

.segment:hover {
  border-color: var(--line-strong);
  color: var(--text);
}

.segment.is-selected {
  border-color: var(--cyan);
  background: #0c2b3d;
  color: var(--cyan);
}

.control-button,
.control-row {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 47px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #0c2030;
  text-align: left;
}

.control-row {
  position: relative;
  margin-top: 8px;
}

.control-icon {
  width: 21px;
  color: var(--cyan);
  font-size: 18px;
  text-align: center;
}

.control-button strong,
.control-row strong {
  display: block;
  font-size: 10px;
  font-weight: 550;
}

.control-button small,
.control-row small {
  display: block;
  margin-top: 2px;
  color: #8194a2;
  font-size: 8px;
}

.control-button:hover,
.control-button:focus-visible,
.control-row:hover,
.control-row:focus-within {
  border-color: var(--cyan-soft);
  background: var(--panel-hover);
}

.control-row input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.switch {
  position: relative;
  width: 25px;
  height: 14px;
  margin-left: auto;
  flex: 0 0 auto;
  border-radius: 10px;
  background: #586572;
}

.switch::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #c5d0d8;
  content: "";
  transition: transform 160ms ease;
}

.control-row input:checked + .switch {
  background: var(--cyan);
}

.control-row input:checked + .switch::after {
  background: white;
  transform: translateX(11px);
}

.info-panel {
  flex: 1;
}

.info-panel dl {
  margin: 0;
}

.info-panel dl div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid #183246;
  font-size: 10px;
}

.info-panel dt {
  color: #c0ccd4;
}

.info-panel dt span {
  margin-right: 4px;
  color: var(--cyan);
}

.info-panel dd {
  margin: 0;
  color: var(--cyan);
  white-space: nowrap;
}

.tip-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto 14px;
  padding: 9px 13px;
  color: #8fa5b4;
  font-size: 10px;
}

.tip-bar strong {
  color: var(--cyan);
  font-weight: 550;
}

.dialog {
  position: fixed;
  z-index: 2;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(2, 11, 18, 0.72);
}

.dialog[hidden] {
  display: none;
}

.dialog-card {
  position: relative;
  width: min(100%, 360px);
  padding: 24px;
  border: 1px solid var(--cyan-soft);
  border-radius: 8px;
  background: var(--panel);
  line-height: 1.5;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.35);
}

.dialog-card h2 {
  margin: 0 0 9px;
  font-size: 19px;
}

.dialog-card p {
  margin: 0;
  color: #b7c6cf;
  font-size: 13px;
}

.close-button {
  position: absolute;
  top: 7px;
  right: 10px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 22px;
}

.close-button:hover {
  color: var(--text);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

@media (max-width: 760px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) 205px;
  }

  .canvas-wrap {
    min-height: 380px;
  }
}

@media (max-width: 620px) {
  .site-header {
    min-height: 52px;
    padding: 0 12px;
  }

  .tagline,
  .help-button span {
    display: none;
  }

  .layout {
    grid-template-columns: 1fr;
    width: min(100% - 20px, 520px);
    padding-top: 10px;
  }

  .canvas-wrap {
    aspect-ratio: 1 / 1;
    min-height: 0;
  }

  .sidebar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .readout-panel {
    grid-row: span 2;
  }

  .info-panel {
    grid-column: 1 / -1;
  }

  .tip-bar {
    width: min(100% - 20px, 520px);
    margin-bottom: 10px;
  }
}

@media (max-width: 390px) {
  .sidebar {
    display: flex;
  }

  .readout-panel {
    order: -1;
  }

  .tip-bar {
    align-items: flex-start;
    line-height: 1.4;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
