:root {
  --brand1: #8dc540;
  --brand2: #01a79c;
  --link: #0284c7;
  --accent-warn: #ea580c;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --bg: #f3f4f6;
  --surface: #ffffff;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.07);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.08);
  --radius: 14px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  min-height: 100vh;
}

body.modal-open {
  overflow: hidden;
}

.topbar {
  height: 3px;
  background: linear-gradient(90deg, var(--brand1), var(--brand2), #0284c7);
}

.shell {
  max-width: none;
  margin: 0 auto;
  padding: 1.25rem clamp(1rem, 3vw, 2rem) 2.5rem;
}

.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem 1.25rem;
  padding: 0.85rem 1.25rem;
  margin: 0 -0.25rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

.app-header-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  color: inherit;
}

.app-header-brand img {
  height: 36px;
  width: auto;
  display: block;
}

.app-header-titles {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.app-header-titles strong {
  font-size: 1rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.app-header-titles span {
  font-size: 0.75rem;
  color: var(--muted);
}

.app-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  align-items: center;
  flex: 1;
  justify-content: flex-end;
}

.app-nav a {
  color: var(--link);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.35rem 0.6rem;
  border-radius: 8px;
}

.app-nav a:hover {
  background: rgba(2, 132, 199, 0.08);
  text-decoration: none;
}

.app-nav .btn-logout {
  margin-left: 0.25rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem 1.5rem;
  box-shadow: var(--shadow-md);
}

.card h2,
.card h3 {
  margin-top: 0;
}

h1 {
  font-size: 1.35rem;
  margin: 0 0 0.35rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.5rem;
}

label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.field-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text);
  margin-bottom: 1rem;
  cursor: pointer;
}

.field-check input {
  width: auto;
}

input[type='text'],
input[type='email'],
input[type='password'],
input[type='number'],
select,
textarea {
  width: 100%;
  max-width: 420px;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  background: var(--surface);
}

textarea {
  min-height: 100px;
  max-width: 100%;
}

.field {
  margin-bottom: 0.85rem;
}

.modal-body .field input,
.modal-body .field select,
.modal-body .field textarea {
  max-width: 100%;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.btn:hover {
  background: #f9fafb;
}

.btn-primary {
  background: linear-gradient(160deg, var(--brand2), #018e85);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 2px 8px rgba(1, 167, 156, 0.35);
}

.btn-primary:hover {
  filter: brightness(1.05);
  background: linear-gradient(160deg, var(--brand2), #018e85);
}

.btn-lg {
  padding: 0.85rem 1.5rem;
  font-size: 1.02rem;
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 10px rgba(220, 38, 38, 0.35);
}

.btn-danger:hover {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
  filter: none;
}

.btn-accent {
  background: #fff7ed;
  border-color: #fdba74;
  color: #c2410c;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(234, 88, 12, 0.12);
}

.btn-accent:hover {
  background: #ffedd5;
  border-color: #fb923c;
}

.btn-exit {
  background: var(--brand1);
  border-color: var(--brand1);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 10px rgba(141, 197, 64, 0.35);
}

.btn-exit:hover {
  filter: brightness(0.95);
}

.btn-logout {
  border-color: var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}

.btn-logout:hover {
  color: var(--danger);
  border-color: #fecaca;
  background: #fef2f2;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  text-align: left;
  padding: 0.65rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
}

.err {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

.ok {
  color: #15803d;
  font-size: 0.85rem;
}

/* Login */
.login-page {
  min-height: calc(100vh - 3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.25rem;
  background:
    radial-gradient(ellipse 80% 60% at 50% -20%, rgba(141, 197, 64, 0.18), transparent),
    radial-gradient(ellipse 60% 50% at 100% 50%, rgba(2, 132, 199, 0.08), transparent),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 2rem 1.75rem;
  box-shadow: var(--shadow-lg);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.login-brand img {
  height: 44px;
  width: auto;
}

.login-brand-text strong {
  display: block;
  font-size: 1.15rem;
}

.login-brand-text span {
  font-size: 0.8rem;
  color: var(--muted);
}

.login-card h1 {
  font-size: 1.2rem;
  margin-bottom: 0.35rem;
}

.login-sub {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 1.25rem;
}

.login-alt {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  text-align: center;
}

.login-alt a {
  color: var(--link);
  font-weight: 500;
}

/* Dashboard grids */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.dash-tile {
  display: block;
  padding: 1.35rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow-md);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.dash-tile:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: #d1d5db;
}

.dash-tile-icon {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
  margin-bottom: 0.75rem;
}

.dash-tile-icon.green {
  background: linear-gradient(135deg, var(--brand1), #6a9e2e);
}

.dash-tile-icon.teal {
  background: linear-gradient(135deg, var(--brand2), #0284c7);
}

.dash-tile-icon.orange {
  background: linear-gradient(135deg, #fb923c, #ea580c);
}

.dash-tile-icon.slate {
  background: linear-gradient(135deg, #64748b, #475569);
}

.dash-tile h2 {
  font-size: 1rem;
  margin: 0 0 0.35rem;
}

.dash-tile p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.45;
}

.player-home-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 860px) {
  .player-home-grid {
    grid-template-columns: 1fr 1fr;
  }

  .player-home-grid .player-home-span {
    grid-column: 1 / -1;
  }
}

.player-home-card-title {
  font-size: 0.95rem;
  margin: 0 0 0.65rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.player-home-tournament-line {
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
}

.player-home-pending-card {
  border-left: 3px solid rgba(1, 167, 156, 0.45);
}

.player-pending-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.player-pending-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 0.75rem;
  padding: 0.5rem 0.65rem;
  background: #f9fafb;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.player-pending-meta {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
  min-width: 0;
}

.player-pending-rival {
  font-size: 0.875rem;
  font-weight: 600;
}

.player-pending-id {
  font-size: 0.75rem;
  color: var(--muted);
}

.player-pending-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.player-pending-empty {
  margin: 0;
  font-size: 0.875rem;
}

.history-detail-meta {
  margin-bottom: 0.75rem;
}

.history-detail-versus {
  margin: 0 0 0.75rem;
  font-weight: 600;
  font-size: 0.95rem;
}

.history-detail-players {
  display: grid;
  gap: 0.85rem;
  margin-bottom: 0.5rem;
}

@media (min-width: 520px) {
  .history-detail-players {
    grid-template-columns: 1fr 1fr;
  }
}

.history-detail-player {
  font-size: 0.875rem;
  padding: 0.65rem 0.75rem;
  background: #f9fafb;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.history-detail-player strong {
  display: block;
  margin-bottom: 0.4rem;
}

.history-detail-times {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--muted);
  line-height: 1.5;
}

.history-detail-briefing {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.table-scroll {
  overflow-x: auto;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
  border-radius: 8px;
}

.btn-pastel-info {
  background: #e0f2fe;
  border-color: #7dd3fc;
  color: #0369a1;
  box-shadow: none;
}

.btn-pastel-info:hover {
  background: #bae6fd;
  border-color: #38bdf8;
}

.btn-pastel-primary {
  background: #f4faeb;
  border-color: #cfe8c4;
  color: #4a6b3a;
  box-shadow: none;
  text-decoration: none;
}

.btn-pastel-primary:hover {
  background: #eaf6e0;
  border-color: #b8d9a8;
  color: #3d5a30;
}

.btn-pastel-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 1.35rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-decoration: none;
  border-radius: 999px;
  border: 1px solid #c5e3b8;
  background: #f2f9ec;
  color: #3d6b32;
  box-shadow: none;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn-pastel-cta:hover {
  background: #e8f4df;
  border-color: #a8d498;
  color: #2f5428;
}

.player-profile-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

@media (min-width: 800px) {
  .player-profile-grid {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

.player-profile-grid .player-profile-card {
  max-width: none;
  margin-bottom: 0;
}

.player-profile-card {
  max-width: 420px;
  margin-bottom: 1rem;
}

.player-profile-field {
  margin: 0 0 0.85rem;
  font-size: 0.95rem;
}

.player-profile-field:last-child {
  margin-bottom: 0;
}

.match-cta-card {
  border-left: 4px solid var(--brand2);
}

.match-cta-card .btn-primary {
  margin-top: 0.75rem;
}

.empty-hint {
  color: var(--muted);
  font-size: 0.95rem;
}

/* Challenge */
.challenge-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 1rem;
  padding-bottom: calc(0.5rem + 3px);
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.85rem;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.challenge-header::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--brand1), var(--brand2), #7dd3fc);
  pointer-events: none;
}

.challenge-header-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 1rem;
  min-width: 0;
  flex: 1;
}

.challenge-header-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0;
  flex-shrink: 0;
  margin-left: auto;
}

@media (max-width: 520px) {
  .challenge-header-tools {
    width: 100%;
    margin-left: 0;
    margin-top: 0.15rem;
    padding-top: 0.45rem;
    border-top: 1px solid var(--border);
    justify-content: space-between;
    gap: 0.5rem 0.75rem;
  }

  .challenge-header-timebox {
    width: auto;
    flex: 1;
    min-width: 0;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    border-left: 0;
    padding-left: 0;
    margin-left: 0;
    margin-right: 0;
    border-top: 0;
    padding-top: 0;
    margin-top: 0;
  }

  .challenge-header-actions {
    border-left: 0;
    padding-left: 0;
    flex: 1 1 auto;
    justify-content: flex-end;
  }
}

.challenge-header-left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.65rem;
  min-width: 0;
  flex: 1;
}

.challenge-kind-pill {
  flex-shrink: 0;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #14532d;
  padding: 0.32rem 0.65rem;
  border-radius: 6px;
  border: 1px solid color-mix(in srgb, var(--brand2) 35%, transparent);
  background: linear-gradient(
    135deg,
    color-mix(in srgb, var(--brand1) 28%, white),
    color-mix(in srgb, var(--brand2) 22%, white)
  );
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55);
  user-select: none;
  pointer-events: none;
}

.challenge-competition-title {
  font-size: 0.9rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  min-width: 0;
  line-height: 1.25;
}

.challenge-header-timebox {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 0.1rem;
  padding-left: 0.85rem;
  margin-left: 0.25rem;
  margin-right: 1.1rem;
  border-left: 1px solid var(--border);
  min-height: 2.25rem;
}

.challenge-timebox-title {
  font-size: 0.65rem;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.challenge-header-timebox .challenge-timer-digits {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.challenge-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  justify-content: flex-end;
  border-left: 1px solid var(--border);
  padding-left: 0.85rem;
  min-height: 2.25rem;
  align-self: center;
}

.challenge-header button[hidden] {
  display: none !important;
}

.challenge-header-err {
  width: 100%;
  margin: 0;
}

.btn-challenge-tool {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  border-radius: 999px;
}

.challenge-header .btn-pastel-cta {
  padding: 0.4rem 0.95rem;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
}

.btn-pastel-danger {
  background: #ffe4e6;
  border-color: #fda4af;
  color: #9f1239;
  box-shadow: none;
  font-weight: 600;
}

.btn-pastel-danger:hover {
  background: #fecdd3;
  border-color: #fb7185;
  color: #881337;
  filter: none;
}

.btn-pastel-salir {
  background: #ede9fe;
  border-color: #c4b5fd;
  color: #5b21b6;
  box-shadow: none;
  font-weight: 600;
  text-decoration: none;
}

.btn-pastel-salir:hover {
  background: #ddd6fe;
  border-color: #a78bfa;
  color: #4c1d95;
}

.challenge-briefing-modal-panel {
  max-width: min(640px, 96vw);
}

.challenge-frame-wrap {
  height: calc(100vh - 72px);
}

.challenge-frame-wrap iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

.challenge-blocked {
  padding: 3rem 1.5rem;
  text-align: center;
  max-width: 420px;
  margin: 2rem auto;
}

.challenge-blocked p {
  margin-bottom: 1.25rem;
  color: var(--muted);
}

.brief-blocked {
  max-width: 480px;
}

.brief-blocked p {
  margin-bottom: 1rem;
}

.ql-editor {
  min-height: 120px;
}

.quill-modal-host .ql-container {
  min-height: 140px;
}

.briefing-body {
  margin: 1rem 0;
}

.briefing-cta-wrap {
  display: flex;
  justify-content: center;
  margin-top: 1.75rem;
  padding-top: 0.5rem;
}

.briefing-body img {
  max-width: 100%;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(17, 24, 39, 0.45);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  overflow-y: auto;
}

.modal-backdrop[hidden] {
  display: none !important;
}

.modal-panel {
  width: 100%;
  max-width: 520px;
  max-height: min(90vh, 720px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 650;
}

.modal-close-btn {
  border: none;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 0.25rem;
  border-radius: 8px;
}

.modal-close-btn:hover {
  background: #f3f4f6;
  color: var(--text);
}

.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
}

#matchModal .modal-panel {
  max-width: 640px;
}

#historyDetailModal .modal-panel {
  max-width: min(640px, 96vw);
}

.admin-result-timing {
  display: grid;
  gap: 0.85rem;
  margin: 0.75rem 0 0;
}

@media (min-width: 640px) {
  .admin-result-timing {
    grid-template-columns: 1fr 1fr;
  }
}

.admin-result-player-block {
  padding: 0.65rem 0.75rem;
  background: #f9fafb;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 0.875rem;
}

.admin-result-player-title {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  font-weight: 650;
}

.admin-result-time-list {
  margin: 0;
  padding-left: 1.1rem;
  line-height: 1.55;
  color: var(--text);
}

.admin-result-time-label {
  color: var(--muted);
  font-weight: 500;
}
