:root {
  --bg: #f0f4f8;
  --card: #ffffff;
  --text: #1d2433;
  --shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
  --radius: 18px;
  --cat-color: #3a86ff;
}

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

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ---- Tira de la frase ---- */
.phrase-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  background: var(--card);
  box-shadow: var(--shadow);
  z-index: 10;
}

.phrase {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 92px;
  padding: 8px;
  overflow-x: auto;
  background: #eef2f7;
  border-radius: var(--radius);
  scroll-behavior: smooth;
}

.phrase-hint {
  color: #8a94a6;
  font-size: 18px;
  padding: 0 12px;
}

.chip {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 78px;
  height: 78px;
  border: none;
  border-radius: 14px;
  background: #fff;
  box-shadow: var(--shadow);
  cursor: pointer;
  animation: pop 0.15s ease;
}
.chip .picto-emoji { font-size: 34px; line-height: 1; }
.chip .picto-img { width: 40px; height: 40px; object-fit: contain; }
.chip-label { font-size: 13px; font-weight: 600; }

@keyframes pop {
  from { transform: scale(0.6); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.phrase-actions { display: flex; gap: 8px; }

.btn {
  border: none;
  border-radius: 16px;
  width: 64px;
  height: 64px;
  font-size: 28px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.08s ease;
}
.btn:active { transform: scale(0.92); }
.btn-speak { background: #3a86ff; }
.btn-back  { background: #ffd166; }
.btn-clear { background: #ff7b7b; }
.btn-settings { background: #e0e6ef; }

/* ---- Panel de ajustes ---- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.overlay[hidden] { display: none; }

.panel {
  width: 100%;
  max-width: 460px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel-head h2 { margin: 0; font-size: 22px; }
.panel-head .btn { width: 48px; height: 48px; font-size: 20px; }

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 17px;
  font-weight: 600;
}
.field select,
.field input[type="range"] {
  width: 100%;
  font-size: 17px;
}
.field select {
  padding: 12px;
  border: 2px solid #d4dbe6;
  border-radius: 12px;
  background: #fff;
}

.btn-wide {
  padding: 14px;
  font-size: 18px;
  font-weight: 700;
  border: none;
  border-radius: 14px;
  background: #3a86ff;
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.btn-wide:active { transform: scale(0.97); }

/* ---- Categorías ---- */
.categories {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  background: var(--bg);
}

.cat {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 14px;
  border: 3px solid transparent;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  cursor: pointer;
  color: var(--text);
}
.cat-icon { font-size: 26px; }
.cat-name { font-size: 13px; font-weight: 600; }
.cat.active {
  border-color: var(--cat-color);
  background: color-mix(in srgb, var(--cat-color) 14%, white);
}

/* ---- Cuadrícula de pictogramas ---- */
.board {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
  padding: 12px;
  overflow-y: auto;
}

.picto {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  aspect-ratio: 1 / 1;
  border: 4px solid color-mix(in srgb, var(--cat-color) 35%, white);
  border-radius: 20px;
  background: var(--card);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.08s ease;
}
.picto:active { transform: scale(0.94); }
.picto-emoji { font-size: 56px; line-height: 1; }
.picto-img { width: 70%; height: 60%; object-fit: contain; }
.picto-label { font-size: 18px; font-weight: 700; text-align: center; }

@media (max-width: 600px) {
  .board { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
  .picto-emoji { font-size: 44px; }
  .picto-label { font-size: 15px; }
}

/* ---- Pantalla de activación por código ---- */
.code-view {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: linear-gradient(160deg, #3a86ff 0%, #8338ec 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.code-view[hidden] { display: none; }
.code-card {
  background: var(--card);
  border-radius: 24px;
  padding: 32px 26px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.code-logo { font-size: 56px; }
.code-card h1 { margin: 0; font-size: 26px; }
.code-card p { margin: 0; color: #5a6473; }
.code-input {
  font-size: 30px;
  font-weight: 700;
  text-align: center;
  letter-spacing: 6px;
  text-transform: uppercase;
  padding: 14px;
  border: 3px solid #d4dbe6;
  border-radius: 14px;
  width: 100%;
}
.code-input:focus { outline: none; border-color: var(--cat-color, #3a86ff); }
.code-error { color: #c0392b; font-weight: 700; }
.code-hint { font-size: 13px; color: #8a94a6; }

/* ---- Pie de ajustes ---- */
.muted { color: #8a94a6; font-size: 14px; }
.settings-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid #eef2f7;
  padding-top: 14px;
  text-align: center;
}
.btn-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  background: #e0e6ef;
  color: var(--text);
}
