:root {
  --bg: #0d1f3c;
  --bg-2: #13305a;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-border: rgba(255, 255, 255, 0.12);
  --text: #eaf2ff;
  --muted: #9db3d6;
  --accent: #7cc4ff;
  --accent-text: #06213f;
  --flake: #ffffff;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 50% 0%, var(--bg-2), var(--bg) 70%) fixed, var(--bg);
}

.top { max-width: 1200px; margin: 0 auto; padding: 24px 16px 8px; }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }

/* Заметная кнопка «Нарисовать свою» в шапке */
.cta {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px 10px 14px;
  border-radius: 14px;
  border: 1.5px solid var(--accent);
  background: rgba(124, 196, 255, 0.12);
  color: var(--text);
  text-decoration: none;
  transition: background 0.15s, transform 0.15s;
}
.cta:hover { background: rgba(124, 196, 255, 0.24); transform: translateY(-1px); }
.cta:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.cta-icon { font-size: 26px; line-height: 1; }
.cta b { display: block; font-size: 16px; }
.cta small { display: block; color: var(--muted); font-size: 12px; }

.linklike {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  font: inherit;
}
.linklike:hover { background: none; color: #a3d6ff; }

/* Знакомство: что тут можно */
.intro {
  max-width: 1200px;
  margin: 8px auto 0;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.intro[hidden] { display: none; }
.intro-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.intro-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 14px;
  color: var(--text);
}
.intro-card h3 { margin: 6px 0 4px; font-size: 15px; }
.intro-card p { margin: 0; color: var(--muted); font-size: 13px; }
.intro-icon { font-size: 24px; }
.intro-card-link { text-decoration: none; border-color: var(--accent); background: rgba(124, 196, 255, 0.1); transition: background 0.15s; }
.intro-card-link:hover { background: rgba(124, 196, 255, 0.2); }
.intro-close { align-self: flex-end; }

@media (max-width: 860px) {
  .intro-cards { grid-template-columns: 1fr 1fr; }
  .cta { width: 100%; justify-content: center; }
}
.top h1 { margin: 0; font-size: 28px; letter-spacing: 0.5px; }
.top p { margin: 4px 0 0; color: var(--muted); }

.layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 20px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-self: start;
}

button, input[type=number] {
  font: inherit;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 8px 12px;
}
button { cursor: pointer; transition: background 0.15s; }
button:hover { background: rgba(255, 255, 255, 0.16); }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

button.primary {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  font-weight: 600;
  font-size: 17px;
  padding: 12px;
}
button.primary:hover { background: #a3d6ff; }

.segmented {
  display: flex;
  margin: 0;
  padding: 3px;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.15);
}
.segmented label { flex: 1; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block;
  text-align: center;
  padding: 6px 4px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
}
.segmented input:checked + span { background: rgba(255, 255, 255, 0.16); color: var(--text); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { display: flex; justify-content: space-between; color: var(--muted); }
.field output { color: var(--text); font-variant-numeric: tabular-nums; }
.field small { color: var(--muted); font-size: 12px; }
.row { display: flex; gap: 6px; }
.row input { flex: 1; min-width: 0; }
input[type=range] { width: 100%; accent-color: var(--accent); }

.check { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.check input { accent-color: var(--accent); width: 18px; height: 18px; }
.check[hidden] { display: none; }

.exports { display: flex; flex-direction: column; gap: 8px; }

.stats { margin: 0; color: var(--text); font-size: 13px; }
.muted { color: var(--muted); }

.stage {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  min-height: 560px;
  overflow: hidden;
}
.view { position: absolute; inset: 0; width: 100%; height: 100%; }
#view2d { padding: 48px 24px 24px; color: var(--flake); filter: drop-shadow(0 0 10px rgba(160, 210, 255, 0.35)); }
#view3d canvas { display: block; width: 100%; height: 100%; }
.view[hidden] { display: none; }

/* пока фоновый поток считает — старая снежинка слегка тускнеет, появляется индикатор */
#view2d { transition: opacity 0.2s; }
.stage.busy #view2d { opacity: 0.55; }
.stage::after {
  content: "";
  position: absolute;
  top: 18px;
  left: 18px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  border-right-color: transparent;
  opacity: 0;
  transition: opacity 0.2s;
  animation: spin 0.8s linear infinite;
}
.stage.busy::after { opacity: 1; transition-delay: 0.15s; }
@keyframes spin { to { transform: rotate(360deg); } }

.thumb.loading { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { background: rgba(255, 255, 255, 0.14); } }

@media (prefers-reduced-motion: reduce) {
  .stage::after, .thumb.loading { animation: none; }
}

.view-switch { position: absolute; top: 12px; right: 12px; z-index: 2; width: 120px; background: rgba(13, 31, 60, 0.7); }

.error { position: absolute; bottom: 12px; left: 12px; right: 12px; margin: 0; padding: 10px; border-radius: 10px; background: #5a1d2a; }

.variants, .tips { max-width: 1200px; margin: 0 auto; padding: 8px 16px 16px; }
.variants-head { display: flex; align-items: center; justify-content: space-between; }
h2 { font-size: 18px; margin: 12px 0; }
.thumbs { display: grid; grid-template-columns: repeat(8, 1fr); gap: 10px; }
.thumb { aspect-ratio: 1; padding: 8px; color: var(--flake); }
.thumb svg { width: 100%; height: 100%; display: block; }

.tips ul { margin: 0; padding-left: 20px; color: var(--muted); }
.tips li { margin-bottom: 6px; }
.tips b { color: var(--text); }

/* ---------- редактор своей снежинки ---------- */

.top a { color: var(--accent); }

.ed-layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 20px;
}
.ed-wedge {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.toolbar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.toolbar .tools { width: 230px; }
.toolbar button:disabled { opacity: 0.4; cursor: default; }
.wedge-svg {
  width: 100%;
  height: min(72vh, 760px);
  touch-action: none; /* пальцем рисуем, а не прокручиваем страницу */
  user-select: none;
  cursor: crosshair;
}
.wedge-svg[data-tool="select"] { cursor: default; }
.hint { margin: 0; color: var(--muted); font-size: 13px; }
.toast { margin: 0; padding: 8px 12px; border-radius: 10px; background: rgba(124, 196, 255, 0.18); border: 1px solid var(--accent); font-size: 14px; }
.toast[hidden] { display: none; }

.wedge-svg .sheet { fill: #eef4ff; }
.wedge-svg .fold { fill: none; stroke: #5d7aa8; stroke-width: 1.5; stroke-dasharray: 6 4; vector-effect: non-scaling-stroke; pointer-events: none; }
.wedge-svg .lbl { fill: #5d7aa8; font-size: 4px; pointer-events: none; }
.wedge-svg .cut-out { fill: rgba(124, 196, 255, 0.10); stroke: var(--accent); stroke-width: 1; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
.wedge-svg .cut-in { fill: var(--bg); stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.wedge-svg[data-tool="select"] .cut-in, .wedge-svg[data-tool="select"] .cut-out { cursor: move; }
.wedge-svg .sel { stroke: #ffd166; stroke-width: 2.5; }
.wedge-svg .vh { fill: #fff; stroke: #e0a400; stroke-width: 2; vector-effect: non-scaling-stroke; cursor: grab; }
.wedge-svg .mh { fill: #fff; stroke: #e0a400; stroke-width: 1.5; vector-effect: non-scaling-stroke; opacity: 0.85; cursor: grab; }
.wedge-svg .mh.curved { fill: #ffd166; }
.wedge-svg .ghost { fill: rgba(255, 209, 102, 0.25); stroke: #ffd166; stroke-width: 1.5; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; pointer-events: none; }
.wedge-svg[data-tool="shape"] { cursor: copy; }
.tb-label { color: var(--muted); font-size: 13px; }
.tb-sep { width: 1px; align-self: stretch; background: var(--panel-border); margin: 0 4px; }
.toolbar button { min-width: 38px; }
.shape-btn.active { background: var(--accent); color: var(--accent-text); }
.wedge-svg .drawing { fill: none; stroke: #ffd166; stroke-width: 2; vector-effect: non-scaling-stroke; pointer-events: none; }
.wedge-svg .drawing.closing { stroke-dasharray: 4 4; opacity: 0.6; }
.wedge-svg .dp { fill: #ffd166; pointer-events: none; }
.wedge-svg .dp.first { fill: #fff; stroke: #ffd166; stroke-width: 2; vector-effect: non-scaling-stroke; }
.wedge-svg .dp.hot { fill: #ffd166; }

.ed-side { display: flex; flex-direction: column; gap: 16px; }
.ed-side .panel { align-self: stretch; }
.ed-preview {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  aspect-ratio: 1;
  padding: 12px;
}
.ed-preview svg { width: 100%; height: 100%; display: block; }
.ed-preview .flake { fill: var(--flake); }
.ed-preview .dropped { fill: #ff6b6b; }
.ed-preview .thin { fill: #ff9f1c; }
.wedge-svg .thin { fill: #ff9f1c; opacity: 0.85; pointer-events: none; }
.warn { position: absolute; left: 10px; right: 10px; bottom: 10px; margin: 0; padding: 8px 10px; border-radius: 10px; background: rgba(90, 29, 42, 0.92); font-size: 13px; }

@media (max-width: 860px) {
  .ed-layout { grid-template-columns: 1fr; }
  .wedge-svg { height: 60vh; }
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .stage { order: -1; min-height: 0; aspect-ratio: 1; }
  .thumbs { grid-template-columns: repeat(4, 1fr); }
  #view2d { padding: 44px 12px 12px; }
}
