:root {
  --bg: #fff8eb;
  --ink: #2d1f30;
  --ink-soft: #5f5162;
  --panel: #fffdf8;
  --line: #efd6b0;
  --primary: #ff7a3d;
  --primary-2: #f24f7a;
  --success: #1d976c;
  --danger: #cb2b43;
  --radius: 18px;
  --shadow: 0 14px 28px rgba(59, 36, 28, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Nunito", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 10%, rgba(255, 122, 61, 0.2), transparent 32%),
    radial-gradient(circle at 85% 20%, rgba(242, 79, 122, 0.2), transparent 30%),
    linear-gradient(170deg, #fff8eb 0%, #fff2de 55%, #ffe8cf 100%);
  min-height: 100vh;
  padding: 1.1rem;
}

.bg-shape {
  position: fixed;
  z-index: -1;
  border-radius: 999px;
  filter: blur(2px);
}

.bg-shape-1 {
  width: 240px;
  height: 240px;
  left: -100px;
  top: -80px;
  background: rgba(255, 122, 61, 0.2);
}

.bg-shape-2 {
  width: 300px;
  height: 300px;
  right: -120px;
  bottom: -110px;
  background: rgba(242, 79, 122, 0.15);
}

.topbar {
  width: min(1200px, 96vw);
  margin: 0 auto 1rem;
}

.topbar h1 {
  font-family: "Baloo 2", cursive;
  font-size: clamp(2rem, 5vw, 3.2rem);
  margin: 0;
}

.topbar p {
  margin: 0.2rem 0 0;
  color: var(--ink-soft);
}

.layout {
  width: min(1200px, 96vw);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 1rem;
}

.category-panel,
.game-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.category-panel {
  padding: 1rem;
  max-height: 80vh;
  overflow: auto;
}

.category-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
}

.category-panel h2,
.game-panel h2,
.levels-panel h3 {
  font-family: "Baloo 2", cursive;
  margin: 0;
}

.panel-help {
  margin: 0.15rem 0 0.8rem;
  color: var(--ink-soft);
}

.category-list {
  display: grid;
  gap: 0.6rem;
}

.category-btn {
  border: 1px solid var(--line);
  border-radius: 12px;
  text-align: left;
  padding: 0.7rem;
  background: #fff;
  cursor: pointer;
  font: inherit;
  color: var(--ink);
}

.category-btn.active {
  border-color: #ff9d75;
  background: linear-gradient(130deg, rgba(255, 122, 61, 0.16), rgba(242, 79, 122, 0.16));
}

.category-title {
  display: block;
  font-weight: 800;
  line-height: 1.25;
}

.category-progress {
  display: block;
  margin-top: 0.2rem;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.game-panel {
  padding: 1rem;
  display: grid;
  gap: 1rem;
}

.game-head {
  display: grid;
  gap: 0.35rem;
}

.game-head p {
  margin: 0.3rem 0 0;
  color: var(--ink-soft);
}

.summary-btn {
  justify-self: start;
  padding: 0.5rem 0.85rem;
  background: #e8f6ef;
  color: #1e7a5b;
}

.operation-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem;
  background: linear-gradient(180deg, #fff, #fff8ef);
}

.instruction {
  margin: 0;
  color: var(--ink-soft);
}

.operation-vertical {
  margin: 0.8rem 0 1rem;
  width: min(320px, 100%);
  font-family: "Baloo 2", cursive;
  font-size: clamp(2rem, 5vw, 2.7rem);
  line-height: 1;
  letter-spacing: 0.03em;
}

.vertical-row {
  display: grid;
  grid-template-columns: 30px 1fr;
  justify-items: end;
  align-items: center;
  min-height: 44px;
}

.vertical-row .op-sign {
  justify-self: center;
}

.separator {
  margin-top: 0.2rem;
  border-top: 4px solid #59323a;
  width: 100%;
  height: 0;
}

.horizontal-operation {
  font-family: "Baloo 2", cursive;
  font-size: clamp(2rem, 5vw, 2.7rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.2;
  text-align: center;
  padding: 0.4rem 0;
}

.ghost-btn {
  border: 0;
  border-radius: 10px;
  padding: 0.68rem 1rem;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  color: #4d4e56;
  background: #f3efe7;
}

.choices-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 1.2rem;
}

.choice-btn {
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 0.9rem 0.5rem;
  background: #fff;
  font-family: "Baloo 2", cursive;
  font-size: clamp(1.4rem, 3.5vw, 2rem);
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, border-color 0.15s;
}

.choice-btn:hover {
  background: #fff3e8;
  border-color: var(--primary);
  transform: scale(1.04);
}

.choice-btn:active {
  transform: scale(0.97);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(45, 31, 48, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  background: #fff;
  border-radius: 24px;
  padding: 2.2rem 2rem;
  max-width: 340px;
  width: 90%;
  text-align: center;
  box-shadow: var(--shadow);
}

.modal-icon {
  font-size: 4rem;
  line-height: 1;
  margin-bottom: 0.6rem;
}

.modal-stars {
  display: flex;
  justify-content: center;
  gap: 0.18rem;
  margin-bottom: 0.6rem;
}

.modal-star {
  color: #d8d0c6;
  font-size: 1.7rem;
  line-height: 1;
}

.modal-star.filled {
  color: #ffbf24;
  text-shadow: 0 2px 0 rgba(177, 112, 0, 0.18);
}

.modal-message {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0 0 1.3rem;
  color: var(--ink);
}

.modal-summary {
  display: grid;
  gap: 0.45rem;
  margin: 0 0 1.3rem;
  text-align: left;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  background: #f7f2ea;
  border-radius: 12px;
  padding: 0.55rem 0.75rem;
  color: var(--ink);
  font-weight: 700;
}

.summary-row strong {
  color: var(--ink);
}

.modal-action-btn {
  border: 0;
  border-radius: 12px;
  padding: 0.8rem 1.8rem;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
  transition: opacity 0.15s;
}

.modal-action-btn:hover {
  opacity: 0.9;
}

.modal-secondary-btn {
  border: 1px solid #dfcec0;
  border-radius: 12px;
  padding: 0.7rem 1rem;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  background: #fff4eb;
  color: #875138;
  margin: 0 0 0.75rem;
}

.modal-secondary-btn:hover {
  background: #ffead8;
}

.modal-action-btn.success {
  background: linear-gradient(135deg, #2fb874, #1d976c);
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 0.45rem;
}

.level-btn {
  border: 1px solid #e2c49f;
  border-radius: 8px;
  padding: 0.45rem 0;
  background: #fff8ec;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.level-btn.current {
  border-color: #f24f7a;
  background: #ffe2e8;
}

.level-btn.done {
  border-color: #61ba98;
  background: #e7fff3;
}

.level-btn.locked {
  background: #f4efe8;
  color: #a49787;
  border-color: #ddd2c6;
  cursor: not-allowed;
}

.collapsible-section {
  margin-bottom: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}

.collapsible-header {
  width: 100%;
  border: none;
  background: linear-gradient(135deg, #fffdf8 0%, #fff8ef 100%);
  padding: 0.85rem 1rem;
  text-align: left;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  color: var(--ink);
  font: inherit;
  transition: background 0.2s ease;
}

.collapsible-header:hover {
  background: linear-gradient(135deg, #fff8f0 0%, #fff3e8 100%);
}

.collapsible-header[aria-expanded="false"] {
  border-bottom: none;
}

.collapsible-header[aria-expanded="true"] {
  border-bottom: 1px solid var(--line);
}

.header-title {
  font-size: 1rem;
}

.header-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  font-size: 1.2rem;
  transition: transform 0.3s ease;
}

.collapsible-header[aria-expanded="false"] .header-icon {
  transform: rotate(-180deg);
}

.collapsible-content {
  background: #fff;
  max-height: 1000px;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
  padding: 0.8rem;
}

.collapsible-content[style*="display: none"],
.collapsible-header[aria-expanded="false"] + .collapsible-content {
  max-height: 0;
  padding: 0;
  display: none;
}

@media (max-width: 1020px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .category-panel {
    max-height: none;
  }
}

@media (max-width: 760px) {
  .level-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}
