:root {
  --navy: #2c3e50;
  --teal: #1abc9c;
  --gold: #f1c40f;
  --slate: #7f8c8d;
  --coral: #e74c3c;
  --white: #ffffff;
  --gray-100: #f7fafc;
  --gray-200: #edf2f7;
  --gray-300: #e2e8f0;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Montserrat", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
  color: var(--navy);
  background: linear-gradient(135deg, #ecf0f1 0%, #d6dbdf 100%);
  min-height: 100vh;
  padding-bottom: 80px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
  -webkit-user-select: none;
}

/* ── Header ── */
.page-header { padding: 1rem; }

.header-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
}

.header-left  { justify-self: start; }
.header-right { justify-self: end; }

.page-title {
  margin: 0;
  justify-self: center;
  font-size: clamp(1.25rem, 3vw, 2rem);
  font-weight: 700;
  font-family: 'Montserrat', sans-serif;
  text-align: center;
  color: var(--navy);
}

/* ── Buttons ── */
.btn {
  display: inline-block;
  padding: 12px 24px;
  border: none;
  border-radius: 6px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.2s;
  text-align: center;
  white-space: nowrap;
}
.btn:hover  { opacity: 0.85; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.teal-btn   { background: var(--teal); color: white; }
.navy-btn   { background: var(--navy); color: white; }
.gold-btn   { background: var(--gold); color: var(--navy); }
.coral-btn  { background: var(--coral); color: white; }
.ghost-btn  {
  background: transparent;
  color: var(--slate);
  border: 1.5px solid var(--gray-300);
  font-size: 14px;
  padding: 7px 14px;
}
.ghost-btn:hover { border-color: var(--slate); background: var(--gray-100); opacity: 1; }

/* ── Score chip (header right) ── */
.score-chip {
  font-size: 16px;
  font-weight: 700;
  color: var(--navy);
  background: white;
  border-radius: 20px;
  padding: 8px 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.09);
  white-space: nowrap;
}

/* ── Instruction banner ── */
.instruction-banner {
  max-width: 1000px;
  margin: 0 auto 0;
  padding: 0 16px;
}

.instruction-banner .section-card {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 14px 20px;
  border-left: 4px solid var(--teal);
}

.instruction-icon {
  font-size: 1.1rem;
  flex-shrink: 0;
}

.instruction-text {
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--navy);
}

.instruction-text strong {
  font-weight: 700;
}

/* ── Layout ── */
main {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.section-card {
  background: white;
  border-radius: 12px;
  padding: 22px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.section-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--slate);
  margin-bottom: 16px;
}

/* ── Scenario card ── */
.scenario-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 8px;
  flex-wrap: wrap;
}

.scenario-progress {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--slate);
}

.scenario-text {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--navy);
  line-height: 1.4;
  margin-bottom: 14px;
}

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

.hint-toggle {
  font-size: 13px;
  font-weight: 600;
  background: none;
  border: 1.5px solid var(--gray-300);
  border-radius: 5px;
  color: var(--slate);
  cursor: pointer;
  padding: 5px 12px;
  font-family: inherit;
  transition: border-color 0.2s, background 0.2s;
}
.hint-toggle:hover { border-color: var(--gold); background: rgba(241,196,15,0.08); }

.hint-text {
  font-size: 13px;
  color: var(--slate);
  font-style: italic;
  line-height: 1.5;
  display: none;
  margin-top: 12px;
  padding: 10px 14px;
  background: var(--gray-100);
  border-radius: 6px;
  border-left: 3px solid var(--gold);
}
.hint-text.visible { display: block; }

/* ── Results screen ── */
#results-screen {
  display: none;
  text-align: center;
  padding: 20px;
}
.results-score {
  font-size: 2.8rem;
  font-weight: 700;
  color: var(--teal);
  margin: 12px 0 4px;
}
.results-label {
  font-size: 0.9rem;
  color: var(--slate);
  font-weight: 600;
  margin-bottom: 20px;
}
.results-msg {
  font-size: 1rem;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 24px;
  line-height: 1.5;
}

/* ── Reservoir ── */
#reservoir {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  min-height: 52px;
}

/* ── Store tiles ── */
.store-tile {
  padding: 11px 16px;
  background: var(--navy);
  color: white;
  border-radius: 6px;
  font-size: 15px;
  font-weight: 600;
  cursor: grab;
  touch-action: none;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  transition: box-shadow 0.15s, transform 0.15s, opacity 0.15s;
}
.store-tile:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.2); transform: translateY(-1px); }
.store-tile.is-source { opacity: 0.3; cursor: grabbing; }
.store-tile.long-press-active { outline: 2.5px solid var(--gold); }

.drag-clone {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.9;
  transform: scale(1.06) translateY(-2px);
  box-shadow: 0 10px 28px rgba(0,0,0,0.25);
  cursor: grabbing;
}

/* ── Constructor ── */
.constructor-layout {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 18px;
  align-items: stretch;
}

.drop-zone {
  min-height: 72px;
  border: 2.5px dashed var(--gray-300);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--slate);
  transition: border-color 0.2s, background 0.2s;
  padding: 14px;
  text-align: center;
}
.drop-zone.filled {
  border-style: solid;
  border-color: var(--teal);
  background: rgba(26,188,156,0.07);
}
.drop-zone.drag-over {
  border-color: var(--gold);
  background: rgba(241,196,15,0.12);
}
.drop-zone .store-tile { width: 100%; text-align: center; cursor: grab; }

/* ── Wrong-answer flash on drop zones ── */
.drop-zone.wrong {
  border-style: solid;
  border-color: var(--coral);
  background: rgba(231,76,60,0.1);
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-6px); }
  40%      { transform: translateX(6px); }
  60%      { transform: translateX(-4px); }
  80%      { transform: translateX(4px); }
}

/* ── Transfer buttons ── */
.transfer-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  justify-content: center;
}

.transfer-btn {
  padding: 11px 18px;
  border: 2.5px solid var(--gray-300);
  border-radius: 6px;
  background: white;
  color: var(--navy);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
  white-space: nowrap;
  text-align: center;
}
.transfer-btn:hover:not(.selected) {
  border-color: var(--slate);
  background: var(--gray-100);
}
.transfer-btn.selected {
  border-color: var(--teal);
  background: rgba(26,188,156,0.1);
  color: var(--teal);
}
.transfer-btn.wrong {
  border-color: var(--coral);
  background: rgba(231,76,60,0.1);
  color: var(--coral);
  animation: shake 0.4s ease;
}

/* ── Feedback bars ── */
.bars-row {
  display: grid;
  grid-template-columns: 1fr 40px 1fr;
  gap: 16px;
  align-items: center;
  margin-bottom: 14px;
}

.bar-group { display: flex; flex-direction: column; gap: 6px; }

.bar-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--slate);
}

.bar-track {
  height: 30px;
  background: var(--gray-200);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}

.bar-fill {
  height: 100%;
  background: var(--teal);
  border-radius: 6px;
  transition: width 0.75s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

/* input bar draining turns coral */
.bar-fill.draining { background: var(--coral); }
/* output bar filling turns teal (already default) */

.bar-value {
  font-size: 13px;
  font-weight: 700;
  color: var(--navy);
  text-align: center;
}

.arrow-col {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 18px;
  font-size: 22px;
  color: var(--gray-300);
  transition: color 0.4s;
}
.arrow-col.active { color: var(--teal); }

@keyframes pulse-slide {
  0%   { left: -14px; opacity: 1; }
  100% { left: 110%;  opacity: 0; }
}
.pulse-dot {
  position: absolute;
  top: 0;
  width: 14px;
  height: 100%;
  background: rgba(255,255,255,0.55);
  border-radius: 4px;
  animation: pulse-slide 0.65s ease-out forwards;
}

/* ── Message ── */
#message {
  min-height: 36px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 6px;
  margin-bottom: 14px;
}
#message.valid   { background: rgba(26,188,156,0.12); color: #16a085; }
#message.invalid { background: rgba(231,76,60,0.1);   color: var(--coral); }
#message:empty   { background: transparent; }

/* ── Locked overlay (prevents interaction during animation) ── */
.locked-overlay {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 10;
  border-radius: 12px;
}
.section-card { position: relative; }
.section-card.locked .locked-overlay { display: block; }

/* ── Responsive ── */
@media (max-width: 767px) {
  .header-grid {
    grid-template-columns: 1fr;
    grid-auto-flow: row;
    text-align: left;
  }
  .page-title   { justify-self: start; }
  .header-right { justify-self: start; margin-top: 4px; }
}

@media (max-width: 600px) {
  .constructor-layout {
    grid-template-columns: 1fr;
  }
  .transfer-buttons {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }
  .bars-row {
    grid-template-columns: 1fr 24px 1fr;
    gap: 8px;
  }
  .btn        { font-size: 14px; padding: 10px 18px; }
  .score-chip { font-size: 13px; padding: 6px 12px; }
}
