/* Sum Factory — kid-friendly UI. Rounded, warm, big hit targets, ≥16px text. */

:root {
  --wood: #8a623c;
  --wood-dark: #6b4a2c;
  --cream: #fff3d0;
  --cream-dim: #e8d9ae;
  --ink: #3c2e18;
  --green: #5cb860;
  --green-dark: #3f8f45;
  --amber: #e8a33c;
  --red: #d9534f;
  --panel: #fdf6e3;
  --shadow: 0 6px 0 rgba(0, 0, 0, 0.18);
  --font: 'Arial Rounded MT Bold', 'Trebuchet MS', 'Comic Sans MS', 'Segoe UI', sans-serif;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  font-size: 16px;
  background: #4e7a33;
  -webkit-user-select: none;
  user-select: none;
}

button { font-family: var(--font); cursor: pointer; }

/* ---------- top bar ---------- */

#topbar {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 56px;
  padding: 0 14px;
  background: linear-gradient(#9a6f44, #85603a);
  border-bottom: 4px solid var(--wood-dark);
  color: var(--cream);
}

.brand { font-size: 20px; font-weight: 800; text-shadow: 0 2px 0 rgba(0,0,0,0.25); margin-right: 6px; }

.stat {
  background: rgba(0, 0, 0, 0.22);
  border-radius: 14px;
  padding: 6px 14px;
  font-size: 17px;
  font-weight: 800;
  white-space: nowrap;
}

.stat.coin { transition: transform 0.12s; }
.stat.coin.bump { animation: bump 0.3s; }
@keyframes bump {
  30% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

.contract-mini { font-size: 15px; background: rgba(30, 80, 30, 0.4); }

.spacer { flex: 1; }

#saveDot {
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.4s;
}
#saveDot.show { animation: savedFlash 2s forwards; }
@keyframes savedFlash {
  0% { opacity: 0; }
  15% { opacity: 0.9; }
  70% { opacity: 0.9; }
  100% { opacity: 0; }
}

.icon-btn {
  font-size: 20px;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 3px solid var(--wood-dark);
  background: var(--cream);
}
.icon-btn:active { transform: translateY(2px); }

/* ---------- layout ---------- */

#gameWrap {
  position: relative;
  height: calc(100% - 56px);
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}
#game.demolishing { cursor: not-allowed; }

/* ---------- tutorial hint ---------- */

#tutorialHint {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(560px, 86vw);
  background: var(--panel);
  color: var(--ink);
  border: 4px solid var(--amber);
  border-radius: 16px;
  padding: 10px 18px;
  font-size: 17px;
  font-weight: 700;
  box-shadow: var(--shadow);
  z-index: 10;
  animation: hintPop 0.35s;
}
@keyframes hintPop {
  from { transform: translateX(-50%) scale(0.85); opacity: 0; }
  to { transform: translateX(-50%) scale(1); opacity: 1; }
}

/* ---------- side panel ---------- */

#sidePanel {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 270px;
  background: var(--panel);
  border: 4px solid var(--wood-dark);
  border-radius: 18px;
  padding: 12px;
  color: var(--ink);
  box-shadow: var(--shadow);
  z-index: 10;
  transition: transform 0.25s;
}
#sidePanel.collapsed { transform: translateX(calc(100% - 44px)); }
#sidePanel.collapsed .panel-head,
#sidePanel.collapsed #panelBody { visibility: hidden; }

#panelToggle {
  position: absolute;
  top: -4px;
  left: -4px;
  width: 40px;
  height: 40px;
  border-radius: 14px;
  border: 3px solid var(--wood-dark);
  background: var(--cream);
  font-size: 17px;
  z-index: 2;
}

.panel-head {
  text-align: center;
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 8px;
}

.panel-title { font-size: 18px; font-weight: 800; margin: 6px 0 4px; }
.panel-sub { font-weight: 800; margin: 6px 0 2px; }
.panel-story { font-size: 15px; margin-bottom: 8px; line-height: 1.35; }
.panel-note { font-size: 15px; margin: 8px 0; }
.panel-sep { border-top: 3px dashed var(--cream-dim); margin: 10px 0; }
.blocked-note { background: #fbe9d0; border-radius: 10px; padding: 8px; }
.bonus-tag { color: var(--green-dark); font-weight: 800; }

.need-list { display: flex; flex-direction: column; gap: 8px; margin: 6px 0; }
.need-row { display: flex; align-items: center; gap: 10px; }
.need-icon { width: 34px; height: 34px; image-rendering: pixelated; }
.need-info { flex: 1; }
.need-label { font-size: 15px; }
.need-bar {
  height: 12px;
  background: var(--cream-dim);
  border-radius: 8px;
  overflow: hidden;
  margin-top: 3px;
}
.need-fill {
  height: 100%;
  background: linear-gradient(#7ede83, var(--green));
  border-radius: 8px;
  transition: width 0.3s;
}

/* ---------- toolbar ---------- */

#toolbar {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: linear-gradient(#9a6f44, #85603a);
  border: 4px solid var(--wood-dark);
  border-radius: 20px;
  box-shadow: var(--shadow);
  z-index: 10;
  max-width: 96vw;
  overflow-x: auto;
}

#palette { display: flex; gap: 8px; }

.tool-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 76px;
  padding: 6px 4px 5px;
  border: 3px solid var(--wood-dark);
  border-radius: 14px;
  background: var(--cream);
  color: var(--ink);
  transition: transform 0.1s;
}
.tool-btn:hover { transform: translateY(-3px); }
.tool-btn.selected {
  background: #ffe9a8;
  border-color: var(--amber);
  box-shadow: 0 0 0 3px var(--amber);
}
.tool-btn.locked { filter: saturate(0.4) brightness(0.9); }
.tool-btn.poor .tool-cost { color: var(--red); }

.tool-icon { width: 40px; height: 40px; image-rendering: pixelated; }
.tool-name { font-size: 13px; font-weight: 800; }
.tool-cost { font-size: 13px; font-weight: 800; color: var(--green-dark); }
.tool-key {
  position: absolute;
  top: 3px;
  left: 5px;
  font-size: 11px;
  font-weight: 800;
  opacity: 0.55;
}
.tool-lock { position: absolute; top: 2px; right: 4px; font-size: 15px; }

.tool-extras { display: flex; gap: 8px; }
.extra-btn {
  width: 52px;
  height: 62px;
  border: 3px solid var(--wood-dark);
  border-radius: 14px;
  background: var(--cream);
  font-size: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--ink);
}
.extra-btn small { font-size: 11px; font-weight: 800; opacity: 0.55; }
.extra-btn.selected { background: #ffd0c4; border-color: var(--red); box-shadow: 0 0 0 3px var(--red); }

/* ---------- toast ---------- */

#toast {
  position: absolute;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%) translateY(16px);
  max-width: min(520px, 88vw);
  background: rgba(40, 30, 12, 0.92);
  color: var(--cream);
  font-size: 16px;
  font-weight: 700;
  border-radius: 14px;
  padding: 11px 18px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 15;
  text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- modals ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 22, 8, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  opacity: 0;
  transition: opacity 0.18s;
  padding: 16px;
}
.overlay.open { opacity: 1; }

.modal {
  background: var(--panel);
  color: var(--ink);
  border: 5px solid var(--wood-dark);
  border-radius: 22px;
  padding: 22px 26px;
  width: min(520px, 94vw);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 12px 0 rgba(0, 0, 0, 0.25);
  transform: scale(0.9);
  transition: transform 0.18s;
  text-align: center;
}
.overlay.open .modal { transform: scale(1); }

.modal h2 { font-size: 24px; margin-bottom: 8px; }
.modal-icon { font-size: 46px; margin-bottom: 4px; }
.modal-body { font-size: 17px; line-height: 1.45; margin: 8px 0 14px; }
.modal-sub { font-size: 15px; opacity: 0.8; margin-bottom: 10px; }

.btn-row { display: flex; gap: 12px; justify-content: center; margin-top: 12px; }
.menu-col { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }

.big-btn {
  font-size: 18px;
  font-weight: 800;
  padding: 12px 22px;
  border-radius: 16px;
  border: 3px solid var(--wood-dark);
  background: var(--cream);
  color: var(--ink);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.2);
  transition: transform 0.08s;
}
.big-btn:hover { transform: translateY(-2px); }
.big-btn:active { transform: translateY(2px); box-shadow: none; }
.big-btn.go { background: linear-gradient(#7ede83, var(--green)); border-color: var(--green-dark); color: #163e18; }
.big-btn.ghost { background: var(--cream); }
.big-btn:disabled { opacity: 0.55; cursor: default; }

/* question modal */

.exam-header { font-size: 15px; font-weight: 800; opacity: 0.8; margin-bottom: 6px; }
.dots { margin-left: 8px; }
.dot {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--cream-dim);
  margin: 0 2px;
  border: 2px solid var(--wood-dark);
}
.dot.done { background: var(--green); }
.dot.now { background: var(--amber); }

.q-prompt {
  font-size: 21px;
  font-weight: 800;
  line-height: 1.4;
  margin: 12px 0 16px;
}

.numeric-wrap { display: flex; gap: 10px; justify-content: center; }
.numeric-input {
  font-family: var(--font);
  font-size: 22px;
  font-weight: 800;
  width: 180px;
  padding: 10px 14px;
  border: 4px solid var(--wood);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  text-align: center;
  -webkit-user-select: text;
  user-select: text;
}
.numeric-input:focus { outline: none; border-color: var(--amber); }

.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.choice-btn {
  font-size: 20px;
  font-weight: 800;
  padding: 16px 8px;
  border-radius: 16px;
  border: 3px solid var(--wood-dark);
  background: #fff;
  color: var(--ink);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.15);
}
.choice-btn:hover:not(:disabled) { background: #ffe9a8; transform: translateY(-2px); }
.choice-btn:disabled { opacity: 0.75; cursor: default; }
.choice-btn.picked-good { background: #c9f3cb; border-color: var(--green-dark); box-shadow: 0 0 0 3px var(--green); opacity: 1; }
.choice-btn.picked-bad { background: #ffd9d0; border-color: var(--red); box-shadow: 0 0 0 3px var(--red); opacity: 1; }

.q-hint {
  margin-top: 12px;
  background: #dceefb;
  border: 3px solid #7db3d8;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 16px;
}

.q-feedback {
  margin-top: 14px;
  border-radius: 14px;
  padding: 12px 16px;
  font-size: 17px;
  text-align: left;
  animation: hintPop2 0.25s;
}
@keyframes hintPop2 {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.q-feedback.good { background: #c9f3cb; border: 3px solid var(--green-dark); }
.q-feedback.try { background: #ffe9c2; border: 3px solid var(--amber); }
.fb-head { font-weight: 800; font-size: 18px; margin-bottom: 4px; }
.fb-expl { line-height: 1.45; }

.q-actions { display: flex; gap: 10px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.hint-btn {
  font-size: 15px;
  font-weight: 700;
  padding: 9px 14px;
  border-radius: 12px;
  border: 3px dashed #7db3d8;
  background: #eef7fd;
  color: #2a5876;
}

/* celebration */

.celebrate-name { font-size: 19px; font-weight: 800; margin: 4px 0; }
.celebrate-stars { font-size: 42px; color: var(--amber); letter-spacing: 6px; margin: 6px 0; animation: starPop 0.5s; }
.celebrate-stars .dim { color: var(--cream-dim); }
@keyframes starPop {
  0% { transform: scale(0.3); }
  70% { transform: scale(1.15); }
  100% { transform: scale(1); }
}
.celebrate-pay { font-size: 24px; font-weight: 800; color: var(--green-dark); margin-bottom: 12px; }

/* splitter modal */

.preset-grid { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.preset-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 26px;
  font-size: 22px;
  font-weight: 800;
  border-radius: 14px;
  border: 3px solid var(--wood-dark);
  background: #fff;
  color: var(--ink);
}
.preset-btn .arrows { font-size: 16px; opacity: 0.6; }
.preset-btn.selected { background: #ffe9a8; border-color: var(--amber); box-shadow: 0 0 0 3px var(--amber); }
.split-counts { font-size: 15px; opacity: 0.8; margin-bottom: 8px; }

/* small screens */

@media (max-width: 720px) {
  #sidePanel { width: 230px; }
  .tool-btn { width: 64px; }
  .brand { display: none; }
}
