: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: 10px;
}

.game-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  transition: transform 0.08s ease;
}

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

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

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

.game-date {
  font-weight: 600;
  font-size: 16px;
}

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

.game-notes {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
  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%;
  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: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);
}
