:root {
  --bg: #070b09;
  --bg-2: #0c1310;
  --panel: rgba(16, 26, 21, 0.78);
  --panel-solid: #101a15;
  --line: rgba(57, 255, 136, 0.14);
  --line-strong: rgba(57, 255, 136, 0.35);
  --text: #e3f2e9;
  --muted: #8ea89a;
  --neon: #39ff88;
  --neon-2: #a8ff3e;
  --neon-dim: rgba(57, 255, 136, 0.12);
  --gold: #ffd36b;
  --danger: #ff6b7a;
  --radius: 14px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.bg-glow {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(900px 500px at 10% -10%, rgba(57, 255, 136, 0.13), transparent 60%),
    radial-gradient(700px 500px at 110% 10%, rgba(168, 255, 62, 0.07), transparent 60%),
    radial-gradient(800px 600px at 50% 120%, rgba(40, 140, 255, 0.07), transparent 60%),
    linear-gradient(180deg, var(--bg-2), var(--bg));
}

.wrap { width: 100%; max-width: 980px; margin: 0 auto; padding: 0 16px; }

/* header */
.site-header {
  position: sticky; top: 0; z-index: 10;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  background: rgba(7, 11, 9, 0.72);
  border-bottom: 1px solid var(--line);
}
.header-inner { display: flex; align-items: center; gap: 12px; padding-top: 12px; padding-bottom: 12px; }
.logo { image-rendering: pixelated; filter: drop-shadow(0 0 10px rgba(57, 255, 136, 0.5)); flex: none; }
h1 {
  margin: 0;
  font: 700 clamp(1.15rem, 3.5vw, 1.6rem)/1.15 Cinzel, Georgia, serif;
  letter-spacing: 0.02em;
  background: linear-gradient(90deg, var(--neon), var(--neon-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 0 24px rgba(57, 255, 136, 0.25);
}
.tagline { margin: 2px 0 0; color: var(--muted); font-size: 0.82rem; }

main { padding-top: 20px; padding-bottom: 24px; }

/* panels */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.controls { padding: 16px; }

.field-row { display: grid; grid-template-columns: 1fr 1fr 180px; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 0.75rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.field small { text-transform: none; letter-spacing: 0; font-weight: 500; }

select, input[type="number"] {
  width: 100%; min-width: 0;
  height: 46px;
  padding: 0 12px;
  font: 600 1rem Inter, system-ui, sans-serif;
  color: var(--text);
  background: #0a110d;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
select {
  appearance: none; -webkit-appearance: none; cursor: pointer; padding-right: 36px;
  background-image: linear-gradient(45deg, transparent 50%, var(--neon) 50%), linear-gradient(135deg, var(--neon) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
select option { background: var(--panel-solid); color: var(--text); }
select option:disabled { color: #4b5a52; }
select:focus, input:focus { border-color: var(--neon); box-shadow: 0 0 0 3px var(--neon-dim), 0 0 18px rgba(57, 255, 136, 0.2); }
input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }

.stepper { display: grid; grid-template-columns: 42px 1fr 42px; }
.stepper input { border-radius: 0; text-align: center; border-left: 0; border-right: 0; }
.stepper button {
  height: 46px; border: 1px solid var(--line-strong); background: #0d1812; color: var(--neon);
  font-size: 1.25rem; cursor: pointer; transition: background 0.15s;
}
.stepper button:first-child { border-radius: 10px 0 0 10px; }
.stepper button:last-child { border-radius: 0 10px 10px 0; }
.stepper button:hover { background: #12241a; }

button { font: inherit; touch-action: manipulation; }
button:focus-visible, summary:focus-visible { outline: 2px solid var(--neon); outline-offset: 2px; }

/* prices */
.prices { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 4px; }
.prices summary {
  list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center;
  padding: 10px 2px; font-weight: 600; color: var(--muted); user-select: none;
}
.prices summary::-webkit-details-marker { display: none; }
.prices summary small { font-weight: 400; }
.prices summary:hover { color: var(--text); }
.chev { width: 9px; height: 9px; border-right: 2px solid var(--neon); border-bottom: 2px solid var(--neon); transform: rotate(45deg); transition: transform 0.2s; margin-right: 6px; }
.prices[open] .chev { transform: rotate(-135deg); }

.price-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; padding-top: 4px; }
.price {
  display: grid; grid-template-columns: 36px 1fr; grid-template-rows: auto auto; column-gap: 10px; row-gap: 6px; align-items: center;
  padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: rgba(0, 0, 0, 0.22);
}
.price .mat-icon { grid-row: 1; }
.price-name { font-size: 0.82rem; font-weight: 600; line-height: 1.2; }
.price input { grid-column: 1 / -1; height: 40px; }
.price-actions { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.gem-price { max-width: 280px; flex: 1 1 220px; }
.ghost {
  height: 40px; padding: 0 16px; border-radius: 10px; cursor: pointer;
  background: transparent; color: var(--neon); border: 1px solid var(--line-strong);
}
.ghost:hover { background: var(--neon-dim); }

.mat-icon { image-rendering: pixelated; flex: none; display: block; }

.error { margin: 14px 0 0; padding: 12px 14px; border-radius: 10px; border: 1px solid rgba(255, 107, 122, 0.4); background: rgba(255, 107, 122, 0.08); color: var(--danger); }

/* results */
#results { margin-top: 18px; transition: opacity 0.15s; }
#results.busy { opacity: 0.6; }

.summary { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 12px; }
.stat {
  display: flex; flex-direction: column; justify-content: center; gap: 4px; min-width: 0;
  padding: 16px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line);
}
.stat-label { font-size: 0.72rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.stat-value { display: flex; align-items: center; gap: 8px; font-size: clamp(1.35rem, 4vw, 1.8rem); font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat-sub { color: var(--muted); font-size: 0.82rem; }
.stat-main {
  border-color: var(--line-strong);
  background: linear-gradient(135deg, rgba(57, 255, 136, 0.14), rgba(16, 26, 21, 0.8) 60%);
  box-shadow: 0 0 0 1px rgba(57, 255, 136, 0.08), 0 0 40px rgba(57, 255, 136, 0.1);
}
.stat-main .stat-value { color: var(--gold); font-size: clamp(1.7rem, 6vw, 2.4rem); text-shadow: 0 0 20px rgba(255, 211, 107, 0.25); }
.g { font-size: 0.6em; margin-left: 3px; color: var(--gold); opacity: 0.85; font-weight: 600; }

.gem { flex: none; filter: drop-shadow(0 0 4px var(--gem)); vertical-align: middle; }

.path {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin-top: 14px; padding: 12px; border-radius: var(--radius);
  border: 1px dashed var(--line-strong); background: rgba(0, 0, 0, 0.2);
}
.node {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--c) 10%, transparent); border: 1px solid color-mix(in srgb, var(--c) 45%, transparent);
  font-size: 0.88rem; white-space: nowrap;
}
.node b { font-variant-numeric: tabular-nums; }
.link { display: inline-flex; align-items: center; gap: 8px; }
.arrow { color: var(--muted); font-size: 0.75rem; white-space: nowrap; }

.section-title {
  margin: 26px 0 12px; font: 700 1.05rem Cinzel, Georgia, serif; letter-spacing: 0.04em; color: var(--neon);
  display: flex; align-items: center; gap: 10px;
}
.section-title::after { content: ""; flex: 1; height: 1px; background: linear-gradient(90deg, var(--line-strong), transparent); }

.materials { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.mat {
  display: flex; align-items: center; gap: 12px; padding: 12px; min-width: 0;
  border-radius: 12px; background: var(--panel); border: 1px solid var(--line);
}
.gem-wrap { width: 44px; height: 44px; display: grid; place-items: center; }
.mat-body { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.mat-name { font-size: 0.82rem; color: var(--muted); }
.mat-qty { font-size: 1.2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.mat-gold { color: var(--gold); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.step {
  position: relative; padding: 14px 16px 12px 18px; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--line); overflow: hidden;
}
.step::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--c); box-shadow: 0 0 14px var(--c); }
.step-head { display: flex; align-items: center; gap: 12px; }
.step-num {
  flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  font-size: 0.8rem; font-weight: 700; color: var(--bg); background: var(--c);
}
.step-title { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; font-weight: 700; flex: 1; min-width: 0; }
.step-title > span { display: inline-flex; align-items: center; gap: 5px; }
.step-title .to { color: var(--muted); }
.step-gold { color: var(--gold); font-weight: 700; font-size: 1.1rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.step-meta { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 8px 0 10px; color: var(--muted); font-size: 0.85rem; }
.step-meta b { color: var(--text); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 5px 10px 5px 6px; border-radius: 10px;
  background: rgba(0, 0, 0, 0.25); border: 1px solid var(--line); font-size: 0.86rem;
}
.chip em { font-style: normal; color: var(--gold); font-variant-numeric: tabular-nums; }
.step-foot { margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--line); color: var(--muted); font-size: 0.82rem; text-align: right; }
.step-foot b { color: var(--text); }

.site-footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px; padding-top: 8px; padding-bottom: 28px; color: #5f7468; font-size: 0.78rem; }
.author { color: var(--neon); font-weight: 600; }

/* responsive */
@media (max-width: 760px) {
  .field-row { grid-template-columns: 1fr 1fr; }
  .field.qty { grid-column: 1 / -1; }
  .price-grid { grid-template-columns: repeat(2, 1fr); }
  .summary { grid-template-columns: 1fr 1fr; }
  .stat-main { grid-column: 1 / -1; }
}
@media (max-width: 420px) {
  .controls { padding: 12px; }
  .price-grid { gap: 8px; }
  .price { padding: 8px; }
  .step { padding: 12px 12px 10px 14px; }
  .step-head { flex-wrap: wrap; }
  .step-gold { margin-left: 40px; }
  .chip { width: 100%; }
  .chip em { margin-left: auto; }
  .gem-price { max-width: none; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
