:root {
  color-scheme: light;
  --bg: #e7ebf0;
  --bg-raise: rgba(255, 255, 255, 0.78);
  --ink: #2a3038;
  --muted: #66707c;
  --line: rgba(90, 102, 116, 0.16);
  --felt: #2f7d52;
  --felt-deep: #246643;
  --accent: #3e4854;
  --accent-ink: #f7f8fa;
  --silver: #c5ced8;
  --amber: #9a6b2f;
  --danger: #c4504a;
  --metal: #b7c0ca;
  --shadow: 0 16px 40px rgba(62, 72, 84, 0.12);
  --radius: 22px;
  font-family: "Segoe UI", "Avenir Next", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; color: var(--ink); }
body {
  min-height: 100dvh;
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(255, 255, 255, 0.9), transparent 55%),
    radial-gradient(900px 420px at 100% 0%, rgba(255, 255, 255, 0.55), transparent 50%),
    linear-gradient(180deg, #f4f6f8 0%, var(--bg) 42%, #dde3ea 100%);
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, p { margin: 0; }

.app {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 8px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand::before {
  content: "";
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background:
    radial-gradient(circle at 35% 30%, #fff, #d5dbe3 46%, #9aa6b3 78%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9), 0 8px 18px rgba(62, 72, 84, 0.16);
}
.brand strong { display: block; font-size: 1.12rem; letter-spacing: -0.02em; }
.brand span { color: var(--muted); font-size: 0.82rem; }
.conn {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--bg-raise);
  backdrop-filter: blur(16px);
  border-radius: 999px;
  padding: 7px 12px 7px 9px;
  max-width: 58vw;
  box-shadow: 0 8px 24px rgba(62, 72, 84, 0.06);
}
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #aeb6c0; flex: none;
}
.conn.on .dot { background: #3f9d68; box-shadow: 0 0 0 4px rgba(63, 157, 104, 0.16); }
.conn small { color: var(--muted); display: block; font-size: 0.72rem; }
.conn b { font-weight: 650; font-size: 0.86rem; }

.main { padding: 8px 18px 22px; overflow: auto; }

.hero { display: grid; gap: 12px; margin: 8px 0 18px; }
.hero h1 {
  font-size: clamp(1.9rem, 4.4vw, 2.8rem);
  line-height: 1.12;
  letter-spacing: -0.035em;
  max-width: 16ch;
  font-weight: 680;
}
.hero p { color: var(--muted); max-width: 62ch; line-height: 1.5; }

.grid { display: grid; gap: 12px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.card, .panel {
  background: var(--bg-raise);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.card {
  text-align: left;
  transition: transform 0.18s ease, border-color 0.18s ease;
}
.card:hover { transform: translateY(-2px); border-color: rgba(120, 132, 146, 0.45); }
.card b { display: block; margin-bottom: 4px; letter-spacing: -0.02em; }
.card span, .muted { color: var(--muted); font-size: 0.9rem; line-height: 1.4; }
.choice.active, .item.active, .nav button.active { border-color: rgba(80, 92, 106, 0.45); }

.stack { display: grid; gap: 8px; }
[hidden] { display: none !important; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.grow { flex: 1; min-width: 180px; }

button.primary, button.ghost, button.danger, button.soft {
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 11px 16px;
  transition: transform 0.15s ease, background 0.15s ease;
}
button.primary:hover, button.soft:hover, button.ghost:hover { transform: translateY(-1px); }
button.primary {
  background: linear-gradient(180deg, #4c5662, var(--accent));
  color: var(--accent-ink);
  font-weight: 680;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 8px 18px rgba(62, 72, 84, 0.18);
}
button.ghost { background: rgba(255, 255, 255, 0.55); border-color: var(--line); }
button.soft {
  background: linear-gradient(180deg, #fbfcfd, #e3e8ee);
  border-color: rgba(255, 255, 255, 0.8);
  box-shadow: inset 0 1px 0 #fff;
}
button.danger { background: var(--danger); color: white; font-weight: 700; }
button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

label.field { display: grid; gap: 6px; font-size: 0.82rem; color: var(--muted); }
input[type="text"], input[type="number"], select {
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 11px 12px;
  color: var(--ink);
}
input[type="range"] { width: 100%; accent-color: #6d7886; }
.switch { display: flex; align-items: center; gap: 8px; }

.workspace { display: grid; gap: 14px; }
@media (min-width: 980px) {
  .workspace { grid-template-columns: minmax(0, 1.4fr) minmax(300px, 0.8fr); align-items: start; }
}

.table-wrap { display: grid; gap: 8px; }
.table {
  position: relative;
  width: min(100%, 760px);
  aspect-ratio: 1.525 / 1.37;
  margin-inline: auto;
  background:
    linear-gradient(90deg, transparent 49.55%, rgba(255,255,255,0.9) 49.55% 50.45%, transparent 50.45%),
    linear-gradient(180deg, var(--felt), var(--felt-deep));
  border: 12px solid #d5dbe2;
  border-radius: 16px;
  box-shadow:
    var(--shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.85),
    inset 0 0 0 1px rgba(120, 132, 146, 0.35);
  touch-action: none;
  overflow: hidden;
}
.table .net {
  position: absolute; left: 0; right: 0; top: 0; height: 9px;
  background: repeating-linear-gradient(90deg, #f7f8fa 0 10px, #8d98a4 10px 14px);
}
.table .baseline {
  position: absolute; left: 10px; right: 10px; bottom: 10px; height: 2px;
  background: rgba(255,255,255,0.55);
}
.hint-abs {
  position: absolute; left: 12px; bottom: 14px; color: rgba(255,255,255,0.88);
  font-size: 0.75rem; pointer-events: none;
}
.ball {
  position: absolute;
  width: 48px; height: 48px; margin-left: -24px; margin-top: -24px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.85);
  background: radial-gradient(circle at 34% 30%, #fff, #f3f0e4 42%, #d7d2c2);
  color: #2a3038;
  display: grid; place-items: center;
  font-size: 0.62rem; font-weight: 760; line-height: 1.05; text-align: center;
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.22);
  user-select: none;
}
.ball.selected { outline: 3px solid #f7f8fa; outline-offset: 2px; }
.ball small { display: block; font-weight: 700; }
.side-tags { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.8rem; }

.stepper { display: flex; align-items: center; gap: 8px; }
.stepper button {
  width: 36px; height: 36px; border-radius: 12px;
  border: 1px solid var(--line); background: #fff;
}
.choice-row { display: flex; flex-wrap: wrap; gap: 6px; }
.choice {
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  padding: 8px 12px;
}
.choice.active { background: #3e4854; color: #f7f8fa; }

.list { display: grid; gap: 8px; }
.item {
  display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center;
  text-align: left;
}

.nav {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  margin: 0 12px 12px;
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(18px);
  box-shadow: 0 10px 30px rgba(62, 72, 84, 0.08);
  position: sticky;
  bottom: calc(8px + env(safe-area-inset-bottom));
}
.nav button {
  background: transparent; border: 1px solid transparent; color: var(--muted);
  border-radius: 16px; padding: 10px 4px; font-size: 0.78rem;
}
.nav button.active { color: var(--ink); background: #fff; border-color: var(--line); }

.runner, .sheet {
  position: fixed; inset: 0;
  background: rgba(42, 48, 56, 0.28);
  backdrop-filter: blur(8px);
  display: grid; place-items: end center;
  padding: 18px;
  z-index: 20;
}
.sheet { z-index: 40; place-items: center; }
.runner .panel, .install-card { width: min(440px, 100%); display: grid; gap: 12px; }
.runner strong { font-size: 2.4rem; letter-spacing: -0.04em; }
.eyebrow {
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.log {
  position: fixed; right: 12px; bottom: 92px; width: min(420px, calc(100% - 24px));
  max-height: 40dvh; overflow: auto; z-index: 15;
  font-family: ui-monospace, Consolas, monospace; font-size: 0.75rem;
}
.log div { padding: 2px 0; }
.log .out { color: #3d5168; }
.log .in { color: var(--amber); }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%);
  background: #fff; color: var(--ink); padding: 12px 16px; border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 30; max-width: min(520px, calc(100% - 24px));
}

.calib-readout { font-variant-numeric: tabular-nums; font-size: 1.35rem; letter-spacing: -0.03em; }
.warn { color: var(--amber); }

@media (max-width: 720px) {
  .top { align-items: flex-start; }
  .nav { margin-inline: 8px; }
}
