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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f5f5f5;
  color: #333;
  min-height: 100vh;
}

header {
  background: linear-gradient(135deg, #e74c3c, #c0392b);
  color: white;
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

header h1 {
  font-size: 1.4rem;
  font-weight: 700;
}

main {
  max-width: 800px;
  margin: 0 auto;
  padding: 1.5rem;
}

.hero {
  text-align: center;
  padding: 2rem 1rem;
  margin-bottom: 1.5rem;
}

.hero h2 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
  color: #2c3e50;
}

.hero p {
  color: #7f8c8d;
  font-size: 1rem;
}

.create-race {
  background: white;
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 2rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.create-race h3 {
  margin-bottom: 1rem;
  font-size: 1.1rem;
}

.form-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.form-row input[type="text"] {
  flex: 1;
  min-width: 200px;
  padding: 0.6rem 1rem;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-row input[type="number"] {
  width: 120px;
  padding: 0.6rem 1rem;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-row input:focus {
  border-color: #e74c3c;
}

.form-row select {
  padding: 0.6rem 1rem;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 0.95rem;
  outline: none;
  background: white;
}

.btn-primary {
  background: #e74c3c;
  color: white;
  border: none;
  padding: 0.6rem 1.5rem;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary:hover {
  background: #c0392b;
}

.btn-secondary {
  background: #ecf0f1;
  color: #2c3e50;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-secondary:hover {
  background: #dfe6e9;
}

.btn-danger {
  background: none;
  border: none;
  color: #e74c3c;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
}

.btn-danger:hover {
  background: #ffeaea;
}

.races-list h3 {
  margin-bottom: 1rem;
  font-size: 1.1rem;
}

.race-card {
  background: white;
  border-radius: 12px;
  padding: 1.2rem;
  margin-bottom: 0.8rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.race-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}

.race-card-info h4 {
  font-size: 1.05rem;
  margin-bottom: 0.3rem;
}

.race-card-info span {
  color: #7f8c8d;
  font-size: 0.85rem;
}

.race-card-meta {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.audio-badge {
  background: #e74c3c;
  color: white;
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 600;
}

.btn-delete-race {
  background: none;
  border: none;
  color: #bbb;
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0.3rem;
}

.btn-delete-race:hover {
  color: #e74c3c;
}

/* Race detail */
.btn-back {
  background: none;
  border: none;
  color: #e74c3c;
  font-size: 1rem;
  cursor: pointer;
  margin-bottom: 1rem;
  padding: 0.4rem 0;
  font-weight: 600;
}

#race-header {
  margin-bottom: 0.5rem;
}

#race-header h2 {
  font-size: 1.5rem;
  color: #2c3e50;
}

#race-header p {
  color: #7f8c8d;
  font-size: 0.9rem;
}

/* Username bar */
.username-bar {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 1rem;
  padding: 0.6rem 1rem;
  background: white;
  border-radius: 10px;
  font-size: 0.9rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.username-bar strong {
  color: #e74c3c;
}

.username-warning {
  color: #e67e22;
  font-style: italic;
}

.btn-change-user {
  background: none;
  border: 1px solid #ddd;
  color: #7f8c8d;
  padding: 0.3rem 0.8rem;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  margin-left: auto;
}

.btn-change-user:hover {
  background: #f5f5f5;
  border-color: #bbb;
}

.race-actions {
  margin-bottom: 1.5rem;
}

.btn-listen {
  background: linear-gradient(135deg, #27ae60, #2ecc71);
  color: white;
  border: none;
  padding: 0.8rem 2rem;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(39, 174, 96, 0.3);
  transition: transform 0.15s;
}

.btn-listen:hover {
  transform: translateY(-2px);
}

/* KM list */
.km-card {
  background: white;
  border-radius: 12px;
  margin-bottom: 0.6rem;
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

.km-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 1.2rem;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

.km-card-header:hover {
  background: #fafafa;
}

.km-card-header h4 {
  font-size: 1rem;
  color: #2c3e50;
}

.km-card-header .km-count {
  font-size: 0.85rem;
  color: #7f8c8d;
}

.km-card-body {
  display: none;
  padding: 0 1.2rem 1.2rem;
  border-top: 1px solid #f0f0f0;
}

.km-card.open .km-card-body {
  display: block;
}

.audio-item {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.8rem 0;
  border-bottom: 1px solid #f5f5f5;
}

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

.audio-item audio {
  flex: 1;
  height: 36px;
  min-width: 0;
}

.audio-item-info {
  flex-shrink: 0;
  text-align: right;
  font-size: 0.8rem;
  color: #999;
  min-width: 80px;
}

.audio-item-info .author {
  color: #e74c3c;
  font-weight: 600;
}

.audio-item-actions {
  flex-shrink: 0;
}

.add-audio-form {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.8rem;
  flex-wrap: wrap;
  align-items: center;
}

.add-audio-form input[type="text"] {
  flex: 1;
  min-width: 120px;
  padding: 0.5rem 0.8rem;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 0.85rem;
  outline: none;
}

.add-audio-form input[type="text"]:focus {
  border-color: #e74c3c;
}

.add-audio-form input[type="file"] {
  font-size: 0.85rem;
}

.btn-record {
  background: #e74c3c;
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}

.btn-record.recording {
  animation: pulse 1s infinite;
  background: #c0392b;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.btn-upload {
  background: #3498db;
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}

.btn-upload:hover {
  background: #2980b9;
}

.rec-status {
  font-size: 0.8rem;
  color: #27ae60;
  margin-top: 0.4rem;
  font-weight: 600;
}

/* Listen mode */
#listen-header h2 {
  font-size: 1.3rem;
  color: #2c3e50;
  margin-bottom: 0.3rem;
}

#listen-header p {
  color: #7f8c8d;
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

#listen-player {
  background: white;
  border-radius: 16px;
  padding: 2rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
}

/* Progress bar */
.progress-section {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.progress-bar-container {
  flex: 1;
  height: 12px;
  background: #ecf0f1;
  border-radius: 6px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #e74c3c, #27ae60);
  border-radius: 6px;
  transition: width 0.4s ease;
  width: 0%;
}

.progress-text {
  font-size: 0.85rem;
  font-weight: 700;
  color: #2c3e50;
  white-space: nowrap;
}

.listen-km-info {
  text-align: center;
  margin-bottom: 1.5rem;
}

#listen-km-label {
  font-size: 2rem;
  font-weight: 800;
  color: #e74c3c;
  display: block;
}

#listen-audio-count {
  font-size: 0.9rem;
  color: #7f8c8d;
}

#listen-audios {
  margin-bottom: 1.5rem;
}

.listen-audio-item {
  background: #f9f9f9;
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 0.8rem;
}

.listen-audio-item .listen-author {
  font-weight: 600;
  color: #e74c3c;
  font-size: 0.9rem;
  margin-bottom: 0.3rem;
}

.listen-audio-item .listen-msg {
  font-size: 0.85rem;
  color: #555;
  margin-bottom: 0.5rem;
  font-style: italic;
}

.listen-audio-item audio {
  width: 100%;
  height: 40px;
}

.listen-controls {
  display: flex;
  gap: 0.8rem;
  justify-content: center;
  flex-wrap: wrap;
}

.btn-nav {
  background: #ecf0f1;
  color: #2c3e50;
  border: none;
  padding: 0.7rem 1.5rem;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-nav:hover {
  background: #dfe6e9;
}

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

.btn-play {
  padding: 0.7rem 2rem;
  font-size: 1rem;
}

.empty-state {
  text-align: center;
  padding: 2rem;
  color: #bbb;
}

/* Username modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal {
  background: white;
  border-radius: 16px;
  padding: 2rem;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.modal h3 {
  font-size: 1.2rem;
  margin-bottom: 0.5rem;
  color: #2c3e50;
}

.modal p {
  font-size: 0.9rem;
  color: #7f8c8d;
  margin-bottom: 1.2rem;
}

.modal input {
  width: 100%;
  padding: 0.7rem 1rem;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
  margin-bottom: 1rem;
}

.modal input:focus {
  border-color: #e74c3c;
}

.modal-actions {
  display: flex;
  gap: 0.8rem;
}

.modal-actions .btn-primary {
  flex: 1;
  padding: 0.8rem;
  font-size: 1rem;
}

.modal-actions .btn-secondary {
  flex: 0 0 auto;
  padding: 0.8rem 1.2rem;
  font-size: 0.95rem;
}

/* Identity icon */
.identity-icon {
  display: inline-block;
  background: #ecf0f1;
  color: #7f8c8d;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.btn-change-user-accent {
  background: #e74c3c !important;
  color: white !important;
  border-color: #e74c3c !important;
}

.btn-change-user-accent:hover {
  background: #c0392b !important;
}

@media (max-width: 600px) {
  .form-row {
    flex-direction: column;
  }
  .form-row input[type="text"],
  .form-row input[type="number"] {
    width: 100%;
    min-width: auto;
  }
  .listen-controls {
    flex-direction: column;
    align-items: stretch;
  }
  .progress-section {
    flex-direction: column;
    gap: 0.4rem;
  }
  .progress-text {
    text-align: center;
  }
}
