/* === RESET & BASE === */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: #0d0d0d;
  color: #ffffff;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
  /* Tela cheia: respeita câmera/notch em cima e a área de gestos embaixo */
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}

/* === SCREENS === */
.screen {
  display: none;
  animation: fadeIn 0.25s ease-out;
}
.screen.active {
  display: block;
}

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

/* === TELA PRINCIPAL - HEADER === */
.app-header {
  padding: 12px 0 16px;
  margin-bottom: 16px;
}

.checkered {
  height: 14px;
  width: 100%;
  background:
    conic-gradient(#fff 90deg, #333 90deg 180deg, #fff 180deg 270deg, #333 270deg);
  background-size: 14px 14px;
  border-radius: 2px;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0 6px;
  gap: 10px;
}

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

.app-header h1 {
  font-size: 20px;
  font-weight: 600;
  color: #ffffff;
  letter-spacing: 0.2px;
}

.btn-header {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  background: #ff4757;
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease;
  font-family: inherit;
  white-space: nowrap;
}
.btn-header:hover {
  opacity: 0.9;
}

.btn-setup {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid #444;
  background: transparent;
  color: #ffffff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, border-color 0.15s ease;
  flex-shrink: 0;
}
.btn-setup:hover {
  background: #2a2a2a;
  border-color: #666;
}

.version {
  font-size: 12px;
  color: #888;
  text-align: center;
  margin-top: 6px;
  letter-spacing: 0.5px;
}
.sync-status {
  font-weight: 600;
  letter-spacing: 0;
}
.sync-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid #4a4a4a;
}
.sync-row-label {
  font-size: 14px;
  color: #ccc;
}
.sync-row .sync-status {
  font-size: 14px;
}

/* === RECORD CARDS === */
.record-card {
  background: #3d3d3d;
  border: 1px solid #4a4a4a;
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 14px;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.2s ease;
  position: relative;
  cursor: pointer;
  overflow: hidden;
}
.record-card:hover {
  transform: translateX(3px);
  border-color: #666;
}
.record-card.expanded {
  background: #2a2a2a;
  border-color: #ff4757;
}

.record-rank {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #2a2a2a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: #ffffff;
  flex-shrink: 0;
  border: 1px solid #555;
  margin-top: 2px;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.record-card.expanded .record-rank {
  background: #ff4757;
  border-color: #ff4757;
}

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

.record-track {
  font-size: 13px;
  font-weight: 600;
  color: #ffffff;
  line-height: 1.4;
}
.record-track.has-setup {
  color: #3b82f6;
  cursor: pointer;
}
.record-track.has-setup:hover {
  text-decoration: underline;
}

.record-meta {
  font-size: 12px;
  color: #bbb;
  margin-top: 3px;
}

.record-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  flex-shrink: 0;
  gap: 2px;
}

.record-time {
  font-size: 20px;
  font-weight: 700;
  color: #ffffff;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  flex-shrink: 0;
  letter-spacing: 0.5px;
}

.record-best {
  font-size: 11px;
  color: #bbb;
  font-weight: 400;
}
.record-best-pos {
  color: #ffffff;
}

.delete-btn {
  position: absolute;
  right: 8px;
  top: 8px;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: #ff4757;
  font-size: 16px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}
.record-card:hover .delete-btn {
  opacity: 1;
}

.expand-icon {
  position: absolute;
  right: 12px;
  bottom: 10px;
  font-size: 11px;
  color: #666;
  transition: transform 0.3s ease, color 0.2s ease;
}
.record-card:hover .expand-icon { color: #999; }
.record-card.expanded .expand-icon {
  transform: rotate(180deg);
  color: #ff4757;
}

.empty-state {
  text-align: center;
  padding: 50px 20px;
  color: #888;
  font-size: 14px;
}
.empty-state p {
  margin-bottom: 8px;
}

/* === EXPANSÃO: REFERÊNCIA F1 === */
.record-details {
  width: 100%;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.25s ease 0.05s,
              margin-top 0.3s ease;
  margin-top: 0;
}
.record-card.expanded .record-details {
  max-height: 380px;
  opacity: 1;
  margin-top: 14px;
}

.details-divider {
  height: 1px;
  background: #444;
  margin-bottom: 14px;
}

.f1-ref-box {
  background: #1e1e1e;
  border: 1px solid #333;
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 12px;
}
.f1-ref-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.f1-ref-title {
  font-size: 11px;
  font-weight: 700;
  color: #ff4757;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}
.f1-ref-year {
  font-size: 10px;
  color: #888;
  background: #2a2a2a;
  padding: 3px 8px;
  border-radius: 6px;
  font-weight: 600;
}
.f1-ref-type {
  font-size: 10px;
  color: #888;
  background: #2a2a2a;
  padding: 3px 8px;
  border-radius: 6px;
  font-weight: 600;
  text-transform: uppercase;
}

.f1-ref-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.f1-ref-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.f1-ref-time {
  font-size: 18px;
  font-weight: 700;
  color: #ffffff;
  font-variant-numeric: tabular-nums;
}
.f1-ref-pilot {
  font-size: 12px;
  color: #bbb;
}
.f1-ref-team {
  font-size: 11px;
  color: #888;
}

.diff-box {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  flex-shrink: 0;
}
.diff-label {
  font-size: 10px;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.diff-value {
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.diff-faster { color: #2ecc71; }
.diff-slower { color: #ff4757; }

.diff-bar {
  width: 100%;
  height: 4px;
  background: #333;
  border-radius: 2px;
  margin-top: 10px;
  overflow: hidden;
  position: relative;
}
.diff-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.6s ease 0.2s;
}
.diff-bar-fill.faster { background: #2ecc71; }
.diff-bar-fill.slower { background: #ff4757; }

.details-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 10px;
  border-top: 1px solid #333;
  margin-top: 8px;
}
.detail-id {
  font-size: 10px;
  color: #555;
  font-family: monospace;
}
.detail-id.faster { color: #2ecc71; }
.detail-id.slower { color: #ff4757; }
.detail-hint {
  font-size: 11px;
  color: #666;
}

/* === TELA FORMULÁRIO === */
.form-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 28px;
  padding-top: 8px;
}

.back-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid #444;
  background: transparent;
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-family: inherit;
  transition: background 0.15s ease;
}
.back-btn:hover {
  background: #2a2a2a;
}

.form-header h2 {
  font-size: 18px;
  font-weight: 600;
  color: #ffffff;
}

.field-group {
  margin-bottom: 18px;
}

.field-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: #aaa;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
}

.field-input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid #444;
  border-radius: 10px;
  background: #1a1a1a;
  color: #ffffff;
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s ease;
}
.field-input:focus {
  border-color: #ff4757;
}
.field-input::placeholder {
  color: #666;
}

/* Dropdowns */
.dropdown-wrapper {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: #1e1e1e;
  border: 1px solid #444;
  border-radius: 10px;
  max-height: 320px;
  overflow-y: auto;
  z-index: 100;
  display: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
.dropdown-menu.open {
  display: block;
  animation: dropdownIn 0.15s ease-out;
}

@keyframes dropdownIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.dropdown-item {
  padding: 11px 16px;
  font-size: 14px;
  color: #e0e0e0;
  cursor: pointer;
  transition: background 0.1s ease;
  border-bottom: 1px solid #2a2a2a;
}
.dropdown-item:last-child {
  border-bottom: none;
}
.dropdown-item:hover {
  background: #2a2a2a;
}

.dropdown-divider {
  padding: 8px 16px;
  font-size: 10px;
  font-weight: 700;
  color: #ff4757;
  text-transform: uppercase;
  letter-spacing: 1px;
  background: #151515;
  border-top: 1px solid #333;
  border-bottom: 1px solid #333;
  pointer-events: none;
}

/* Form actions */
.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 28px;
}

.btn-secondary {
  flex: 1;
  padding: 14px;
  border: 1px solid #444;
  border-radius: 10px;
  background: transparent;
  color: #ffffff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s ease;
}
.btn-secondary:hover {
  background: #2a2a2a;
}

.btn-save {
  flex: 1.5;
  padding: 14px;
  border: none;
  border-radius: 10px;
  background: #ff4757;
  color: #ffffff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: opacity 0.15s ease;
}
.btn-save:hover {
  opacity: 0.9;
}

/* Loading */
.loading {
  text-align: center;
  padding: 40px;
  color: #888;
  font-size: 14px;
}

/* Scrollbar */
.dropdown-menu::-webkit-scrollbar {
  width: 6px;
}
.dropdown-menu::-webkit-scrollbar-track {
  background: #1a1a1a;
  border-radius: 3px;
}
.dropdown-menu::-webkit-scrollbar-thumb {
  background: #555;
  border-radius: 3px;
}

/* === TELA DE PREFERÊNCIAS === */
.prefs-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 28px;
  padding-top: 8px;
}

.prefs-header h2 {
  font-size: 18px;
  font-weight: 600;
  color: #ffffff;
}

.prefs-section {
  margin-bottom: 24px;
}

.prefs-section-title {
  font-size: 15px;
  font-weight: 700;
  color: #ff4757;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 14px;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 10px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.checkbox-item:hover {
  border-color: #444;
  background: #1e1e1e;
}

.checkbox-item input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border: 2px solid #555;
  border-radius: 6px;
  background: #2a2a2a;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.checkbox-item input[type="checkbox"]:checked {
  background: #ff4757;
  border-color: #ff4757;
}
.checkbox-item input[type="checkbox"]:checked::after {
  content: '✓';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
}
.checkbox-item input[type="checkbox"]:focus {
  outline: none;
  border-color: #ff4757;
}

.checkbox-label {
  font-size: 15px;
  color: #ffffff;
  font-weight: 500;
  user-select: none;
}
.checkbox-label.slow { color: #ff4757; }
.checkbox-label.fast { color: #2ecc71; }

.checkbox-desc {
  font-size: 12px;
  color: #888;
  margin-top: 2px;
}

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

/* === CONTEXT MENU (LONG PRESS) === */
.context-menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 9998;
  display: none;
  animation: fadeIn 0.15s ease;
}
.context-menu-overlay.active {
  display: block;
}

.context-menu {
  position: fixed;
  background: #2a2a2a;
  border: 1px solid #444;
  border-radius: 14px;
  padding: 8px 0;
  min-width: 180px;
  z-index: 9999;
  display: none;
  box-shadow: 0 12px 40px rgba(0,0,0,0.6);
  animation: scaleIn 0.15s ease;
  overflow: hidden;
}
.context-menu.active {
  display: block;
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.92); }
  to   { opacity: 1; transform: scale(1); }
}

.context-menu-header {
  padding: 10px 16px 8px;
  font-size: 12px;
  font-weight: 600;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid #3a3a3a;
  margin-bottom: 4px;
}

.context-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.1s ease;
  user-select: none;
}
.context-menu-item:hover {
  background: #333;
}
.context-menu-item.edit {
  color: #2ecc71;
}
.context-menu-item.delete {
  color: #ff4757;
}
.context-menu-item .icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

/* Prevent text selection during long press */
.no-select {
  -webkit-user-select: none;
  user-select: none;
}

/* Modal: foto do setup */
.setup-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  z-index: 10000;
  align-items: flex-start;
  justify-content: center;
  padding: 30px 14px;
  overflow-y: auto;
}
.setup-modal-overlay.open {
  display: flex;
}
.setup-modal-box {
  background: #fff;
  border-radius: 14px;
  max-width: 620px;
  width: 100%;
  overflow: hidden;
  position: relative;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.setup-modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 34px;
  height: 34px;
  font-size: 1.1rem;
  cursor: pointer;
  z-index: 2;
  line-height: 1;
}
.setup-modal-close:hover {
  background: rgba(0, 0, 0, 0.85);
}
.setup-modal-box img {
  display: block;
  width: 100%;
  height: auto;
}

/* === BOTÃO CAPACETE (Meu Equipamento) === */
.btn-helmet {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: 1px solid #444;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, border-color 0.15s ease;
  flex-shrink: 0;
  padding: 0;
}
.btn-helmet:hover {
  background: #2a2a2a;
  border-color: #ff4757;
}
.btn-helmet img {
  width: 26px;
  height: 26px;
  object-fit: contain;
  display: block;
}

/* === MEU EQUIPAMENTO === */
.equip-feed {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 8px;
}
.equip-item {
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
}
.equip-item img {
  display: block;
  width: 100%;
  height: auto;               /* mostra a foto inteira, sem cortar, igual em qualquer tela */
}
.equip-caption {
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.4;
  color: #fff;
  background: #000;
  min-height: 2.8em;          /* garante ao menos ~2 linhas, mesmo vazia */
  white-space: pre-wrap;
  word-break: break-word;
  border-top: 1px solid #2a2a2a;
}
.equip-caption-empty {
  color: #888;
  font-style: italic;
}
.equip-empty {
  text-align: center;
  color: #888;
  font-size: 14px;
  padding: 40px 20px;
  line-height: 1.7;
}
.equip-gate {
  text-align: center;
  color: #ccc;
  font-size: 14px;
  padding: 40px 24px;
  line-height: 1.7;
}
.equip-gate p {
  margin-bottom: 16px;
}
.equip-gate .btn-google {
  background: #ff4757;
  color: #fff;
  border-color: #ff4757;
}
.equip-gate .btn-google:hover {
  opacity: 0.9;
  background: #ff4757;
}
.equip-upload {
  margin-top: 20px;
  text-align: center;
  padding-bottom: 20px;
}
.equip-upload-btn {
  display: inline-block;
  padding: 12px 24px;
  background: #ff4757;
  color: #fff;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease;
}
.equip-upload-btn:hover { opacity: 0.9; }
.equip-upload-btn.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
  background: #555;
}
.equip-hint {
  margin-top: 10px;
  font-size: 12px;
  color: #777;
}

/* === CONTA / LOGIN GOOGLE === */
.account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 2px;
}
.account-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.account-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #ff4757;
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.account-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.account-name {
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}
.account-desc {
  font-size: 12px;
  color: #888;
}
.btn-google {
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid #444;
  background: #fff;
  color: #333;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.btn-google:hover { background: #f0f0f0; }
.btn-google.logout {
  background: transparent;
  color: #ff4757;
  border-color: #ff4757;
}
.btn-google.logout:hover { background: rgba(255,71,87,0.1); }
