:root {
  --bg-primary: #0b0b0b;
  --bg-secondary: #151515;
  --bg-elevated: #1a1a1a;
  --bg-hover: #1f1f1f;
  --border: #2b2b2b;
  --border-strong: #4a4a4a;
  --text-primary: #f2f2f2;
  --text-muted: #ababab;
  --accent-cyan: #ffffff;
  --accent-purple: #d8d8d8;
  --success: #f2f2f2;
  --warning: #d0d0d0;
  --error: #f2f2f2;
  --radius: 16px;
  --shadow: 0 16px 36px rgba(0, 0, 0, 0.33);
  --space-mobile: 16px;
  --space-desktop: 24px;
  --tap-min: 44px;
  --text-sm: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  font-family: "Manrope", "Segoe UI", Arial, sans-serif;
  font-size: var(--text-sm);
  line-height: 1.45;
  color: var(--text-primary);
  background:
    radial-gradient(90% 65% at 50% -8%, rgba(255, 255, 255, 0.08) 0%, transparent 60%),
    linear-gradient(180deg, #121212 0%, #0a0a0a 100%);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.12;
  background-image:
    linear-gradient(45deg, rgba(255, 255, 255, 0.08) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(220, 220, 220, 0.08) 25%, transparent 25%);
  background-size: 28px 28px;
  mix-blend-mode: screen;
}

.hidden { display: none !important; }

.app-shell {
  max-width: 980px;
  margin: 0 auto;
  padding: var(--space-mobile);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, #1a1a1a 0%, #101010 100%);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 8px;
  z-index: 10;
  backdrop-filter: blur(6px);
}

h1, h2, h3, p { margin: 0; }

h1 {
  font-family: "Bodoni Moda", Georgia, serif;
  font-size: 27px;
  letter-spacing: 0.5px;
  color: var(--text-primary);
}

h2 {
  font-family: "Bodoni Moda", Georgia, serif;
  letter-spacing: 0.2px;
  font-size: 26px;
  line-height: 1.1;
}

h3 {
  font-family: "Bodoni Moda", Georgia, serif;
  font-size: 22px;
  line-height: 1.2;
}

.brand-kicker {
  font-size: 10px;
  color: #d3d3d3;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  margin-bottom: 3px;
}

#whoami { color: var(--text-muted); margin-top: 4px; font-size: 13px; }

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 12px 0;
}

.tab {
  border: 1px solid var(--border);
  background: linear-gradient(180deg, #1a1a1a 0%, #131313 100%);
  color: var(--text-muted);
  border-radius: 12px;
  min-height: var(--tap-min);
  padding: 10px;
  font-weight: 700;
  font-size: 13px;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease, color 140ms ease;
}

.tab.active {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.13), rgba(185, 185, 185, 0.13));
  border-color: rgba(255, 255, 255, 0.45);
  color: var(--text-primary);
}

.tab:active {
  transform: translateY(1px);
}

.panel {
  display: none;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, #171717 0%, #101010 100%);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.panel.active { display: block; }

.auth-panel {
  margin-top: 12px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding-top: 28px;
  padding-bottom: 28px;
}

.hero-copy {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.auth-logo {
  width: 24px;
  height: 24px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: #fff;
}

.stack {
  display: grid;
  gap: 8px;
  margin: 10px 0 14px;
}

.field {
  display: grid;
  gap: 6px;
  width: 100%;
}

.field label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.hint {
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 13px;
  max-width: 64ch;
}

.max-read {
  max-width: 64ch;
}

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

.inline-row input {
  flex: 1 1 220px;
}

.photo-row input {
  flex: 1 1 220px;
}

.lichess-row {
  align-items: center;
}

.control-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  width: 100%;
}

.field-row .control-row > * {
  height: var(--tap-min);
}

.lichess-input {
  flex: 0 1 210px !important;
  max-width: 210px;
}

input, select, textarea, button { font: inherit; }

input, select, textarea {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #101010;
  color: var(--text-primary);
  min-height: var(--tap-min);
  padding: 10px 12px;
  width: 100%;
}

input::placeholder, textarea::placeholder { color: var(--text-muted); }

input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(255, 255, 255, 0.62);
  outline-offset: 1px;
}

textarea { min-height: 70px; resize: vertical; }

.btn {
  border: 1px solid rgba(255, 255, 255, 0.38);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.12), rgba(175, 175, 175, 0.08));
  color: #f7f7f7;
  border-radius: 12px;
  min-height: var(--tap-min);
  padding: 9px 12px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 130ms ease, filter 130ms ease;
}

#profileForm .btn {
  min-height: var(--tap-min);
}

.btn:hover { filter: brightness(1.12); transform: translateY(-1px); }
.btn:active { filter: brightness(1.06); transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: wait; transform: none; }

.btn.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.25);
  color: #d9d9d9;
}

.error {
  margin-top: 10px;
  color: var(--error);
  font-weight: 700;
}

.cards {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.card {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: linear-gradient(180deg, #1a1a1a 0%, #121212 100%);
  padding: 14px;
  animation: cardIn 180ms ease-out;
}

.card .meta {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 4px;
  word-break: break-word;
}

.today-layout {
  display: grid;
  gap: 12px;
}

.hero-card {
  background: linear-gradient(145deg, #202020 0%, #121212 100%);
  border-color: var(--border-strong);
}

.quick-actions .btn {
  min-width: 170px;
}

.agenda-list {
  margin-top: 10px;
  display: grid;
  gap: 8px;
}

.agenda-item {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 8px;
  align-items: center;
  min-height: 36px;
  padding: 6px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
}

.agenda-time {
  font-size: 12px;
  color: var(--text-muted);
}

.agenda-title {
  font-size: 14px;
}

.puzzle-board {
  width: 100%;
  max-width: 340px;
  margin-top: 8px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #3a3a3a;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

.lichess-board {
  aspect-ratio: 1 / 1;
}

.lichess-board.cg-wrap {
  width: 100%;
  margin: 0;
}

.tag {
  display: inline-block;
  font-size: 12px;
  color: #d5d5d5;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 2px 8px;
  margin-right: 6px;
  margin-top: 6px;
}

.card .row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.participant-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.participant-row img {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--border);
  flex: 0 0 auto;
}

.participant-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.tg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.1);
  color: #f7f7f7;
  text-decoration: none;
  font-size: 15px;
}

.filters { margin: 8px 0 12px; }
main { display: grid; gap: 10px; }

.loading {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  min-height: var(--tap-min);
}

.loading-skeleton {
  display: grid;
  gap: 8px;
  min-height: 120px;
}

.skeleton-row {
  height: 14px;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(255,255,255,0.08), rgba(255,255,255,0.18), rgba(255,255,255,0.08));
  background-size: 220% 100%;
  animation: shimmer 1.2s linear infinite;
}

.skeleton-row.w-50 { width: 50%; }
.skeleton-row.w-80 { width: 80%; }

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

.empty-state {
  min-height: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 30px;
  opacity: 0.5;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.58);
  z-index: 20;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  background: #151515;
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 13px;
  max-width: min(92vw, 460px);
  text-align: center;
  z-index: 30;
}

.toast.success {
  background: #191919;
  color: #f0f0f0;
  border-color: rgba(255, 255, 255, 0.4);
}

.toast.error {
  background: #1a1a1a;
  border-color: rgba(255, 255, 255, 0.7);
  color: #ffffff;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1;
}

.grade-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  font-size: 12px;
  background: rgba(255, 255, 255, 0.05);
}

.grade-novice { color: #d9d9d9; }
.grade-amateur { color: #e8e8e8; border-color: rgba(255,255,255,0.4); }
.grade-strong { color: #f3f3f3; border-color: rgba(255,255,255,0.58); }
.grade-tournament { color: #ffffff; border-color: rgba(255,255,255,0.75); }

.chip-accent {
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: #f2f2f2;
  background: rgba(255, 255, 255, 0.12);
}

.row-between {
  justify-content: space-between;
  align-items: center;
}

.events-overview {
  background: linear-gradient(180deg, #1b1b1b 0%, #121212 100%);
}

.events-overview-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.events-kpis {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.kpi {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  padding: 10px;
  display: grid;
  gap: 4px;
}

.kpi-label {
  color: var(--text-muted);
  font-size: 12px;
}

.kpi-value {
  font-family: "Bodoni Moda", Georgia, serif;
  font-size: 20px;
  line-height: 1;
}

.event-group {
  margin-top: 10px;
}

.month-calendar {
  background: linear-gradient(180deg, #1b1b1b 0%, #111111 100%);
}

.calendar-weekdays {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.calendar-tools {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.calendar-tools .btn {
  min-height: 40px;
  padding: 6px 12px;
}

.calendar-weekdays span {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
}

.calendar-grid {
  margin-top: 6px;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.cal-day {
  border: 1px solid var(--border);
  border-radius: 12px;
  min-height: var(--tap-min);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.015));
  color: var(--text-primary);
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 1px;
  padding: 6px 4px;
}

.cal-day-num {
  font-weight: 800;
  font-size: 14px;
  line-height: 1;
}

.cal-day-month {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1;
}

.cal-day-count {
  margin-top: 3px;
  min-width: 20px;
  min-height: 16px;
  padding: 0 6px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.3);
  font-size: 11px;
  background: rgba(255, 255, 255, 0.1);
}

.cal-day-count.empty {
  opacity: 0.45;
  border-style: dashed;
}

.cal-day-label {
  font-size: 10px;
  color: var(--text-muted);
}

.cal-day.is-today {
  border-color: rgba(255, 255, 255, 0.62);
}

.cal-day.is-active {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.2), rgba(200, 200, 200, 0.1));
  border-color: rgba(255, 255, 255, 0.78);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.event-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 10px 2px 8px;
}

.event-group-head h3 {
  font-size: 20px;
  text-transform: capitalize;
}

.event-card {
  background: linear-gradient(180deg, #191919 0%, #111111 100%);
}

.event-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.event-timeline-row {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 10px;
  align-items: start;
}

.event-time-pin {
  position: sticky;
  top: 82px;
  min-height: 30px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.38);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  font-size: 12px;
  background: rgba(255,255,255,0.08);
}

.event-meta-grid {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 10px;
}

.event-people {
  margin-top: 8px;
}

.event-description {
  margin-top: 8px;
  line-height: 1.5;
}

.event-timing {
  margin-top: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  display: grid;
  gap: 4px;
}

.event-actions .btn {
  min-width: 160px;
}

.progress {
  margin-top: 8px;
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  overflow: hidden;
}

.progress > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #ffffff, #bfbfbf);
}

.mobile-tabs {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  gap: 8px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  background: rgba(16, 16, 16, 0.96);
  border-top: 1px solid var(--border);
  z-index: 35;
}

.mobile-tab {
  min-height: var(--tap-min);
  min-width: 96px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  padding: 8px 6px;
  flex: 0 0 auto;
  scroll-snap-align: start;
}

.mobile-tab.active {
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.48);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.13), rgba(185, 185, 185, 0.13));
}

@media (max-width: 760px) {
  .app-shell { padding: var(--space-mobile); }
  .tabs { display: none; }
  .mobile-tabs { display: flex; }
  main { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
  h1 { font-size: 22px; }
  h2 { font-size: 24px; }
  .auth-logo { width: 20px; height: 20px; border-radius: 4px; }
  .section-head { align-items: flex-start; flex-direction: column; }
  #profileBtn {
    position: static;
    transform: none;
    min-height: var(--tap-min);
    min-width: auto;
    padding: 0 12px;
    box-shadow: none;
    min-width: 108px;
  }
  .events-kpis {
    grid-template-columns: 1fr;
  }
  .calendar-weekdays span {
    font-size: 11px;
  }
  .cal-day {
    padding: 6px 2px;
    gap: 0;
  }
  .cal-day-month,
  .cal-day-label {
    display: none;
  }
  .cal-day-count {
    margin-top: 4px;
    min-width: 18px;
    min-height: 14px;
    font-size: 10px;
  }
  .event-card-top {
    flex-direction: column;
  }
  .event-timeline-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .event-time-pin {
    position: static;
    width: fit-content;
  }
  .event-meta-grid {
    grid-template-columns: 1fr;
  }
  .event-actions .btn {
    width: 100%;
    min-width: 0;
  }
  body.profile-open #profile {
    position: fixed;
    left: var(--space-mobile);
    right: var(--space-mobile);
    bottom: calc(var(--space-mobile) + env(safe-area-inset-bottom));
    max-height: 82vh;
    overflow-y: auto;
    z-index: 40;
  }
}

@media (max-width: 420px) {
  .mobile-tab { min-width: 86px; }
  .inline-row { flex-direction: column; }
  .lichess-input { max-width: 100%; }
  .control-row { grid-template-columns: 1fr; }
  .quick-actions .btn { width: 100%; min-width: 0; }
  .agenda-item { grid-template-columns: 56px 1fr; }
}

@media (min-width: 761px) {
  .app-shell { padding: var(--space-desktop); }
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.7);
  outline-offset: 2px;
}

body.profile-open #appContent .panel {
  display: none !important;
}

body.profile-open #appContent #profile {
  display: block !important;
}

body.profile-open .mobile-tabs {
  display: none !important;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes shimmer {
  to { background-position: -220% 0; }
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
  h3 { font-size: 19px; }
