/* =========================================================
   PixelLab — estilos mobile-first
   Defaults: telas pequenas (≥ 320px).
   Tablet:   @media (min-width: 700px)
   Desktop:  @media (min-width: 1080px)
   ========================================================= */

:root {
  --bg: #0f1226;
  --bg-2: #161a36;
  --panel: #1d2247;
  --panel-2: #242a59;
  --line: #2e3570;
  --text: #e8ecff;
  --muted: #9aa3d6;
  --brand: #ff3366;
  --brand-2: #6a5cff;
  --accent: #00d4a8;
  --danger: #ff5b6b;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --radius: 14px;
  --radius-sm: 8px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(800px 400px at 10% -10%, rgba(106, 92, 255, .25), transparent 60%),
    radial-gradient(600px 400px at 110% 10%, rgba(255, 51, 102, .18), transparent 60%),
    linear-gradient(180deg, #0c0f23 0%, #0f1226 100%);
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

/* Espaço extra no fim para a tool bar mobile não sobrepor o conteúdo */
body { padding-bottom: calc(76px + var(--safe-bottom)); }

/* ============================================================
   TOPBAR — compacta no mobile, expandida no desktop
   ============================================================ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  gap: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, .06);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  background: rgba(15, 18, 38, .85);
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: clamp(16px, 4.5vw, 22px);
  letter-spacing: .5px;
  background: linear-gradient(90deg, #fff, #c9c2ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand .tagline {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
  display: none; /* escondida em telas pequenas */
}

.logo {
  display: grid;
  grid-template-columns: 10px 10px;
  grid-template-rows: 10px 10px;
  gap: 2px;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}
.logo .pix { border-radius: 2px; }
.logo .p1 { background: var(--brand); }
.logo .p2 { background: var(--brand-2); }
.logo .p3 { background: var(--accent); }
.logo .p4 { background: #fff; }

.ghost-btn {
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .1);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  transition: background .15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  white-space: nowrap;
}
.ghost-btn:hover { background: rgba(255, 255, 255, .12); }
.ghost-btn:active { background: rgba(255, 255, 255, .18); }
.ghost-btn.danger { color: var(--danger); border-color: rgba(255, 91, 107, .35); }
.ghost-btn.danger:hover { background: rgba(255, 91, 107, .15); }

.icn { font-weight: 700; }

@media (min-width: 700px) {
  .topbar { padding: 16px 22px; }
  .brand .tagline { display: block; }
  .logo { width: 26px; height: 26px; grid-template-columns: 12px 12px; grid-template-rows: 12px 12px; }
}

/* ============================================================
   LAYOUT — flex coluna no mobile, grid 3 col no desktop
   ============================================================ */
.layout {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  align-items: stretch;
}

/* Stage primeiro no mobile, deixa painéis abaixo */
.stage { order: -1; }

.panel { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

@media (min-width: 700px) {
  .layout { padding: 16px 20px; gap: 16px; }
}

@media (min-width: 1080px) {
  .layout {
    display: grid;
    grid-template-columns: 290px minmax(0, 1fr) 280px;
    gap: 20px;
    padding: 20px 28px 30px;
    align-items: start;
  }
  .stage { order: 0; }
  /* esconde a tool bar mobile no desktop */
  body { padding-bottom: 0; }
  .mobile-bar { display: none !important; }
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 10px;
  font-size: 13px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--muted);
}

.hint {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 10px;
  line-height: 1.45;
}
.hint.mini { font-size: 12px; margin-top: 8px; }

@media (min-width: 700px) {
  .card { padding: 16px; }
}

/* ============================================================
   RESOLUÇÃO
   ============================================================ */
.res-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.res-btn {
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  min-height: 44px;
  transition: all .15s ease;
}
.res-btn:hover { background: rgba(255, 255, 255, .1); }
.res-btn:active { transform: scale(.97); }
.res-btn.active {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  border-color: transparent;
  color: white;
}

.custom-res {
  display: grid;
  grid-template-columns: 1fr 80px auto;
  gap: 6px;
  align-items: center;
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}
.custom-res input {
  background: rgba(0, 0, 0, .25);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 9px 8px;
  border-radius: 6px;
  font-size: 14px;
  width: 100%;
  min-height: 40px;
}

.mini-btn {
  background: rgba(255, 255, 255, .08);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  min-height: 40px;
}
.mini-btn:hover { background: rgba(255, 255, 255, .14); }
.mini-btn:active { transform: scale(.97); }
.mini-btn.full { width: 100%; margin-top: 8px; }

.stat-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 12px;
}
.stat-row > div {
  background: rgba(0, 0, 0, .2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.stat-value { font-size: 16px; font-weight: 700; }

@media (min-width: 1080px) {
  .res-buttons { grid-template-columns: 1fr 1fr; }
}

/* ============================================================
   FERRAMENTAS
   ============================================================ */
.tools {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.tool-btn {
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 11px;
  min-height: 56px;
  transition: all .15s ease;
}
.tool-btn:hover { background: rgba(255, 255, 255, .1); }
.tool-btn:active { transform: scale(.97); }
.tool-btn.active {
  background: linear-gradient(135deg, var(--brand-2), var(--accent));
  border-color: transparent;
}
.tool-btn svg { display: block; }
.tool-btn span { font-size: 11px; }

.brush-row {
  display: grid;
  grid-template-columns: 1fr 1.4fr auto;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted);
}
.brush-row input[type="range"] { width: 100%; }
#brushVal {
  background: rgba(0, 0, 0, .25);
  border: 1px solid var(--line);
  padding: 4px 10px;
  border-radius: 4px;
  font-weight: 700;
  color: var(--text);
  font-size: 13px;
  min-width: 28px;
  text-align: center;
}

@media (min-width: 1080px) {
  .tools { grid-template-columns: 1fr 1fr; }
}

/* ============================================================
   CORES
   ============================================================ */
.color-row { display: flex; align-items: center; gap: 10px; }
.color-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 13px;
}
.color-picker input[type="color"] {
  width: 0; height: 0; opacity: 0; position: absolute;
}
.color-swatch {
  width: 42px; height: 42px;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, .15);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .25);
}

.palette {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  margin-top: 6px;
}
.palette button {
  aspect-ratio: 1;
  min-height: 32px;
  border: 2px solid rgba(255, 255, 255, .1);
  border-radius: 6px;
  cursor: pointer;
  padding: 0;
  transition: transform .1s;
  position: relative;
}
.palette button:hover { transform: scale(1.08); }
.palette button:active { transform: scale(.94); }
.palette button.active { border-color: white; box-shadow: 0 0 0 2px var(--brand); }

/* ============================================================
   STAGE / CANVAS  — fluido, sem cell em pixels
   ============================================================ */
.stage {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stage-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.stage-toolbar .spacer { flex: 1; }

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  padding: 6px 4px;
}
.toggle input { width: 18px; height: 18px; }

.canvas-wrap {
  position: relative;
  display: grid;
  place-items: center;
  padding: clamp(8px, 3vw, 22px);
  background:
    linear-gradient(45deg, #1a1f44 25%, transparent 25%),
    linear-gradient(-45deg, #1a1f44 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1a1f44 75%),
    linear-gradient(-45deg, transparent 75%, #1a1f44 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-color: #14183a;
  border-radius: 10px;
  border: 1px solid var(--line);
  min-height: 280px;
}

.canvas-shadow {
  filter: drop-shadow(0 6px 22px rgba(0, 0, 0, .5));
  width: 100%;
  display: flex;
  justify-content: center;
}

.grid {
  display: grid;
  background: white;
  border-radius: 2px;
  user-select: none;
  touch-action: none;
  cursor: crosshair;
  width: 100%;
  max-width: 540px;
  aspect-ratio: 1 / 1;
}

.grid.show-grid .cell { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08); }

.cell {
  background: white;
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
}
.cell.painted {
  background: var(--c);
}

.coord-hud {
  position: absolute;
  bottom: 6px;
  right: 8px;
  background: rgba(0, 0, 0, .65);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 10px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  color: var(--text);
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s;
}
.coord-hud.visible { opacity: 1; }

.stage-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.primary-btn {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  border: 0;
  color: white;
  padding: 11px 18px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
  min-height: 44px;
  box-shadow: 0 6px 18px rgba(255, 51, 102, .35);
}
.primary-btn:hover { filter: brightness(1.1); }
.primary-btn:active { transform: scale(.97); }

@media (min-width: 1080px) {
  .stage { padding: 16px; gap: 12px; }
  .canvas-wrap { min-height: 480px; }
  .grid { max-width: 560px; }
}

/* ============================================================
   PAINEL DIREITO — APRENDA
   ============================================================ */
.learn-list {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}
.learn-list li { margin-bottom: 8px; }
.learn-list strong { color: var(--text); }

.challenges {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
}

.color-detail {
  display: grid;
  grid-template-columns: 60px 1fr;
  gap: 12px;
  align-items: center;
}
.big-swatch {
  width: 60px;
  height: 60px;
  border-radius: 12px;
  background: var(--brand);
  border: 2px solid rgba(255, 255, 255, .15);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .25);
}
.color-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
}
.color-info > div { display: flex; gap: 8px; align-items: baseline; }
.color-info span { color: var(--muted); width: 50px; flex-shrink: 0; }
.color-info code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--text);
  font-size: 11px;
  line-height: 1.35;
  word-break: break-all;
}

@media (min-width: 380px) {
  .color-detail { grid-template-columns: 70px 1fr; }
  .big-swatch { width: 70px; height: 70px; }
  .color-info { font-size: 12px; }
  .color-info code { font-size: 12px; }
}

/* ============================================================
   BARRA DE AÇÕES MOBILE — sticky bottom
   ============================================================ */
.mobile-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: linear-gradient(180deg, rgba(29, 34, 71, .92), rgba(15, 18, 38, .98));
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding: 8px 10px calc(8px + var(--safe-bottom));
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 20;
  box-shadow: 0 -6px 24px rgba(0, 0, 0, .4);
}
.mobile-bar .mb-tool,
.mobile-bar .mb-action {
  flex: 1;
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .08);
  color: var(--text);
  padding: 8px 4px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
}
.mobile-bar .mb-tool.active {
  background: linear-gradient(135deg, var(--brand-2), var(--accent));
  border-color: transparent;
}
.mobile-bar .mb-tool:active,
.mobile-bar .mb-action:active { transform: scale(.95); }
.mobile-bar .mb-color {
  flex: 0 0 auto;
  width: 48px; height: 48px;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, .15);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, .25);
  cursor: pointer;
  padding: 0;
}

/* ============================================================
   MODAL
   ============================================================ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .65);
  display: grid;
  place-items: end center;
  z-index: 100;
  padding: 0;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--panel);
  border: 1px solid var(--line);
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  border-bottom: 0;
  padding: 20px 18px calc(28px + var(--safe-bottom));
  max-width: 560px;
  width: 100%;
  position: relative;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  animation: slideUp .25s ease-out;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-close {
  position: absolute;
  top: 10px; right: 12px;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 28px;
  cursor: pointer;
  line-height: 1;
  padding: 6px 10px;
  min-width: 44px;
  min-height: 44px;
}
.modal-close:hover { color: var(--text); }
.modal-content h2 { margin-top: 0; font-size: 18px; }
.modal-content ol, .modal-content ul { line-height: 1.6; color: var(--muted); padding-left: 22px; }
.modal-content ol strong, .modal-content ul b { color: var(--text); }
.modal-content h3 { margin: 18px 0 8px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.shortcuts { color: var(--muted); font-size: 13px; line-height: 1.9; }
kbd {
  background: rgba(255, 255, 255, .1);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 6px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  color: var(--text);
}

@media (min-width: 700px) {
  .modal {
    place-items: center;
    padding: 20px;
  }
  .modal-content {
    border-radius: var(--radius);
    border-bottom: 1px solid var(--line);
    padding: 28px;
    max-height: 90vh;
    animation: fadeIn .15s ease-out;
  }
  @keyframes fadeIn {
    from { opacity: 0; transform: scale(.96); }
    to { opacity: 1; transform: scale(1); }
  }
}

/* ============================================================
   FOOTER
   ============================================================ */
.footer {
  text-align: center;
  padding: 14px;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid rgba(255, 255, 255, .06);
}

/* ============================================================
   ACESSIBILIDADE — foco visível
   ============================================================ */
button:focus-visible,
input:focus-visible,
label:focus-visible {
  outline: 2px solid var(--brand-2);
  outline-offset: 2px;
}
