:root {
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --border-subtle: #e2e8f0;
  --border-strong: #cbd5e1;
  --text-main: #0f172a;
  --text-slate: #1e293b;
  --text-muted: #475569;
  --text-soft: #64748b;

  --kairos-teal: #008f8c;
  --kairos-teal-hover: #007572;
  --kairos-teal-soft: #f0fdfa;
  --kairos-teal-border: #99f6e4;

  --kaito-steel: #528099;
  --kaito-steel-hover: #3f677d;
  --kaito-steel-soft: #f0f7fa;
  --kaito-steel-border: #bae6fd;

  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-card: 0 6px 24px -4px rgba(15, 23, 42, 0.08), 0 1px 4px rgba(15, 23, 42, 0.04);
}

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

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text-main);
  background-color: var(--bg-page);
  background-image:
    linear-gradient(to right, rgba(148, 163, 184, 0.14) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(148, 163, 184, 0.14) 1px, transparent 1px);
  background-size: 32px 32px;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Cabecera */
.topbar {
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 30;
}

.topbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.brand-logo {
  width: 34px;
  height: 30px;
  display: block;
}

.brand-wordmark {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  font-size: 1.12rem;
  letter-spacing: 0.04em;
}

.brand-kairos {
  font-weight: 800;
  color: var(--text-slate);
}

.brand-ia {
  font-weight: 500;
  color: var(--text-soft);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tagline-pill {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  background: #f1f5f9;
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  padding: 5px 12px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: #ffffff;
  color: var(--text-slate);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.icon-btn:hover {
  background: #f1f5f9;
}

/* Main Grid */
.main-container {
  flex: 1;
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 18px 18px 28px;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 504px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

/* Arena Canvas */
.arena-card {
  padding: 12px;
}

.canvas-wrapper {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-strong);
  background: #f8fafc;
}

#game-canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 480 / 620;
  touch-action: manipulation;
  cursor: pointer;
}

/* Overlays */
.canvas-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.56);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  z-index: 15;
  overflow-y: auto;
}

.overlay-modal {
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.25);
  padding: 20px;
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
}

.eyebrow {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--kairos-teal);
  margin-bottom: 6px;
}

.modal-title {
  margin: 0 0 8px;
  font-size: 1.42rem;
  line-height: 1.2;
  color: var(--text-slate);
  font-weight: 800;
}

.modal-title-sm {
  margin: 4px 0 6px;
  font-size: 1.25rem;
  color: var(--text-slate);
}

.modal-subtitle,
.modal-subtitle-sm {
  margin: 0 0 14px;
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.rules-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.rule-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: #f8fafc;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--text-slate);
}

.rule-icon {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  font-size: 1.15rem;
}

.rule-avatar-img {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  object-fit: contain;
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: 9px;
  padding: 3px;
}

.rule-avatar-round {
  border-radius: 50%;
  padding: 0;
  border: 2px solid var(--kaito-steel);
}

.tag-pill {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  white-space: nowrap;
}

.tag-blue {
  background: #e0f2fe;
  color: #0369a1;
}

.tag-green {
  background: #d1fae5;
  color: #047857;
}

.tag-indigo {
  background: #e0e7ff;
  color: #4338ca;
}

.tag-amber {
  background: #fef3c7;
  color: #b45309;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.controls-hint {
  margin: 0;
  font-size: 0.76rem;
  line-height: 1.45;
  color: var(--text-soft);
}

kbd {
  display: inline-block;
  padding: 1px 5px;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-slate);
  background: #f1f5f9;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
}

/* Botones */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: inherit;
  font-weight: 700;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.1s ease, background-color 0.15s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn-lg {
  padding: 13px 20px;
  font-size: 0.96rem;
  width: 100%;
}

.btn-md {
  padding: 10px 14px;
  font-size: 0.84rem;
}

.btn-primary {
  background: var(--text-slate);
  color: #ffffff;
}

.btn-primary:hover {
  background: #0f172a;
}

.btn-teal {
  background: var(--kairos-teal);
  color: #ffffff;
}

.btn-teal:hover {
  background: var(--kairos-teal-hover);
}

.btn-outline {
  background: #ffffff;
  color: var(--text-slate);
  border-color: var(--border-strong);
}

.btn-outline:hover {
  background: #f8fafc;
}

.btn-ghost {
  background: #f8fafc;
  color: var(--text-muted);
  border-color: var(--border-subtle);
  padding: 8px 12px;
  font-size: 0.8rem;
}

.btn-ghost:hover {
  background: #f1f5f9;
  color: var(--text-main);
}

/* Controles táctiles bajo canvas */
.touch-controls {
  display: grid;
  grid-template-columns: 1fr 1.15fr 1fr;
  gap: 8px;
  margin-top: 10px;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
}

.ctrl-btn {
  font-family: inherit;
  font-weight: 700;
  font-size: 0.86rem;
  padding: 11px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: #ffffff;
  color: var(--text-slate);
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}

.ctrl-btn:hover {
  background: #f1f5f9;
}

.ctrl-btn:active {
  background: #e2e8f0;
  transform: scale(0.98);
}

.ctrl-btn-drop {
  background: var(--text-slate);
  border-color: var(--text-slate);
  color: #ffffff;
}

.ctrl-btn-drop:hover {
  background: #0f172a;
}

/* Sidebar */
.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.side-card {
  padding: 14px 16px;
}

.side-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.side-eyebrow {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--text-soft);
}

.level-pill {
  font-size: 0.74rem;
  font-weight: 800;
  color: var(--kairos-teal);
  background: var(--kairos-teal-soft);
  border: 1px solid var(--kairos-teal-border);
  border-radius: 999px;
  padding: 2px 10px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.kpi-box {
  background: #f8fafc;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.kpi-label {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text-soft);
}

.kpi-value {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-slate);
  font-variant-numeric: tabular-nums;
}

.kpi-teal .kpi-value {
  color: var(--kairos-teal);
}

.kpi-steel .kpi-value {
  color: var(--kaito-steel);
}

.best-row {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Next preview */
.next-preview {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px solid var(--border-subtle);
  border-left: 4px solid var(--kairos-teal);
}

.next-type {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: var(--text-soft);
}

.next-title {
  font-size: 0.9rem;
  color: var(--text-slate);
}

.next-dest {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* Powers */
.powers-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.power-card {
  width: 100%;
  text-align: left;
  font-family: inherit;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: #f8fafc;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

.power-card:disabled {
  cursor: default;
  opacity: 0.85;
}

.power-card.is-ready.power-kairos {
  background: var(--kairos-teal-soft);
  border-color: var(--kairos-teal);
  box-shadow: 0 0 0 3px rgba(0, 143, 140, 0.16);
}

.power-card.is-ready.power-kaito {
  background: var(--kaito-steel-soft);
  border-color: var(--kaito-steel);
  box-shadow: 0 0 0 3px rgba(82, 128, 153, 0.18);
}

.power-icon {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  object-fit: contain;
  background: #ffffff;
  border-radius: 8px;
  padding: 3px;
  border: 1px solid var(--border-subtle);
}

.power-icon-round {
  border-radius: 50%;
  padding: 0;
  border: 2px solid var(--kaito-steel);
}

.power-info {
  flex: 1;
  min-width: 0;
}

.power-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 3px;
  font-size: 0.84rem;
  color: var(--text-slate);
}

.power-state {
  font-size: 0.68rem;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 999px;
  background: #e2e8f0;
  color: var(--text-muted);
  white-space: nowrap;
}

.power-card.is-ready .power-state {
  background: var(--kairos-teal);
  color: #ffffff;
}

.power-card.is-ready.power-kaito .power-state {
  background: var(--kaito-steel);
}

.power-info p {
  margin: 0;
  font-size: 0.74rem;
  line-height: 1.4;
  color: var(--text-soft);
}

.slowmo-bar-wrap {
  margin-top: 6px;
  height: 5px;
  background: #dbeafe;
  border-radius: 999px;
  overflow: hidden;
}

.slowmo-bar-fill {
  height: 100%;
  width: 100%;
  background: #0284c7;
  transition: width 0.1s linear;
}

/* Live Log */
.live-log {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.log-item {
  font-size: 0.77rem;
  line-height: 1.4;
  color: var(--text-slate);
  background: #f8fafc;
  border: 1px solid var(--border-subtle);
  border-radius: 7px;
  padding: 7px 9px;
}

.log-item.log-kairos {
  border-left: 3px solid var(--kairos-teal);
  background: var(--kairos-teal-soft);
}

.log-item.log-kaito {
  border-left: 3px solid var(--kaito-steel);
  background: var(--kaito-steel-soft);
}

.log-item.log-err {
  border-left: 3px solid #ef4444;
  background: #fef2f2;
}

/* Game Over Results inside overlay */
.modal-results {
  text-align: center;
}

.rank-pill {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  padding: 4px 11px;
  border-radius: 999px;
  background: var(--kairos-teal-soft);
  color: var(--kairos-teal);
  border: 1px solid var(--kairos-teal-border);
  margin-bottom: 6px;
}

.res-kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  margin-bottom: 12px;
}

.res-kpi {
  background: #f8fafc;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 7px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.res-kpi span {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-soft);
}

.res-kpi strong {
  font-size: 0.96rem;
  color: var(--text-slate);
}

.res-kpi-teal strong {
  color: var(--kairos-teal);
}

.takeaway-box {
  background: #f1f5f9;
  border-left: 3px solid var(--kairos-teal);
  border-radius: 7px;
  padding: 9px 11px;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--text-slate);
  text-align: left;
  margin-bottom: 12px;
}

.results-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.results-sub-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Footer */
.footer {
  text-align: center;
  padding: 12px 16px 20px;
  font-size: 0.78rem;
  color: var(--text-soft);
}

.footer a {
  color: var(--kairos-teal);
  font-weight: 600;
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

/* Responsive */
@media (max-width: 860px) {
  .tagline-pill {
    display: none;
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

  .main-container {
    padding: 12px 10px 22px;
  }
}

@media (max-width: 480px) {
  .sound-label {
    display: none;
  }

  .overlay-modal {
    padding: 14px;
  }

  .modal-title {
    font-size: 1.2rem;
  }

  .res-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
