:root {
  --bg:        #EDEAE2;
  --surface:   #FFFFFF;
  --surface-2: #E0DDD5;
  --border:    rgba(0,0,0,0.18);
  --border-md: rgba(0,0,0,0.28);
  --text-1:    #111110;
  --text-2:    #333331;
  --text-3:    #777774;
  --accent:    #1A5FAF;
  --accent-bg: #C8E0FF;
  --success:   #145C3E;
  --success-bg:#B8EDD6;
  --warn:      #7A4500;
  --warn-bg:   #FFD88A;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --font:      'Nunito', sans-serif;
  --ease:      0.18s ease;
}

html[data-theme="dark"] {
  --bg:        #1A1917;
  --surface:   #2A2825;
  --surface-2: #353330;
  --border:    rgba(255,255,255,0.14);
  --border-md: rgba(255,255,255,0.24);
  --text-1:    #F5F2EC;
  --text-2:    #C8C5BE;
  --text-3:    #888880;
  --accent:    #6AABFF;
  --accent-bg: rgba(26,95,175,0.30);
  --success:   #4DCCA0;
  --success-bg:rgba(20,92,62,0.30);
  --warn:      #FFB84D;
  --warn-bg:   rgba(122,69,0,0.30);
}

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

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-1);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background var(--ease), color var(--ease);
}

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

/* ШАПКА */
#appHeader {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

#appHeaderInner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  padding: 14px 16px;
}

#appLogo {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-1);
}

#themeMenuWrapper { position: relative; }

#themeToggle {
  background: var(--surface-2);
  border: 1px solid var(--border-md);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 15px;
  color: var(--text-1);
  font-weight: 600;
}

#themeDropdown {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--surface);
  border: 1px solid var(--border-md);
  border-radius: var(--radius-md);
  flex-direction: column;
  min-width: 150px;
  z-index: 200;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  overflow: hidden;
}

#themeDropdown.open { display: flex; }

#themeDropdown button {
  background: none;
  border: none;
  padding: 12px 18px;
  text-align: left;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-1) !important;
  opacity: 1 !important;
}

#themeDropdown button:hover { background: var(--surface-2); }

/* ОСНОВНОЙ КОНТЕЙНЕР */
#appMain {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  padding: 24px 16px;
}

#appMain > section {
  width: 100%;
}

/* КАРТА УРОВНЕЙ */
#screenMap .map-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 12px;
}

#screenMap .col-labels {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}

#screenMap .col-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-3);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

#screenMap .map-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.map-cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  height: 100px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  text-align: center;
  cursor: pointer;
  user-select: none;
  transition: background var(--ease), border-color var(--ease), transform var(--ease);
}

.map-cell:hover {
  background: var(--surface-2);
  transform: translateY(-1px);
}

.map-cell.locked {
  opacity: 0.28;
  cursor: default;
  pointer-events: none;
}

.map-cell.active {
  border-color: var(--accent);
  background: var(--accent-bg);
}

.map-cell.completed {
  border-color: var(--success);
  background: var(--success-bg);
}

.map-cell .cell-id {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-1);
}

.map-cell .cell-sub {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
}

/* ЭКРАН ЗАДАЧИ */
#screenTask .task-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.nav-btn {
  background: none;
  border: none;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-2);
  padding: 4px 0;
}

.nav-btn:hover { color: var(--text-1); }

.task-progress {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
}

.task-theme {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

.task-question {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-1);
  line-height: 1.4;
  margin-bottom: 28px;
}

.cards-source {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 24px;
}

.card {
  flex: 1;
  min-width: 60px;
  background: var(--surface);
  border: 1px solid var(--border-md);
  border-radius: var(--radius-md);
  padding: 16px 6px;
  text-align: center;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-1);
  cursor: pointer;
  user-select: none;
  word-break: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
  line-height: 1.3;
  transition: background var(--ease), transform var(--ease);
}

.card:hover { background: var(--surface-2); }

.card.selected {
  border: 2px solid var(--accent);
  background: var(--accent-bg);
  transform: translateY(-2px);
}

.card.placed {
  opacity: 0.25;
  cursor: default;
  pointer-events: none;
}

@keyframes shake {
  0%,100% { transform: translateX(0); }
  25%      { transform: translateX(-5px); }
  75%      { transform: translateX(5px); }
}

.card.conflict { animation: shake 0.35s ease; }

.zones-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 24px;
}

.zone {
  background: var(--surface);
  border: 1px dashed var(--border-md);
  border-radius: var(--radius-md);
  padding: 12px;
  min-height: 66px;
  cursor: pointer;
  transition: background var(--ease), border-color var(--ease);
}

.zone:hover {
  background: var(--surface-2);
  border-color: var(--accent);
}

.zone.correct {
  border-style: solid;
  border-color: var(--success);
  background: var(--success-bg);
}

.zone-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.zone-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 32px;
  align-items: center;
}

.zone-card {
  background: var(--surface-2);
  border: 1px solid var(--border-md);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-1);
  cursor: pointer;
}

.zone-card:hover { background: var(--warn-bg); border-color: var(--warn); }

.zone-empty-hint {
  font-size: 12px;
  color: var(--text-3);
}

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

.footer-btn {
  flex: 1;
  padding: 13px;
  font-size: 14px;
  font-weight: 700;
  border: 1px solid var(--border-md);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text-2);
  transition: background var(--ease);
}

.footer-btn:hover { background: var(--surface-2); color: var(--text-1); }

.footer-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.footer-btn.primary:hover { opacity: 0.88; }

.report-btn {
  flex-shrink: 0;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  font-size: 15px;
  color: var(--text-3);
}

.report-btn:hover { color: var(--warn); border-color: var(--warn); }

/* ОВЕРЛЕИ */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.40);
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 20px;
}

.overlay.open { display: flex; }

.overlay-box {
  background: var(--surface);
  border: 1px solid var(--border-md);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 100%;
  max-width: 360px;
}

.overlay-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-1);
  margin-bottom: 12px;
}

.overlay-text {
  font-size: 15px;
  color: var(--text-2);
  line-height: 1.6;
  margin-bottom: 20px;
}

.overlay-close {
  background: var(--surface-2);
  border: 1px solid var(--border-md);
  border-radius: var(--radius-sm);
  padding: 9px 22px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-1);
}

.report-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.report-option {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-1);
  cursor: pointer;
}

.report-comment {
  width: 100%;
  min-height: 72px;
  padding: 10px 12px;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-1);
  background: var(--surface-2);
  border: 1px solid var(--border-md);
  border-radius: var(--radius-sm);
  resize: vertical;
  margin-bottom: 16px;
  outline: none;
}

.report-comment:focus { border-color: var(--accent); }

.overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#snackbar {
  display: none;
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-1);
  color: var(--bg);
  border-radius: var(--radius-md);
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 600;
  z-index: 400;
  max-width: 320px;
  text-align: center;
  white-space: nowrap;
}

#snackbar.show { display: block; }

@media (min-width: 600px) {
  #appMain { padding: 32px 24px; }
  .task-question { font-size: 19px; }
  .map-cell { height: 110px; }
}

/* ФУТЕР */
#appFooter {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--surface);
  margin-top: 0;
  display: flex;
  justify-content: center;
}

#appFooterInner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 420px;
  padding: 16px;
  font-size: 12px;
  color: var(--text-3);
}

#appFooterInner a {
  color: var(--text-3);
  text-decoration: none;
  border-bottom: 1px solid var(--border-md);
  transition: color var(--ease);
}

#appFooterInner a:hover {
  color: var(--text-2);
}