:root {
  --bg-a: #f2efe4;
  --bg-b: #dfe9ed;
  --card: #fffef9;
  --ink: #20303a;
  --muted: #495a64;
  --line: #c9d4d9;
  --accent: #0f7f74;
  --accent-dark: #0b645c;
  --ok: #17623f;
  --err: #8a2525;
  --choice: #eff5f8;
  --choice-active: #d5ebf6;
  --purple-1: #8c72d1;
  --purple-2: #6949bf;
  --purple-3: #4f338f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "Gill Sans", "Trebuchet MS", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(900px 500px at -5% -10%, #fff7e6 0%, transparent 58%),
    radial-gradient(740px 520px at 104% -12%, #e8f2f8 0%, transparent 60%),
    linear-gradient(180deg, var(--bg-a), var(--bg-b));
}

.vsepr-shell {
  max-width: 1300px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  gap: 14px;
}

.card {
  border: 1px solid #d3d9db;
  border-radius: 14px;
  background: linear-gradient(180deg, #fffefa, var(--card));
  box-shadow: 0 10px 24px rgba(25, 40, 52, 0.14);
}

.topbar {
  padding: 14px;
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
}

h1 {
  margin: 0;
  font-size: 1.42rem;
  letter-spacing: 0.02em;
}

.subtitle {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.94rem;
}

.top-controls {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: end;
  gap: 8px;
  min-width: min(560px, 100%);
}

.top-controls label {
  font-size: 0.85rem;
  color: var(--muted);
}

select,
button {
  font: inherit;
  font-size: 0.93rem;
  border: 1px solid #c4d0d7;
  border-radius: 10px;
  padding: 8px 10px;
  color: var(--ink);
  background: #fff;
}

button {
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: #86a1ac;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(180deg, #0d9083, var(--accent));
  border-color: #0c6860;
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #0c877b, var(--accent-dark));
  border-color: #0a5750;
}

.layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 14px;
}

.control-panel {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.status-block {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: #f8fbfd;
  display: grid;
  gap: 7px;
}

.phase-badge {
  display: inline-block;
  width: fit-content;
  font-weight: 700;
  font-size: 0.85rem;
  color: #195f86;
  background: #dceef8;
  border: 1px solid #b6d5ea;
  border-radius: 999px;
  padding: 2px 9px;
}

h2 {
  margin: 0;
  font-size: 1.08rem;
}

.prompt-text {
  margin: 0;
  font-size: 0.92rem;
  color: #324550;
  line-height: 1.35;
}

.feedback {
  margin: 0;
  font-size: 0.9rem;
  border-radius: 9px;
  border: 1px solid #cae0ef;
  background: #eaf4fb;
  color: #20455e;
  padding: 7px 8px;
  min-height: 32px;
}

.feedback.ok {
  border-color: #badcc7;
  background: #ebf7ef;
  color: var(--ok);
}

.feedback.err {
  border-color: #e5c1c1;
  background: #feeeee;
  color: var(--err);
}

.step-panel {
  display: none;
  border: 1px dashed #cad3d8;
  border-radius: 12px;
  padding: 10px;
  background: #fcfefd;
  gap: 9px;
}

.step-panel.active {
  display: grid;
}

h3 {
  margin: 0;
  font-size: 1rem;
}

.panel-note {
  margin: 0;
  font-size: 0.9rem;
  color: #3a4d58;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.choice-grid.molecular {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.choice-grid.domain {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.choice-btn {
  text-align: left;
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid #c9d5db;
  background: var(--choice);
}

.choice-grid.domain .choice-btn {
  text-align: center;
  padding: 8px 0;
}

.choice-btn.active {
  background: var(--choice-active);
  border-color: #78a1b5;
  color: #1f4458;
}

.token-palette {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.token-btn {
  text-align: left;
  background: #f3eefc;
  border-color: #cabce8;
}

.token-btn.active {
  background: #dfd2f5;
  border-color: #9e87d4;
  color: #3b266f;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.row > * {
  flex: 1;
  min-width: 140px;
}

.credits-box {
  margin-top: auto;
  border: 1px solid #ccd7dd;
  border-radius: 12px;
  padding: 10px;
  background: linear-gradient(180deg, #f8fbfd, #eef4f7);
  color: #37505f;
  font-size: 0.82rem;
  line-height: 1.35;
}

.viewer-panel {
  padding: 10px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 10px;
  min-height: 74vh;
}

.viewer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.94rem;
  color: #314650;
  gap: 10px;
  flex-wrap: wrap;
}

.viewer-stage {
  position: relative;
  border: 2px solid #647887;
  border-radius: 16px;
  overflow: hidden;
  min-height: 560px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(241, 248, 251, 0.86)),
    repeating-linear-gradient(
      135deg,
      rgba(176, 190, 201, 0.14) 0 11px,
      rgba(176, 190, 201, 0.08) 11px 22px
    );
}

#lewisSvg,
#modelCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#modelCanvas {
  display: none;
  touch-action: none;
}

.star-ribbon {
  position: absolute;
  top: 10px;
  right: 10px;
  width: clamp(84px, 14vw, 132px);
  height: auto;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-6px) scale(0.92);
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 4;
}

.star-ribbon.show {
  opacity: 0.98;
  transform: translateY(0) scale(1);
}

.viewer-hint {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.lewis-atom {
  fill: #f7fbfd;
  stroke: #405666;
  stroke-width: 1.6;
}

.lewis-central {
  fill: #f1faf8;
  stroke: #2f5761;
}

.lewis-bond {
  stroke: #263843;
  stroke-width: 2.3;
  stroke-linecap: round;
}

.lewis-label {
  fill: #1f2f3a;
  font-family: "Avenir Next", "Trebuchet MS", sans-serif;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: middle;
}

.lewis-pair-dot {
  fill: #1f2f3a;
}

@media (max-width: 1040px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .viewer-panel {
    min-height: 62vh;
  }

  .viewer-stage {
    min-height: 440px;
  }
}

@media (max-width: 720px) {
  .topbar {
    align-items: start;
    flex-direction: column;
  }

  .top-controls {
    grid-template-columns: 1fr 1fr;
    width: 100%;
    min-width: 0;
  }

  .top-controls label {
    grid-column: 1 / -1;
  }

  #moleculeSelect {
    grid-column: 1 / -1;
  }

  .choice-grid,
  .choice-grid.molecular,
  .token-palette {
    grid-template-columns: 1fr;
  }

  .choice-grid.domain {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .viewer-stage {
    min-height: 360px;
  }
}
