:root {
  --bg0: #e8efe9;
  --panel: rgba(247, 244, 239, 0.92);
  --panel-border: rgba(13, 92, 86, 0.18);
  --teal: #0d5c56;
  --teal-deep: #084742;
  --teal-soft: #c4e8e2;
  --ink: #1a2b2a;
  --ink-soft: #3d5250;
  --muted: #5c706e;
  --accent: #c45c26;
  --accent-soft: #f5e6dc;
  --text: #1a2b2a;
  --line: rgba(13, 92, 86, 0.22);
  --radius: 14px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #d8e0d6;
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
}

#c {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

.topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: linear-gradient(180deg, rgba(247,244,239,0.72), rgba(247,244,239,0.18) 70%, transparent);
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  text-shadow: 0 1px 2px rgba(255,255,255,0.7);
}
.brand .wordmark {
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--teal);
  font-weight: 700;
}
.brand h1 {
  font-size: clamp(14px, 3.4vw, 20px);
  font-weight: 650;
  color: var(--ink);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand a.kitchen-link {
  color: var(--ink-soft);
  font-size: 12px;
  text-decoration: none;
  border-bottom: 1px solid transparent;
}
.brand a.kitchen-link:hover {
  color: var(--teal);
  border-bottom-color: var(--teal-soft);
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.controls {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 8px 24px rgba(26, 43, 42, 0.08);
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.row label.explode-label,
.row .explode-label {
  font-size: 12px;
  color: var(--muted);
  min-width: 56px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 650;
}

#explodeRange {
  flex: 1;
  min-width: 120px;
  accent-color: var(--teal);
  height: 28px;
  cursor: pointer;
}

#explodePct {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--teal);
  min-width: 40px;
  text-align: right;
  font-weight: 650;
}

.size-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  flex: 1;
}
.size-pills button {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  font-weight: 650;
  padding: 6px 9px;
  border-radius: 8px;
  cursor: pointer;
  min-width: 40px;
}
.size-pills button:hover { background: var(--teal-soft); }
.size-pills button.active {
  background: var(--teal);
  border-color: var(--teal-deep);
  color: #fff;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(13, 92, 86, 0.06);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  white-space: nowrap;
  user-select: none;
}
.btn:hover { background: rgba(13, 92, 86, 0.14); border-color: var(--teal); }
.btn:active { transform: scale(0.97); }
.btn.active {
  background: var(--teal);
  border-color: var(--teal-deep);
  color: #fff;
}
.btn.primary {
  background: linear-gradient(135deg, #0d5c56, #14756e);
  border-color: #0d5c56;
  color: #fff;
}
.btn.primary:hover { filter: brightness(1.08); }

.side {
  position: absolute;
  top: 72px;
  right: 12px;
  bottom: 168px;
  width: min(300px, calc(100vw - 24px));
  z-index: 18;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.side > * { pointer-events: auto; }

.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 12px 14px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 8px 24px rgba(26, 43, 42, 0.08);
}

.card h2 {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--teal);
  margin-bottom: 6px;
}
.card .part-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 4px;
}
.card .part-size {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--teal-deep);
  margin-bottom: 6px;
  line-height: 1.4;
  white-space: pre-line;
}
.card .part-size:empty { display: none; }
.card .part-desc {
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
}

.parts-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.parts-list ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.parts-list button {
  width: 100%;
  text-align: left;
  appearance: none;
  border: none;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.parts-list button:hover { background: rgba(13, 92, 86, 0.08); }
.parts-list button.selected {
  background: rgba(196, 92, 38, 0.16);
  color: #8a3a12;
  font-weight: 650;
}

.hint-bar {
  position: absolute;
  left: 12px;
  top: 72px;
  z-index: 15;
  max-width: min(300px, calc(100vw - 340px));
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  font-size: 12px;
  color: var(--muted);
  pointer-events: none;
}

.loading {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #e8efe9;
  transition: opacity 0.4s;
}
.loading.hide { opacity: 0; pointer-events: none; }
.loading span {
  color: var(--teal);
  font-size: 14px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

@media (max-width: 720px) {
  .side {
    top: 68px;
    bottom: unset;
    right: 12px;
    left: auto;
    width: min(260px, 52vw);
  }
  .parts-list { display: none; }
  .hint-bar { display: none; }
  .controls { bottom: 8px; left: 8px; right: 8px; padding: 10px; gap: 8px; }
  .brand h1 { font-size: 13px; }
  .btn { padding: 8px 10px; font-size: 12px; }
  .size-pills button { padding: 6px 7px; font-size: 11px; min-width: 36px; }
}

@media (max-width: 420px) {
  .side { width: calc(100vw - 24px); left: 12px; right: 12px; }
  .card { padding: 8px 10px; }
  .card .part-name { font-size: 16px; margin-bottom: 2px; }
  .card .part-size { font-size: 11px; margin-bottom: 4px; }
  .card .part-desc { font-size: 12px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
  .row .btn.extra { display: none; }
  #btnTop { display: inline-flex; }
}

.label-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 12; display: none; }
.label-layer.on { display: block; }
.leader-svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.leader { fill: none; stroke: rgba(8, 71, 66, 0.7); stroke-width: 1.4; }
.leader-dot { fill: #c45c26; stroke: #f7f4ef; stroke-width: 1; }
.part-label {
  position: absolute; white-space: nowrap;
  font: 600 11px/1.2 var(--font); color: var(--ink);
  background: rgba(247, 244, 239, 0.92); border: 1px solid rgba(13, 92, 86, 0.35);
  padding: 2px 7px; border-radius: 6px;
}
