/* Componentes reutilizables: botones, cuadros, campos, fichas, listas, avisos. */

/* ---------- Botones ---------- */
.btn {
  --b-h: 54px;
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: var(--b-h); min-width: 120px;
  padding: 0 var(--s6);
  border: 0; border-radius: var(--r-pill);
  font-weight: 800; font-size: 1.05rem; line-height: 1.1; text-align: center; text-decoration: none;
  color: #fff;
  background: linear-gradient(180deg, var(--btn-top), var(--btn-bottom));
  box-shadow: inset 0 1.5px 0 rgba(255, 255, 255, .22), inset 0 -2px 0 rgba(0, 0, 0, .25), 0 3px 0 var(--btn-edge), 0 6px 16px rgba(10, 30, 50, .22);
  transition: transform var(--t-med) var(--spring), box-shadow var(--t-fast) var(--ease-out), filter var(--t-fast);
  user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
}
.btn::after { /* brillo superior */
  content: ''; position: absolute; inset: 2px 4px auto; height: 50%;
  border-radius: var(--r-pill) var(--r-pill) 40% 40% / var(--r-pill) var(--r-pill) 12px 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .14), rgba(255, 255, 255, .02));
  pointer-events: none;
}
.btn:hover { transform: translateY(-1px) scale(1.02); box-shadow: inset 0 1.5px 0 rgba(255, 255, 255, .22), inset 0 -2px 0 rgba(0, 0, 0, .25), 0 3px 0 var(--btn-edge), 0 0 0 4px rgba(95, 208, 255, .55), 0 8px 20px rgba(10, 30, 50, .25); }
.btn:active { transform: translateY(2px) scale(.98); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .18), 0 1px 0 var(--btn-edge), 0 2px 6px rgba(10, 30, 50, .2); transition-duration: 60ms; }
.btn:focus-visible { outline: none; box-shadow: inset 0 1.5px 0 rgba(255, 255, 255, .22), 0 3px 0 var(--btn-edge), 0 0 0 4px var(--focus), 0 0 18px 4px rgba(95, 208, 255, .55); }
.btn[disabled], .btn[aria-disabled="true"] { filter: grayscale(.4) opacity(.55); cursor: not-allowed; transform: none; }
.btn.is-loading { color: transparent; pointer-events: none; }
.btn.is-loading::before {
  content: ''; position: absolute; width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, .35); border-top-color: #fff; animation: spin 800ms linear infinite;
}
.btn--light {
  color: var(--ink);
  background: linear-gradient(180deg, #ffffff, #eef2f5);
  box-shadow: inset 0 0 0 2px var(--line), inset 0 -2px 0 rgba(0, 0, 0, .05), 0 3px 0 #c7d2db, 0 6px 14px rgba(20, 70, 110, .12);
}
.btn--light::after { display: none; }
.btn--light:hover { box-shadow: inset 0 0 0 2px var(--sky-300), 0 3px 0 #c7d2db, 0 0 0 4px rgba(95, 208, 255, .45), 0 8px 18px rgba(20, 70, 110, .14); }
.btn--light:active { box-shadow: inset 0 0 0 2px var(--sky-300), 0 1px 0 #c7d2db; }
.btn--light.is-loading::before { border-color: rgba(0, 0, 0, .15); border-top-color: var(--ink); }
.btn--sky { background: linear-gradient(180deg, #3cc2f5, #0a8fd0); box-shadow: inset 0 1.5px 0 rgba(255, 255, 255, .35), inset 0 -2px 0 rgba(0, 0, 0, .15), 0 3px 0 #06679b, 0 6px 16px rgba(10, 110, 170, .3); }
.btn--danger { background: linear-gradient(180deg, #f0645a, #c4332a); box-shadow: inset 0 1.5px 0 rgba(255, 255, 255, .25), 0 3px 0 #8e2019, 0 6px 14px rgba(150, 30, 20, .25); }
.btn--small { --b-h: 44px; min-width: 0; padding: 0 var(--s4); font-size: .95rem; }
.btn--block { display: flex; width: 100%; }
.btn--ghost {
  min-width: 0; background: transparent; color: var(--sky-700); box-shadow: none; padding: 0 var(--s3);
}
.btn--ghost::after { display: none; }
.btn--ghost:hover { background: rgba(20, 165, 227, .1); box-shadow: none; transform: none; }
.btn--ghost:active { background: rgba(20, 165, 227, .18); box-shadow: none; }
.btn .glyph { width: 26px; height: 26px; flex: none; margin-left: -6px; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: var(--tap); height: var(--tap); flex: none;
  border: 0; border-radius: 50%;
  background: var(--paper); color: var(--ink-2);
  box-shadow: inset 0 0 0 2px var(--line), var(--sh-1);
  transition: transform var(--t-med) var(--spring), box-shadow var(--t-fast);
}
.icon-btn:hover { transform: scale(1.06); box-shadow: inset 0 0 0 2px var(--sky-300), 0 0 0 4px rgba(95, 208, 255, .35); }
.icon-btn:active { transform: scale(.94); }
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn .dot {
  position: absolute; transform: translate(14px, -14px);
  min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px;
  background: var(--coral); color: #fff; font-size: .72rem; font-weight: 800; line-height: 20px; text-align: center;
  box-shadow: 0 0 0 2px #fff;
}

/* Botón "Atrás" estilo WSR: círculo con flecha + píldora con el texto */
.back-btn {
  display: inline-flex; align-items: center; gap: 0;
  min-height: var(--tap); padding: 0 var(--s4) 0 0;
  border: 0; border-radius: var(--r-pill);
  background: var(--paper); color: var(--ink);
  font-weight: 800; font-size: 1rem;
  box-shadow: inset 0 0 0 2px var(--line), var(--sh-1);
  transition: transform var(--t-med) var(--spring), box-shadow var(--t-fast);
}
.back-btn .circle {
  display: grid; place-items: center; width: var(--tap); height: var(--tap); border-radius: 50%;
  background: linear-gradient(180deg, var(--btn-top), var(--btn-bottom)); color: #fff; margin-right: var(--s3);
  box-shadow: 0 2px 0 var(--btn-edge);
}
.back-btn svg { width: 22px; height: 22px; }
.back-btn:hover { transform: translateX(-2px); box-shadow: inset 0 0 0 2px var(--sky-300), 0 0 0 4px rgba(95, 208, 255, .35); }
.back-btn:active { transform: scale(.96); }

/* Glifo de botón del Wii Remote (A / B) */
.glyph-a, .glyph-b {
  display: inline-grid; place-items: center; width: 1.5em; height: 1.5em; border-radius: 50%;
  font-weight: 800; font-size: .9em; line-height: 1; vertical-align: -0.35em;
  color: #4b5056; background: radial-gradient(circle at 50% 35%, #ffffff, #dfe4e8 70%);
  box-shadow: inset 0 0 0 2px #9aa3ab, 0 1px 0 rgba(0, 0, 0, .15);
}
.glyph-b { border-radius: 30%; }

/* ---------- Cuadros (diálogos blancos de la Wii) ---------- */
.panel {
  position: relative;
  background: var(--paper);
  border-radius: var(--r-l);
  box-shadow: inset 0 0 0 2px var(--line-2), var(--sh-2);
  padding: var(--s6);
}
.panel--flush { padding: 0; overflow: hidden; }
.panel-title {
  display: flex; align-items: center; justify-content: center;
  min-height: 52px; padding: var(--s2) var(--s8);
  margin: calc(var(--s6) * -1) calc(var(--s6) * -1) var(--s5);
  border-radius: var(--r-l) var(--r-l) 0 0;
  background: linear-gradient(180deg, #f8fbfd, #eef4f8);
  border-bottom: 2px solid var(--line-2);
  font-weight: 800; font-size: 1.15rem; text-align: center;
}

/* Píldora de título de pantalla (como tt_maru_window_360_title) */
.title-pill {
  display: inline-flex; align-items: center; gap: var(--s3);
  min-height: 52px; padding: var(--s2) var(--s8);
  border-radius: var(--r-pill);
  background: var(--paper);
  box-shadow: inset 0 0 0 2px var(--line), var(--sh-1);
  font-weight: 800; font-size: clamp(1.1rem, 2.4vw, 1.4rem);
  text-align: center;
}
.title-pill img, .title-pill svg { width: 30px; height: 30px; }

/* ---------- Campos ---------- */
.field { display: grid; gap: 6px; }
.field > label, .field-label { font-weight: 700; font-size: .95rem; color: var(--ink); }
.field .hint { font-size: .85rem; color: var(--ink-2); font-weight: 500; }
.field .error { font-size: .88rem; color: var(--err); font-weight: 700; display: flex; gap: 6px; align-items: flex-start; }
.field .error:empty { display: none; }
.field .error::before { content: '!'; flex: none; display: inline-grid; place-items: center; width: 18px; height: 18px; margin-top: 2px; border-radius: 50%; background: var(--err); color: #fff; font-size: .75rem; }
.input-wrap { position: relative; display: flex; align-items: center; }
.input {
  width: 100%;
  min-height: 52px;
  padding: 12px 16px;
  border: 2px solid var(--line);
  border-radius: var(--r-s);
  background: var(--paper-2);
  font-weight: 600; font-size: 1.05rem;
  transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
  -webkit-appearance: none; appearance: none;
}
.input::placeholder { color: var(--ink-3); font-weight: 500; }
.input:hover { border-color: #c2d1dc; }
.input:focus { outline: none; border-color: var(--sky-400); background: #fff; box-shadow: 0 0 0 4px rgba(69, 189, 238, .22); }
.input[aria-invalid="true"] { border-color: var(--err); background: #fffafa; }
.input[aria-invalid="true"]:focus { box-shadow: 0 0 0 4px rgba(217, 59, 48, .18); }
.input.is-valid { border-color: #9fd8b4; }
.input-wrap .input { padding-right: 56px; }
.input-wrap .reveal {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px; border: 0; border-radius: var(--r-xs); background: transparent; color: var(--ink-2);
  display: grid; place-items: center;
}
.input-wrap .reveal:hover { background: var(--sky-100); color: var(--sky-700); }
.input-wrap .reveal svg { width: 22px; height: 22px; }

/* Control segmentado */
.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding: 5px; gap: 4px;
  border-radius: var(--r-pill);
  background: #e9f0f5;
  box-shadow: inset 0 1px 2px rgba(20, 60, 90, .1);
}
.segmented button {
  min-height: 44px; border: 0; border-radius: var(--r-pill);
  background: transparent; color: var(--ink-2); font-weight: 800;
  transition: background var(--t-med) var(--ease-out), color var(--t-fast), box-shadow var(--t-med);
}
.segmented button[aria-selected="true"], .segmented button[aria-pressed="true"] {
  background: #fff; color: var(--ink);
  box-shadow: 0 1px 2px rgba(20, 60, 90, .12), 0 3px 8px rgba(20, 60, 90, .08);
}

/* ---------- Avisos ---------- */
.banner {
  display: flex; gap: var(--s3); align-items: flex-start;
  padding: var(--s3) var(--s4); border-radius: var(--r-s);
  font-weight: 700; font-size: .95rem;
}
.banner--error { background: var(--err-bg); color: #9b2219; }
.banner--ok { background: var(--ok-bg); color: #13703a; }
.banner--info { background: var(--sky-100); color: var(--sky-700); }
.banner:empty { display: none; }

.toasts {
  position: fixed; z-index: 50; left: 50%; transform: translateX(-50%);
  top: calc(var(--s3) + var(--safe-t));
  display: grid; gap: var(--s2); width: min(440px, calc(100vw - 24px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-radius: var(--r-m);
  background: rgba(255, 255, 255, .96);
  box-shadow: inset 0 0 0 2px var(--line-2), var(--sh-3);
  font-weight: 700;
  animation: toast-in 520ms var(--spring) both;
}
.toast.out { animation: toast-out 220ms var(--ease-out) both; }
.toast .mii-face { width: 48px; height: 48px; }
.toast .grow { flex: 1; min-width: 0; }
.toast small { display: block; color: var(--ink-2); font-weight: 600; }
.toast .actions { display: flex; gap: var(--s2); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-18px) scale(.95); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-10px) scale(.97); } }

/* ---------- Mii ---------- */
.mii-face {
  position: relative; flex: none;
  width: 64px; height: 64px; border-radius: 50%;
  background: radial-gradient(circle at 50% 30%, #ffffff, #e2eef5);
  box-shadow: inset 0 0 0 2px var(--line), 0 2px 6px rgba(20, 70, 110, .1);
  overflow: hidden;
}
.mii-face img { width: 112%; height: 112%; margin: -2% -6%; object-fit: cover; opacity: 0; transition: opacity var(--t-med); }
.mii-face img.ready { opacity: 1; }
.mii-face .initial {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-weight: 800; font-size: 1.6em; color: var(--sky-600);
}
.mii-face.has-img .initial { display: none; }
.mii-face .presence {
  position: absolute; right: 2px; bottom: 2px; width: 22%; height: 22%; min-width: 12px; min-height: 12px;
  border-radius: 50%; background: #b8c3cc; box-shadow: 0 0 0 2px #fff;
}
.mii-face .presence.on { background: var(--leaf); }

/* ---------- Fichas / tarjetas ---------- */
.tile {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 120px; padding: var(--s4);
  border: 0; border-radius: var(--r-m);
  background: var(--paper);
  color: var(--ink);
  box-shadow: inset 0 0 0 2px var(--line), 0 4px 0 #d3dee6, var(--sh-1);
  text-align: center; font-weight: 800;
  transition: transform var(--t-med) var(--spring), box-shadow var(--t-fast) var(--ease-out);
}
.tile:hover, .tile:focus-visible {
  outline: none;
  transform: translateY(-3px) scale(1.025);
  box-shadow: inset 0 0 0 3px var(--sky-300), 0 4px 0 #b9dcf0, 0 0 0 5px rgba(95, 208, 255, .35), 0 14px 30px rgba(20, 110, 170, .18);
}
.tile:active { transform: translateY(2px) scale(.98); transition-duration: 80ms; }
.tile[aria-disabled="true"] { filter: grayscale(1) opacity(.5); cursor: not-allowed; transform: none; box-shadow: inset 0 0 0 2px var(--line), 0 2px 0 #dfe6eb; }
.tile .tile-sub { font-weight: 600; font-size: .85rem; color: var(--ink-2); }
.tile .lock { position: absolute; top: 10px; right: 10px; width: 22px; height: 22px; color: var(--ink-3); }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  height: 26px; padding: 0 10px; border-radius: var(--r-pill);
  font-size: .78rem; font-weight: 800; letter-spacing: .02em;
  background: var(--sky-100); color: var(--sky-700);
}
.badge--pro { background: linear-gradient(180deg, #ffd56b, #ffab1f); color: #6b3a00; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .6); }
.badge--ok { background: var(--ok-bg); color: #13703a; }
.badge--muted { background: #eef2f5; color: var(--ink-2); }

/* ---------- Listas ---------- */
.list { display: grid; gap: var(--s2); margin: 0; padding: 0; list-style: none; }
.row {
  display: flex; align-items: center; gap: var(--s3);
  min-height: 72px; padding: var(--s2) var(--s3);
  border-radius: var(--r-m);
  background: var(--paper);
  box-shadow: inset 0 0 0 2px var(--line-2);
}
.row .grow { flex: 1; min-width: 0; }
.row .name { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { font-size: .85rem; color: var(--ink-2); font-weight: 600; }
.row .actions { display: flex; gap: var(--s2); flex-wrap: wrap; justify-content: flex-end; }

.empty {
  display: grid; justify-items: center; gap: var(--s3);
  padding: var(--s8) var(--s4); text-align: center; color: var(--ink-2);
}
.empty svg { width: 64px; height: 64px; color: var(--sky-300); }
.empty strong { color: var(--ink); font-size: 1.05rem; }

/* ---------- Carga ---------- */
.spinner {
  width: 40px; height: 40px; border-radius: 50%;
  border: 4px solid var(--sky-100); border-top-color: var(--sky-500);
  animation: spin 900ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-screen { flex: 1; display: grid; place-items: center; align-content: center; gap: var(--s4); color: var(--ink-2); font-weight: 700; }

/* ---------- Hoja modal ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center; padding: var(--s4);
  background: rgba(30, 50, 70, .38);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  animation: fade-in 200ms var(--ease-out) both;
}
.sheet {
  width: min(520px, 100%); max-height: calc(100dvh - 32px); overflow: auto;
  animation: sheet-in 460ms var(--spring) both;
}
@keyframes fade-in { from { opacity: 0; } }
@keyframes sheet-in { from { opacity: 0; transform: translateY(24px) scale(.96); } }
.sheet-actions { display: flex; gap: var(--s3); justify-content: center; flex-wrap: wrap; margin-top: var(--s5); }
.sheet-actions .btn { flex: 1 1 160px; }

/* ---------- Barra superior de pantallas de menú ---------- */
.topbar {
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: var(--s3);
  margin-bottom: var(--s5);
}
.topbar > :first-child { justify-self: start; }
.topbar > :last-child { justify-self: end; display: flex; gap: var(--s2); align-items: center; }
.topbar .title-pill { justify-self: center; }
@media (max-width: 560px) {
  .topbar { grid-template-columns: auto 1fr auto; }
  .topbar .title-pill { min-height: 44px; padding: var(--s1) var(--s5); font-size: 1.05rem; justify-self: center; }
  .back-btn .label { display: none; }
  .back-btn { padding: 0; }
  .back-btn .circle { margin-right: 0; }
}

.me-chip {
  display: inline-flex; align-items: center; gap: var(--s2);
  min-height: var(--tap); padding: 4px var(--s4) 4px 4px;
  border: 0; border-radius: var(--r-pill);
  background: var(--paper); box-shadow: inset 0 0 0 2px var(--line), var(--sh-1);
  font-weight: 800; max-width: 220px;
  transition: transform var(--t-med) var(--spring), box-shadow var(--t-fast);
}
.me-chip .mii-face { width: 40px; height: 40px; }
.me-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-chip:hover { transform: scale(1.03); box-shadow: inset 0 0 0 2px var(--sky-300), 0 0 0 4px rgba(95, 208, 255, .35); }
@media (max-width: 560px) { .me-chip span { display: none; } .me-chip { padding: 4px; } }

/* Indicador "Oprime A" que respira */
.press-a {
  display: inline-flex; align-items: center; gap: var(--s2);
  padding: var(--s2) var(--s5); border-radius: var(--r-pill);
  background: rgba(255, 255, 255, .92);
  box-shadow: inset 0 0 0 2px var(--line), var(--sh-2);
  font-weight: 800; font-size: 1.1rem; color: var(--ink);
  animation: breathe 1.6s ease-in-out infinite;
}
.press-a .glyph-a { width: 1.7em; height: 1.7em; font-size: 1em; }
@keyframes breathe { 50% { transform: scale(1.05); box-shadow: inset 0 0 0 2px var(--sky-300), 0 0 0 6px rgba(95, 208, 255, .25), var(--sh-2); } }
