:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --border: #2f3f56;
  --text: #e8edf4;
  --text-muted: #8b9cb3;
  --accent: #3dd68c;
  --accent-dim: #2a9d63;
  --gold: #f0c14b;
  --danger: #f07178;
  --profit: #3dd68c;
  --loss: #f07178;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --nav-height: 72px;
  --header-height: 88px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
  overflow-x: hidden;
}

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: linear-gradient(180deg, var(--bg) 70%, transparent);
  padding: calc(12px + var(--safe-top)) 16px 8px;
}

.header-inner {
  max-width: 640px;
  margin: 0 auto;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.sync-status {
  font-size: 0.68rem;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  white-space: nowrap;
}

.sync-synced { color: var(--accent); background: rgba(61, 214, 140, 0.12); }
.sync-syncing { color: var(--gold); background: rgba(240, 193, 75, 0.12); }
.sync-error { color: var(--danger); background: rgba(240, 113, 120, 0.12); }

.account-btn {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

.account-btn:active {
  transform: scale(0.97);
}

.auth-screen {
  display: flex;
  justify-content: center;
  padding: 8px 0 24px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.auth-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}

.auth-card h2 {
  font-size: 1.3rem;
  margin-bottom: 8px;
}

.auth-subtitle {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-bottom: 20px;
}

.auth-toggle {
  margin-top: 16px;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.auth-offline-btn {
  margin-top: 12px;
}

.auth-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-bottom: 12px;
  text-align: left;
}

.auth-success {
  color: var(--accent);
  font-size: 0.85rem;
  margin-bottom: 12px;
  text-align: left;
}

.setup-steps {
  padding-left: 20px;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.setup-steps li {
  margin-bottom: 12px;
}

.setup-steps code {
  font-size: 0.8rem;
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--text);
}

.setup-steps a {
  color: var(--accent);
}

.logo {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.tagline {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.main {
  flex: 1;
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
  padding: 8px 16px calc(var(--nav-height) + var(--safe-bottom) + 16px);
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 20;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.7rem;
  transition: color 0.15s;
}

.nav-btn.active {
  color: var(--accent);
}

.nav-icon {
  font-size: 1.35rem;
  line-height: 1;
}

.section-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 20px 0 10px;
}

.section-title:first-child {
  margin-top: 4px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card-clickable {
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.card-clickable:hover,
.card-clickable:active {
  background: var(--surface-2);
  border-color: var(--accent-dim);
}

.hero-card {
  background: linear-gradient(135deg, #1a2332 0%, #1e3a2f 100%);
  border-color: var(--accent-dim);
  text-align: center;
  padding: 24px 16px;
}

.hero-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.hero-amount {
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin: 4px 0;
}

.hero-amount.positive { color: var(--profit); }
.hero-amount.negative { color: var(--loss); }

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

.stat-box {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: center;
}

.stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-value {
  font-size: 1.25rem;
  font-weight: 600;
  margin-top: 4px;
}

.stat-value.expense { color: var(--danger); }
.stat-value.prize { color: var(--gold); }

.event-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.event-name {
  font-size: 1.05rem;
  font-weight: 600;
}

.event-meta {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.event-profit {
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  margin-top: 8px;
  margin-right: 4px;
}

.cp-value {
  font-weight: 700;
  color: #ffcb6b;
  white-space: nowrap;
}

.cp-slots {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.cp-slot {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
}

.cp-slot-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.cp-slot-value {
  font-size: 1.2rem;
  font-weight: 700;
  margin-top: 4px;
}

.cp-slot-cp {
  font-size: 0.82rem;
  color: #ffcb6b;
  margin-top: 2px;
}

.player-card-header {
  margin-bottom: 16px;
}

.player-card-header h2 {
  font-size: 1.4rem;
  font-weight: 700;
}

.player-cp-hero {
  margin-bottom: 16px;
}

.finish-list {
  padding: 4px 0;
}

.finish-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

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

.finish-row-muted {
  opacity: 0.55;
}

.finish-event {
  font-weight: 600;
  font-size: 0.92rem;
}

.finish-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.finish-cp {
  font-weight: 700;
  color: #ffcb6b;
  white-space: nowrap;
}

.badge.result {
  background: rgba(61, 214, 140, 0.15);
  color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  width: 100%;
}

.btn:active {
  transform: scale(0.98);
}

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

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

.btn-danger {
  background: rgba(240, 113, 120, 0.15);
  color: var(--danger);
  border: 1px solid rgba(240, 113, 120, 0.3);
}

.btn-sm {
  padding: 8px 14px;
  font-size: 0.85rem;
  width: auto;
}

.btn-row {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.btn-row .btn {
  flex: 1;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  appearance: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.form-group textarea {
  min-height: 80px;
  resize: vertical;
}

.form-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.expense-list {
  list-style: none;
}

.expense-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.expense-item:last-child {
  border-bottom: none;
}

.expense-item-clickable {
  cursor: pointer;
  transition: background 0.15s;
  border-radius: var(--radius-sm);
  margin: 0 -8px;
  padding-left: 8px;
  padding-right: 8px;
}

.expense-item-clickable:active {
  background: var(--surface-2);
}

.expense-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.expense-details {
  flex: 1;
  min-width: 0;
}

.expense-category {
  font-weight: 600;
  font-size: 0.92rem;
}

.expense-note {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.expense-amount {
  font-weight: 600;
  color: var(--danger);
  white-space: nowrap;
}

.receipt-thumb {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  cursor: pointer;
  border: 1px solid var(--border);
}

.receipt-preview {
  width: 100%;
  max-height: 200px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  margin-top: 8px;
  border: 1px solid var(--border);
}

.receipt-upload {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s;
  text-align: center;
}

.receipt-upload:hover,
.receipt-upload.has-image {
  border-color: var(--accent-dim);
}

.receipt-upload input {
  display: none;
}

.receipt-upload-icon {
  font-size: 2rem;
}

.receipt-upload-text {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 4px;
}

.photos-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.photos-edit-hint {
  margin: 0;
  flex: 1;
}

.photo-grid-editing .photo-item {
  cursor: grab;
}

.photo-grid-editing .photo-item:active {
  cursor: grabbing;
}

.photo-item-dragging {
  opacity: 0.5;
}

.photo-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}

.photo-favorite {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  color: rgba(255, 255, 255, 0.85);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.photo-favorite-active {
  background: rgba(240, 193, 75, 0.95);
  color: #1a1200;
}

.photo-favorite-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(240, 193, 75, 0.95);
  color: #1a1200;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 1;
}

.favorite-photos-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.favorite-photo-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.favorite-photo-event-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.favorite-photo-date {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: -2px;
}

.photo-edit-controls {
  position: absolute;
  inset: auto 0 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
}

.photo-move,
.photo-delete {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.photo-move:disabled {
  opacity: 0.35;
  cursor: default;
}

.photo-delete {
  background: rgba(180, 40, 50, 0.9);
  font-size: 0.75rem;
}

.photo-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: pointer;
  display: block;
}

.photo-thumb-loading {
  background: var(--surface-2);
}

.photo-thumb-missing {
  background: var(--surface-2);
  opacity: 0.55;
}

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

.empty-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}

.empty-state h3 {
  color: var(--text);
  font-size: 1.1rem;
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 0.88rem;
  margin-bottom: 20px;
}

.confirm-message {
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.5;
  margin-bottom: 20px;
}

.confirm-actions {
  display: flex;
  gap: 10px;
}

.confirm-actions .btn {
  flex: 1;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

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

.modal {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 640px;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 20px 16px calc(20px + var(--safe-bottom));
  animation: slideUp 0.25s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
}

.modal-close {
  background: var(--surface-2);
  border: none;
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 16px;
}

.tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
}

.tab.active {
  background: var(--surface);
  color: var(--text);
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.category-btn {
  padding: 12px 8px;
  background: var(--surface-2);
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s;
}

.category-btn .cat-icon {
  display: block;
  font-size: 1.3rem;
  margin-bottom: 4px;
}

.category-btn.selected {
  border-color: var(--accent);
  background: rgba(61, 214, 140, 0.1);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--accent);
  font-size: 0.88rem;
  font-weight: 600;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  margin-bottom: 12px;
}

.detail-header {
  margin-bottom: 16px;
}

.detail-header h2 {
  font-size: 1.4rem;
  font-weight: 700;
}

.detail-header .event-meta {
  margin-top: 6px;
}

.prizing-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.prizing-item:last-child {
  border-bottom: none;
}

.prizing-item-clickable {
  cursor: pointer;
  transition: background 0.15s;
  border-radius: var(--radius-sm);
  margin: 0 -8px;
  padding-left: 8px;
  padding-right: 8px;
}

.prizing-item-clickable:active {
  background: var(--surface-2);
}

.prizing-desc {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.9rem;
}

.prizing-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.prize-total-preview {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-weight: 600;
  color: var(--gold);
  margin-bottom: 16px;
  text-align: center;
}

.prizing-amount {
  font-weight: 600;
  color: var(--gold);
}

/* Season report */
.report-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.report-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.report-export-btn {
  flex-shrink: 0;
  margin-top: 4px;
}

.report-table-wrap {
  padding: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 20px;
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.report-table th,
.report-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.report-table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--surface-2);
}

.report-table tbody tr:last-child td {
  border-bottom: none;
}

.report-table td:first-child,
.report-table th:first-child {
  position: sticky;
  left: 0;
  background: var(--surface);
  z-index: 1;
}

.report-table th:first-child {
  background: var(--surface-2);
  z-index: 2;
}

.report-empty {
  color: var(--text-muted);
  text-align: center;
  white-space: normal;
}

.report-money.positive { color: var(--gold); }
.report-money.negative { color: var(--loss); }

.hidden {
  display: none !important;
}

@media (min-width: 641px) {
  .modal-overlay {
    align-items: center;
    padding: 20px;
  }

  .modal {
    border-radius: var(--radius);
    max-height: 85vh;
  }

  .bottom-nav {
    max-width: 640px;
    left: 50%;
    transform: translateX(-50%);
    border-radius: var(--radius) var(--radius) 0 0;
  }
}
