:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #f59e0b;
  --accent-hover: #fbbf24;
  --danger: #ef4444;
  --border: #334155;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-2: #f1f5f9;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.4;
  min-height: 100vh;
  overscroll-behavior-y: none;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 12px) 20px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.top-bar h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 24px;
  padding: 6px 10px;
  border-radius: 10px;
}

.icon-btn:hover, .icon-btn:active {
  background: var(--surface-2);
}

.view {
  padding: 16px 20px calc(100px + var(--safe-bottom));
  max-width: 640px;
  margin: 0 auto;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 8px;
  text-align: center;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--accent);
}

.stat-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

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

.date-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.date-header {
  padding: 10px 16px;
  background: var(--surface-2);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

.date-label {
  font-weight: 600;
  font-size: 15px;
  text-transform: capitalize;
}

.date-summary {
  color: var(--text-muted);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.date-games {
  list-style: none;
  padding: 0;
  margin: 0;
}

.game-item {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  transition: transform 0.08s ease;
}

.game-item + .game-item {
  border-top: 1px solid var(--border);
}

.game-item:active { transform: scale(0.99); }

.game-score {
  font-size: 26px;
  font-weight: 700;
  color: var(--accent);
  min-width: 56px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

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

.game-location {
  font-size: 15px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-notes {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
}

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(20px + var(--safe-bottom));
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--accent);
  color: #0f172a;
  border: none;
  font-size: 32px;
  font-weight: 300;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
}

.fab:hover { background: var(--accent-hover); }
.fab:active { transform: scale(0.95); }

/* Dialog */
.dialog {
  border: none;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 20px;
  width: min(440px, calc(100% - 32px));
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.dialog h2 {
  margin: 0 0 16px;
  font-size: 20px;
}

.dialog h3 {
  margin: 0 0 6px;
  font-size: 16px;
}

.dialog label {
  display: block;
  margin-bottom: 14px;
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 500;
}

.dialog input, .dialog textarea {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  margin-top: 6px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font: inherit;
  font-size: 17px;
}

.dialog input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  min-height: 46px;
}

.location-label {
  display: block;
  position: relative;
  margin-bottom: 14px;
}

.dialog .location-label > label {
  display: block;
  margin-bottom: 0;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
}

.location-field {
  position: relative;
  margin-top: 6px;
}

.dialog .location-field input {
  margin-top: 0;
  padding-right: 48px;
}

.location-chevron {
  position: absolute;
  right: 4px;
  top: 4px;
  bottom: 4px;
  width: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-muted);
  border-radius: 8px;
  padding: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
  z-index: 2;
}

.location-chevron:hover,
.location-chevron:active {
  background: var(--border);
  color: var(--text);
}

.location-chevron svg {
  pointer-events: none;
  display: block;
}

.scores-section {
  margin-bottom: 14px;
}

.scores-label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 500;
}

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

.score-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.dialog .score-row input {
  flex: 1;
  margin-top: 0;
  min-width: 0;
}

.score-remove {
  width: 46px;
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 10px;
  font-size: 22px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
}

.score-remove:hover,
.score-remove:active {
  color: var(--danger);
  border-color: var(--danger);
}

.add-score {
  margin-top: 10px;
  width: 100%;
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-muted);
  padding: 12px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.add-score:hover,
.add-score:active {
  border-style: solid;
  color: var(--text);
  background: var(--surface-2);
}

.add-score[hidden] { display: none; }

.category-group {
  margin-bottom: 14px;
}

.category-label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 500;
}

.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.seg-btn {
  flex: 1;
  padding: 10px 6px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s;
}

.seg-btn.active {
  background: var(--accent);
  color: #0f172a;
}

.game-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

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

.game-category {
  flex-shrink: 0;
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.category-pratique { background: rgba(148, 163, 184, 0.18); color: var(--text-muted); }
.category-ligue    { background: rgba(96, 165, 250, 0.18); color: #60a5fa; }
.category-tournoi  { background: rgba(245, 158, 11, 0.20); color: var(--accent); }

.location-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  list-style: none;
  margin: 4px 0 0;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 10;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.location-suggestions li {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text);
  font-size: 16px;
}

.location-suggestions li:hover,
.location-suggestions li:active {
  background: var(--border);
}

.location-suggestions[hidden] { display: none; }

.dialog input:focus, .dialog textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.dialog textarea { resize: vertical; min-height: 72px; }

.dialog-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
  flex-wrap: wrap;
}

.spacer { flex: 1; }

.btn-primary, .btn-secondary, .btn-danger {
  padding: 11px 18px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 15px;
}

.btn-primary {
  background: var(--accent);
  color: #0f172a;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--border); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.btn-danger:hover { background: rgba(239, 68, 68, 0.1); }

.file-label {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.settings-section {
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.settings-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.sync-status {
  background: var(--surface-2);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  color: var(--text-muted);
  margin: 8px 0;
}

.sync-status.connected {
  color: #10b981;
}

.sync-status.error {
  color: var(--danger);
}

.muted {
  color: var(--text-muted);
  font-size: 14px;
  margin: 4px 0 8px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(100px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-2);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
  max-width: calc(100% - 40px);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
