:root {
  --bg: #0c1018;
  --bg-elevated: #141a26;
  --bg-card: #182030;
  --bg-input: #101622;
  --border: #263147;
  --border-strong: #374766;
  --text: #eef2ff;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --gold: #eab308;
  --gold-soft: rgba(234, 179, 8, 0.14);
  --accent: #3b82f6;
  --accent-bright: #60a5fa;
  --accent-soft: rgba(59, 130, 246, 0.18);

  --match-green: #22c55e;
  --match-green-bg: rgba(34, 197, 94, 0.88);
  --match-green-soft: rgba(34, 197, 94, 0.14);
  --match-orange: #f97316;
  --match-orange-bg: rgba(249, 115, 22, 0.9);
  --match-orange-soft: rgba(249, 115, 22, 0.15);

  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.14);

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);

  --col-check: 52px;
  --col-name: 200px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.bg-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 15% 10%, rgba(59, 130, 246, 0.12), transparent 40%),
    radial-gradient(circle at 85% 15%, rgba(234, 179, 8, 0.08), transparent 36%);
  z-index: 0;
}

.container {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 20px;
  position: relative;
  z-index: 1;
}

/* Topbar */
.topbar {
  border-bottom: 1px solid var(--border);
  background: rgba(12, 16, 24, 0.85);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 30;
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 60px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text);
}

.brand-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--gold-soft);
  border: 1px solid rgba(234, 179, 8, 0.35);
  color: var(--gold);
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-text strong {
  font-size: 16px;
  letter-spacing: -0.01em;
}

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

.topbar-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--match-green);
}

.status-dot.saving {
  background: var(--gold);
  animation: pulse 0.9s infinite alternate;
}

.status-dot.error {
  background: var(--danger);
}

@keyframes pulse {
  from { opacity: 0.4; }
  to { opacity: 1; }
}

.main-content {
  padding-top: 28px;
  padding-bottom: 64px;
}

/* Buttons & Controls */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-card);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  background: #202b40;
  border-color: #4a5e85;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

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

.btn-primary {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  border-color: #3b82f6;
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  border-color: #60a5fa;
}

.btn-gold {
  background: linear-gradient(135deg, #ca8a04, #a16207);
  border-color: #eab308;
  color: #fffbeb;
  box-shadow: 0 6px 20px rgba(234, 179, 8, 0.2);
}

.btn-gold:hover:not(:disabled) {
  background: linear-gradient(135deg, #eab308, #ca8a04);
  border-color: #fde047;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.06);
  border-color: transparent;
  color: var(--text);
}

.btn-danger {
  background: var(--danger-soft);
  border-color: rgba(239, 68, 68, 0.45);
  color: #fecaca;
}

.btn-danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.25);
  border-color: var(--danger);
}

.btn-sm {
  padding: 6px 10px;
  font-size: 12px;
}

.btn-icon {
  padding: 6px 8px;
}

.input, .select {
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus, .select:focus {
  border-color: var(--accent-bright);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18);
}

/* Page 1: Dates overview */
.page-hero {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.page-hero h1 {
  margin: 0 0 6px;
  font-size: 26px;
  letter-spacing: -0.02em;
}

.page-hero p {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
}

.dates-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 24px;
  align-items: start;
}

.dates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.date-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.15s, box-shadow 0.15s;
}

.date-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent-bright);
  box-shadow: var(--shadow);
}

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

.date-badge {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--gold-soft);
  border: 1px solid rgba(234, 179, 8, 0.3);
  text-align: center;
}

.date-badge .day {
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
  color: #fde047;
}

.date-badge .month {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--gold);
  margin-top: 3px;
}

.date-card-meta {
  flex: 1;
  min-width: 0;
}

.date-card-weekday {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: capitalize;
}

.date-card-title {
  margin: 3px 0 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.date-card-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.date-card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.card-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card-panel h2 {
  margin: 0 0 14px;
  font-size: 17px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.form-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* Page 2: Session Planner */
.planner-header {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.planner-title-group {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.planner-date-heading {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.planner-date-main {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.planner-date-main h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: -0.01em;
  text-transform: capitalize;
}

.planner-subtitle-input {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-family: inherit;
  padding: 3px 6px;
  border-radius: 6px;
  width: 260px;
  max-width: 100%;
  margin-left: -6px;
}

.planner-subtitle-input:hover {
  border-color: var(--border);
}

.planner-subtitle-input:focus {
  outline: none;
  background: var(--bg-input);
  border-color: var(--accent-bright);
  color: var(--text);
}

.planner-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.control-group {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  font-size: 12px;
  color: var(--text-muted);
}

.stepper {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.stepper-btn {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--bg-card);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.stepper-btn:hover:not(:disabled) {
  background: #233048;
  border-color: var(--accent-bright);
}

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

.stepper-value {
  min-width: 22px;
  text-align: center;
  font-weight: 700;
  color: var(--text);
  font-size: 13px;
}

.hint-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(59, 130, 246, 0.08);
  border: 1px solid rgba(59, 130, 246, 0.24);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 13px;
  color: #cbd5e1;
}

.hint-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.hint-steps span strong {
  color: var(--accent-bright);
}

.hover-readout {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--gold);
  min-height: 20px;
}

/* Schedule Grid */
.grid-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.grid-scroll {
  overflow-x: auto;
  overflow-y: visible;
}

.grid-table {
  min-width: 820px;
  width: 100%;
}

.grid-header-row,
.player-row,
.match-row {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--border);
}

.grid-header-row {
  background: var(--bg-elevated);
  min-height: 44px;
}

.col-check {
  width: var(--col-check);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-right: 1px solid var(--border);
  padding: 4px;
  gap: 2px;
}

.col-name {
  width: var(--col-name);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  border-right: 1px solid var(--border);
  padding: 6px 10px;
}

.col-timeline {
  flex: 1;
  min-width: 520px;
  position: relative;
  display: flex;
  align-items: stretch;
}

.col-header-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.select-all-btn {
  background: transparent;
  border: none;
  color: var(--accent-bright);
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
  padding: 1px 4px;
  border-radius: 4px;
}

.select-all-btn:hover {
  background: var(--accent-soft);
}

/* Time ruler */
.time-ruler {
  position: relative;
  width: 100%;
  height: 44px;
  user-select: none;
}

.ruler-tick {
  position: absolute;
  top: 0;
  bottom: 0;
  border-left: 1px solid rgba(148, 163, 184, 0.25);
  pointer-events: none;
}

.ruler-tick.end-tick {
  border-left: none;
  border-right: 1px solid rgba(148, 163, 184, 0.25);
}

.ruler-label {
  position: absolute;
  top: 13px;
  transform: translateX(-50%);
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  white-space: nowrap;
}

.ruler-tick:first-child .ruler-label {
  transform: translateX(2px);
}

.ruler-tick.end-tick .ruler-label {
  transform: translateX(-100%);
  padding-right: 3px;
}

/* Player rows */
.player-row {
  min-height: 48px;
  transition: background 0.12s;
}

.player-row:last-child {
  border-bottom: none;
}

.player-row.is-selected {
  background: rgba(59, 130, 246, 0.06);
}

.player-row:hover {
  background: rgba(255, 255, 255, 0.02);
}

.player-row.is-selected:hover {
  background: rgba(59, 130, 246, 0.09);
}

.gm-checkbox {
  width: 18px;
  height: 18px;
  accent-color: var(--gold);
  cursor: pointer;
}

.gm-checkbox:disabled {
  opacity: 0.25;
  cursor: not-allowed;
}

.row-num {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 700;
  width: 16px;
  text-align: right;
  flex-shrink: 0;
}

.nickname-input {
  width: 100%;
  min-width: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  padding: 6px 7px;
  transition: border-color 0.15s, background 0.15s;
}

.nickname-input::placeholder {
  color: var(--text-dim);
  font-weight: 400;
}

.nickname-input:hover {
  border-color: var(--border);
}

.nickname-input:focus {
  outline: none;
  background: var(--bg-input);
  border-color: var(--accent-bright);
}

.row-hours-badge {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--accent-bright);
  white-space: nowrap;
  flex-shrink: 0;
}

.row-clear-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  font-size: 13px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.12s, color 0.12s, background 0.12s;
}

.player-row:hover .row-clear-btn,
.row-clear-btn:focus-visible {
  opacity: 1;
}

.row-clear-btn:hover {
  color: #fca5a5;
  background: var(--danger-soft);
}

/* Timeline slots */
.slot-track {
  display: flex;
  width: 100%;
  user-select: none;
  touch-action: none;
}

.slot-cell {
  flex: 1;
  position: relative;
  border-right: 1px dashed rgba(148, 163, 184, 0.14);
  cursor: crosshair;
  transition: background 0.08s;
}

.slot-cell.hour-end {
  border-right: 1px solid rgba(148, 163, 184, 0.28);
}

.slot-cell:last-child {
  border-right: none;
}

.slot-cell:hover {
  background: rgba(255, 255, 255, 0.07);
}

.slot-cell.active {
  background: linear-gradient(180deg, #3b82f6, #2563eb);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.slot-cell.active:hover {
  background: linear-gradient(180deg, #60a5fa, #3b82f6);
}

/* Match Action & Result Bar */
.match-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 18px;
  padding: 16px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.match-selected-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.player-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--gold-soft);
  border: 1px solid rgba(234, 179, 8, 0.35);
  color: #fef08a;
  font-size: 12px;
  font-weight: 600;
}

.match-result-wrapper {
  margin-top: 16px;
  animation: fadeSlide 0.2s ease-out;
}

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

.match-stale-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  background: rgba(234, 179, 8, 0.12);
  border-bottom: 1px solid rgba(234, 179, 8, 0.3);
  color: #fde047;
  font-size: 12px;
  font-weight: 600;
}

.match-row {
  min-height: 58px;
  background: #121826;
  border-bottom: none;
}

.match-label-col {
  width: calc(var(--col-check) + var(--col-name));
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}

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

.match-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 11px;
  color: var(--text-muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.legend-swatch.green { background: var(--match-green); }
.legend-swatch.orange { background: var(--match-orange); }

.match-cell {
  flex: 1;
  position: relative;
  border-right: 1px dashed rgba(148, 163, 184, 0.14);
  cursor: pointer;
}

.match-cell.hour-end {
  border-right: 1px solid rgba(148, 163, 184, 0.28);
}

.match-cell:last-child {
  border-right: none;
}

.match-cell.status-full {
  background: var(--match-green-bg);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.match-cell.status-minus_one {
  background: var(--match-orange-bg);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.match-cell.status-none {
  background: rgba(15, 23, 42, 0.6);
}

.match-cell:hover {
  outline: 2px solid #fff;
  outline-offset: -2px;
  z-index: 2;
}

.match-inspector {
  padding: 10px 16px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  min-height: 38px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.match-summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 14px;
}

.summary-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.summary-box.green-box {
  border-color: rgba(34, 197, 94, 0.35);
}

.summary-box.orange-box {
  border-color: rgba(249, 115, 22, 0.35);
}

.summary-box h3 {
  margin: 0 0 10px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.interval-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.interval-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.green-box .interval-item {
  background: var(--match-green-soft);
  border: 1px solid rgba(34, 197, 94, 0.25);
}

.orange-box .interval-item {
  background: var(--match-orange-soft);
  border: 1px solid rgba(249, 115, 22, 0.25);
}

.interval-time {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

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

.missing-badge {
  color: #fed7aa;
  font-weight: 600;
}

.empty-state {
  text-align: center;
  padding: 36px 20px;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}

/* Modal & Toast */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 14, 0.72);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 20px;
}

.modal-backdrop.hidden {
  display: none;
}

.modal-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

.modal-card h3 {
  margin: 0 0 10px;
  font-size: 17px;
}

.modal-card p {
  margin: 0 0 18px;
  color: var(--text-muted);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.toast-container {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 120;
}

.toast {
  background: #1e293b;
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 500;
}

.toast.error {
  border-color: var(--danger);
  background: #33161b;
}

.loading-box {
  padding: 40px;
  text-align: center;
  color: var(--text-muted);
}

@media (max-width: 960px) {
  .dates-layout {
    grid-template-columns: 1fr;
  }
  .match-summary-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  :root {
    --col-check: 42px;
    --col-name: 145px;
  }
  .container {
    padding: 0 12px;
  }
  .planner-header {
    padding: 14px;
  }
}
