:root {
  color-scheme: dark;
  --bg: #0A0A0B;
  --panel: #141416;
  --panel-2: #1C1C20;
  --ink: #F4F4F5;
  --ink-2: #8E8E93;
  --line: #3A3A3C;
  --line-hi: #6A6A6E;
  --green: #538D4E;
  --yellow: #B59F3B;
  --gray: #3A3A3C;
  --danger: #C94A4A;
  --ui: "Instrument Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

html {
  scroll-padding-top: env(safe-area-inset-top, 0px);
  touch-action: manipulation;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 16px;
  line-height: 1.45;
  padding-block: 0 36px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

input, select, textarea {
  font-size: 16px !important;
}

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.app {
  max-width: 540px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* barra superior */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-block: 10px;
  border-bottom: 1px solid var(--line);
}

.bar .l, .bar .r {
  display: flex;
  align-items: center;
  gap: 4px;
}

.bar h1 {
  margin: 0;
  font-family: var(--mono);
  font-weight: 600;
  font-size: clamp(0.76rem, 3vw, 1rem);
  letter-spacing: 0.12em;
  white-space: nowrap;
  text-align: center;
}

.icon {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  background: none;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  flex-shrink: 0;
}

.icon:hover {
  background: var(--panel);
}

.auth-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.auth-btn:hover {
  border-color: var(--line-hi);
}

.auth-btn.logged {
  border-color: var(--green);
}

.avatar {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  text-transform: uppercase;
}

/* modos */
.modes {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 38px;
}

.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
  background: var(--panel);
}

.seg button {
  background: none;
  border: 0;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-2);
}

.seg button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--bg);
}

.ghost {
  background: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 0.85rem;
  font-weight: 600;
}

.ghost:hover {
  border-color: var(--line-hi);
}

/* frase rebuscada */
.top {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  padding-block: 4px;
  min-height: 76px;
  justify-content: center;
}

.cat {
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.phrase {
  margin: 0;
  font-weight: 700;
  font-size: clamp(1.4rem, 5.8vw, 1.95rem);
  line-height: 1.25;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
  min-width: 0;
  text-wrap: balance;
}

.phrase.loading {
  color: var(--ink-2);
  font-size: 1rem;
  font-family: var(--mono);
  font-weight: 500;
}

/* cuadrícula */
.grid {
  display: grid;
  gap: 6px;
}

.row {
  display: grid;
  grid-template-columns: repeat(var(--n), minmax(0, 1fr));
  gap: 6px;
}

.c {
  container-type: inline-size;
  position: relative;
  height: 54px;
  border: 2px solid var(--line);
  border-radius: 4px;
  display: grid;
  place-items: center;
  min-width: 0;
  overflow: hidden;
}

.c span.t {
  font-family: var(--mono);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 16px !important;
  line-height: 1;
  text-align: center;
  padding: 0 3px;
  display: inline-block;
  white-space: nowrap;
  transform-origin: center center;
  transform: scale(var(--scale, 1));
}

input.t {
  font-family: var(--mono);
  font-weight: 600;
  text-transform: uppercase;
  background: transparent;
  border: 0;
  color: var(--ink);
  width: calc(100% / var(--scale, 1));
  flex-shrink: 0;
  height: 100%;
  text-align: center;
  padding: 0 3px;
  outline: none;
  border-radius: 2px;
  font-size: 16px !important;
  transform-origin: center center;
  transform: scale(var(--scale, 1));
}

.c.filled {
  border-color: var(--line-hi);
}

.c:focus-within {
  border-color: var(--ink);
}

.c.g {
  background: var(--green);
  border-color: var(--green);
}

.c.y {
  background: var(--yellow);
  border-color: var(--yellow);
}

.c.x {
  background: var(--gray);
  border-color: var(--gray);
}

.c.g .t, .c.y .t, .c.x .t {
  color: #fff;
}

.c.locked::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 10px;
  height: 10px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white' fill-opacity='.85'%3E%3Cpath d='M17 9h-1V7a4 4 0 0 0-8 0v2H7a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-8a2 2 0 0 0-2-2zM10 7a2 2 0 0 1 4 0v2h-4V7z'/%3E%3C/svg%3E") center / contain no-repeat;
}

.row.shake {
  animation: shake .4s;
}

.c.pop {
  animation: pop .35s both;
}

@keyframes shake {
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

@keyframes pop {
  from { transform: scale(0.9); opacity: 0.3; }
  to { transform: scale(1); opacity: 1; }
}

.controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.btn {
  border: 0;
  border-radius: 10px;
  padding: 12px 22px;
  font-weight: 700;
  background: var(--ink);
  color: var(--bg);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn.green {
  background: var(--green);
  color: #fff;
}

.btn.yellow {
  background: var(--yellow);
  color: #0A0A0B;
}

.btn.danger {
  background: none;
  border: 1px solid var(--danger);
  color: #F08080;
}

.btn.line {
  background: none;
  border: 1px solid var(--line);
  color: var(--ink);
}

.btn.line:hover {
  border-color: var(--line-hi);
}

.keys {
  margin: 0;
  font-size: 0.78rem;
  color: var(--ink-2);
  text-align: center;
  max-width: 46ch;
}

/* barra de acciones secundaria */
.extra-nav {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
}

.pill-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 8px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink);
  text-align: center;
}

.pill-action:hover {
  border-color: var(--line-hi);
  background: var(--panel-2);
}

/* espacio responsivo para anuncios */
.ad-slot {
  width: 100%;
  max-width: 100%;
  min-height: 90px;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-sizing: border-box;
}

.ad-slot:empty {
  display: none;
}

/* pie legal discreto */
.foot-legal {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  font-size: 0.76rem;
  color: var(--ink-2);
  padding-top: 4px;
}

.foot-legal button {
  background: none;
  border: 0;
  padding: 4px 6px;
  color: var(--ink-2);
  text-decoration: underline;
  font-size: 0.76rem;
}

.foot-legal button:hover {
  color: var(--ink);
}

/* banner de consentimiento de privacidad */
.cookie-bar {
  position: fixed;
  z-index: 45;
  left: 50%;
  transform: translateX(-50%);
  bottom: max(12px, env(safe-area-inset-bottom, 0px));
  width: calc(100% - 24px);
  max-width: 520px;
  background: var(--panel-2);
  border: 1px solid var(--line-hi);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.65);
}

.cookie-bar p {
  margin: 0;
  font-size: 0.8rem;
  color: var(--ink-2);
  line-height: 1.4;
}

.cookie-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.cookie-actions button {
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 600;
}

/* formularios dentro de modales */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}

.field label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-2);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.field input, .field select {
  width: 100%;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 16px !important;
}

.field input:focus, .field select:focus {
  border-color: var(--ink);
  outline: none;
}

/* tabs de login / registro */
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 3px;
}

.auth-tabs button {
  background: none;
  border: 0;
  border-radius: 8px;
  padding: 7px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--ink-2);
}

.auth-tabs button[aria-pressed="true"] {
  background: var(--panel-2);
  color: var(--ink);
}

.forgot-btn {
  background: none;
  border: 0;
  padding: 0;
  font-size: 0.78rem;
  color: var(--ink-2);
  cursor: pointer;
  text-align: right;
}

.forgot-btn:hover {
  color: var(--ink);
  text-decoration: underline;
}

/* aviso de confirmación de correo */
.notice {
  background: rgba(83, 141, 78, 0.14);
  border: 1px solid var(--green);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.85rem;
  line-height: 1.4;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}

.notice b {
  overflow-wrap: anywhere;
  color: var(--ink);
}

.link-btn {
  background: none;
  border: 0;
  padding: 0;
  color: var(--ink);
  text-decoration: underline;
  font-size: 0.82rem;
  font-weight: 600;
  align-self: flex-start;
}

.link-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  text-decoration: none;
}

/* texto legal dentro del modal */
.legal-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--ink-2);
  line-height: 1.5;
  text-align: left;
}

.legal-box h3 {
  margin: 4px 0 0;
  font-size: 0.92rem;
  color: var(--ink);
}

.legal-box ul {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* mapeo dinámico palabra -> sinónimo */
.syn-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}

.syn-row {
  display: grid;
  grid-template-columns: 1fr auto 1.2fr;
  align-items: center;
  gap: 8px;
}

.syn-word {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.syn-arrow {
  font-family: var(--mono);
  color: var(--ink-2);
  font-weight: 700;
}

.syn-row input {
  width: 100%;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 16px !important;
}

.syn-row input:focus {
  border-color: var(--yellow);
  outline: none;
}

/* tarjeta visual de resultado */
.res-card {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.res-meta {
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: var(--ink-2);
  text-transform: uppercase;
}

.res-board {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.res-line {
  display: flex;
  gap: 5px;
  justify-content: center;
}

.res-tile {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  display: inline-block;
}

.res-tile.g {
  background: var(--green);
}

.res-tile.y {
  background: var(--yellow);
}

.res-tile.x {
  background: var(--gray);
}

/* diagrama de posiciones en reglas */
.pos-map {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 8px;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 5px;
  text-align: center;
}

.pos-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.pos-num {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--ink-2);
}

.pos-word {
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.pos-box {
  width: 100%;
  height: 30px;
  border: 1.5px solid var(--line-hi);
  border-radius: 4px;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink-2);
}

/* modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.75);
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}

.sheet {
  position: relative;
  width: 100%;
  max-width: 440px;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px 20px max(20px, env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sheet h2 {
  margin: 0;
  font-size: 1.3rem;
  line-height: 1.2;
  text-wrap: balance;
  padding-right: 28px;
}

.sheet p {
  margin: 0;
}

.close-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 36px;
  height: 36px;
  background: none;
  border: 0;
  border-radius: 8px;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--ink-2);
}

.lab {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.orig {
  font-weight: 700;
  font-size: 1.5rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.facts div {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
}

.facts b {
  font-size: 1.5rem;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.facts span {
  font-size: 0.78rem;
  color: var(--ink-2);
}

.btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btns .btn {
  flex: 1 1 150px;
}

.rules li {
  margin-bottom: 6px;
}

.rules ul {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.93rem;
}

.sample {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.sample .c {
  height: 44px;
}

.cap {
  font-size: 0.8rem;
  color: var(--ink-2);
}

.nums {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  text-align: center;
}

.nums b {
  display: block;
  font-size: 1.6rem;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.nums span {
  font-size: 0.7rem;
  color: var(--ink-2);
}

.dist {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.dist div {
  display: grid;
  grid-template-columns: 14px 1fr;
  gap: 8px;
  align-items: center;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.dist i {
  display: block;
  min-width: 22px;
  background: var(--gray);
  color: #fff;
  font-style: normal;
  text-align: right;
  padding: 1px 6px;
  font-weight: 600;
}

.dist i.me {
  background: var(--green);
}

.toast {
  position: fixed;
  z-index: 60;
  left: 50%;
  transform: translateX(-50%);
  top: calc(64px + env(safe-area-inset-top, 0px));
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  max-width: calc(100% - 32px);
  text-align: center;
}

[hidden] {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .row.shake, .c.pop {
    animation: none;
  }
}

/* skeleton screen */
@keyframes skPulse {
  from { opacity: 0.35; }
  to   { opacity: 0.75; }
}

.skeleton {
  background: var(--panel-2);
  border-radius: 6px;
  animation: skPulse 1.3s ease-in-out infinite alternate;
  display: block;
}

.sk-cat {
  width: 140px;
  height: 14px;
  margin: 0 auto;
}

.sk-phrase {
  width: min(360px, 85%);
  height: 32px;
  margin: 2px auto;
}

.c.sk {
  background: var(--panel);
  border-color: var(--line);
  animation: skPulse 1.3s ease-in-out infinite alternate;
}

.btn.sk-btn {
  min-width: 156px;
  height: 47px;
  background: var(--panel-2);
  color: transparent;
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .skeleton, .c.sk {
    animation: none;
  }
}

@media (max-width: 420px) {
  .pill-action {
    font-size: 0.78rem;
    padding: 9px 6px;
  }
  .pos-word {
    font-size: 0.74rem;
  }
}

@media (min-width: 640px) {
  .app {
    max-width: 660px;
  }
  .c {
    height: 62px;
  }
  .c span.t,
  input.t {
    font-size: 18px !important;
  }
}
