/* Reset & base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', sans-serif;
  background: #f5f7fa;
  min-height: 100vh;
  transition: background 0.3s ease, color 0.3s ease;
  overflow-y: auto;
}

/* Dark mode toggle => center bottom */
.theme-toggle {
  position: fixed;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
}

#theme-btn {
  position: relative;
  width: 60px;
  height: 32px;
  background: #e5e7eb;
  border-radius: 32px;
  border: none;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  transition: background 0.3s ease, box-shadow 0.2s ease;
  outline: none;
}
#theme-btn:hover {
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.08);
  background: #d1d5db;
}
#theme-btn::before {
  content: '🌞';
  position: absolute;
  top: 4px;
  left: 4px;
  width: 24px;
  height: 24px;
  background: #ffffff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  transition: left 0.3s ease, content 0.3s ease, background 0.3s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}
body.dark-theme #theme-btn {
  background: #4a5568;
}
body.dark-theme #theme-btn:hover {
  background: #2d3748;
}
body.dark-theme #theme-btn::before {
  content: '🌙';
  left: 32px;
  background: #2d3748;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Overall app layout */
.app-container {
  display: flex;
  flex-direction: column;
  width: 95%;
  max-width: 360px;
  margin: 1.5rem auto;
  gap: 1rem;
  justify-content: center;
  align-items: center;
  padding: 1.5rem;
  background: #ffffff;
  border-radius: 32px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

/* Header Row (Timer) */
.header-row {
  display: flex;
  justify-content: center;
  width: 100%;
  align-items: center;
}

.timer-card {
  background: #ffffff;
  border-radius: 32px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  padding: 1.25rem;
  width: 100%;
  text-align: center;
}

.time-display {
  font-size: 2rem;
  font-weight: 600;
  color: #2d3748;
  transition: color 0.3s ease;
}

.period-subtitle {
  display: block;
  font-size: 0.8rem;
  font-weight: 400;
  color: #4a5568;
  text-align: center;
  margin-top: 0.5rem;
  transition: color 0.3s ease;
}

body.dark-theme .period-subtitle {
  color: #e2e8f0;
}

/* Fencers wrapper */
.fencers {
  display: flex;
  gap: 1rem;
  justify-content: center;
  width: 100%;
}

/* Each fencer card => position relative for absolute P-card */
.fencer-card {
  position: relative;
  background: #ffffff;
  border-radius: 32px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  padding: 1.25rem;
  width: 100%;
  text-align: center;
  border: 2px solid transparent;
  transition: box-shadow 0.3s ease; /* Smooth transition for glow */
}

/* Left fencer => red border, Right fencer => green border */
.fencer-left {
  border-color: #f56565;
}
.fencer-right {
  border-color: #48bb78;
}

/* Golden border for priority state */
.fencer-card.priority {
  border-color: #d4af37; /* Golden color */
  box-shadow: 0 0 10px rgba(212, 175, 55, 0.8); /* Persistent glow */
}

/* Random priority selection animation for Fencer A */
.fencer-card.random-priority-a {
  animation: random-priority-selection 2s ease-in-out forwards;
}

/* Random priority selection animation for Fencer B */
.fencer-card.random-priority-b {
  animation: random-priority-selection 2s ease-in-out forwards 0.25s; /* Delayed start */
}

@keyframes random-priority-selection {
  0% {
    box-shadow: 0 0 0 rgba(212, 175, 55, 0);
  }
  12.5% {
    box-shadow: 0 0 15px rgba(212, 175, 55, 0.8);
  }
  25% {
    box-shadow: 0 0 0 rgba(212, 175, 55, 0);
  }
  37.5% {
    box-shadow: 0 0 15px rgba(212, 175, 55, 0.8);
  }
  50% {
    box-shadow: 0 0 0 rgba(212, 175, 55, 0);
  }
  62.5% {
    box-shadow: 0 0 15px rgba(212, 175, 55, 0.8);
  }
  75% {
    box-shadow: 0 0 0 rgba(212, 175, 55, 0);
  }
  100% {
    box-shadow: 0 0 0 rgba(212, 175, 55, 0);
  }
}

/* Final priority selection animation */
.fencer-card.final-priority-selecting {
  animation: final-priority-selection 1.5s ease-in-out forwards;
}

@keyframes final-priority-selection {
  0% {
    box-shadow: 0 0 0 rgba(212, 175, 55, 0);
    border-color: transparent;
  }
  33% {
    box-shadow: 0 0 20px rgba(212, 175, 55, 0.8);
    border-color: #d4af37;
  }
  66% {
    box-shadow: 0 0 10px rgba(212, 175, 55, 0.4);
    border-color: #d4af37;
  }
  100% {
    box-shadow: 0 0 10px rgba(212, 175, 55, 0.8);
    border-color: #d4af37;
  }
}

/* Score styling */
.fencer-score {
  font-size: 3rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: #2d3748;
  transition: color 0.3s ease;
}

/* Buttons to adjust score */
.score-controls {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  margin-bottom: 1rem;
}

.score-adjust,
.period-btn {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 16px;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  background: #e5e7eb;
  color: #4a5568;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}
.score-adjust:hover,
.period-btn:hover {
  background: #d1d5db;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}
.score-adjust:active,
.period-btn:active {
  background: #a0aec0;
}

/* Touch buttons (left is red, right is green) */
.touch-btn {
  display: inline-block;
  width: 100%;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 32px;
  cursor: pointer;
  color: #ffffff;
  transition: background 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}
.green-btn {
  background: #f56565; /* left is red */
}
.green-btn:hover {
  background: #e53e3e;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.08);
}
.green-btn:active {
  background: #c53030;
}
.red-btn {
  background: #48bb78; /* right is green */
}
.red-btn:hover {
  background: #38a169;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.08);
}
.red-btn:active {
  background: #2d8f5f;
}

/* Double Touch => match Start button dimensions */
.extra-actions {
  width: 100%;
}
.extra-btn {
  width: 100%;
  height: 56px;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 32px;
  border: none;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  color: #ffffff;
  background: #a0aec0;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}
.extra-btn:hover {
  background: #718096;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.08);
}
.extra-btn:active {
  background: #4a5568;
}

/* Settings Section */
.settings {
  width: 100%;
  background: #ffffff;
  border-radius: 32px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  padding: 1rem;
  margin-top: 0.5rem;
}

/* "Settings" label slightly larger/bolder and left-aligned */
.setting-item:first-of-type {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  text-align: left; /* Align "Settings" title to the left */
}

/* No divider lines; just spacing for labels and controls */
.setting-item {
  display: flex;
  justify-content: space-between; /* Revert to space-between to separate labels and controls */
  align-items: center;
  font-size: 1rem;
  font-weight: 500; /* medium */
  color: #2d3748;
  padding: 0.5rem 0;
}

/* Make labels left-aligned */
.setting-item span {
  margin-right: 0.3rem; /* Maintain gap before controls */
  text-align: left; /* Ensure labels are left-aligned */
}

/* Period controls styling to match the screenshot */
.period-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem; /* Space between buttons and number */
}

/* Ensure the period number (#period) stays visually consistent */
#period {
  font-size: 1rem;
  font-weight: 500;
  color: #2d3748;
  margin: 0 6px; /* Maintain 12px gap between elements */
  transition: color 0.3s ease;
}

/* Dark theme adjustments for #period and labels */
body.dark-theme .setting-item {
  color: #e2e8f0;
}
body.dark-theme #period {
  color: #e2e8f0;
}

/* Toggle Switch => revert to 60×32 to match dark-theme toggle size */
.switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 32px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: 0.4s;
  border-radius: 32px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.slider:before {
  position: absolute;
  content: "";
  height: 24px;
  width: 24px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: 0.4s;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

input:checked + .slider {
  background-color: #48bb78;
}

input:checked + .slider:before {
  transform: translateX(24px);
}

body.dark-theme .slider {
  background-color: #4a5568;
}

body.dark-theme input:checked + .slider {
  background-color: #38a169;
}

body.dark-theme .slider:before {
  background-color: #e2e8f0; /* Slightly lighter for contrast in dark mode */
}

/* Timer Controls */
.timer-controls {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1rem; /* Add spacing between Start and Priority buttons */
}

/* Start/Pause button => 56px tall, 100% width */
.timer-toggle {
  width: 100%;
  height: 56px;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 32px;
  border: none;
  cursor: pointer;
  color: #ffffff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  transition: background 0.2s ease, box-shadow 0.2s ease;
}
.timer-toggle.start {
  background: #48bb78;
}
.timer-toggle.pause {
  background: #f56565;
}
.timer-toggle:hover {
  background: #38a169;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.08);
}
.timer-toggle:active {
  background: #2d8f5f;
}

/* Period & Reset row */
.period-reset-row {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
}
.reset-buttons {
  display: flex;
  gap: 1rem;
  width: 100%;
}
.timer-reset {
  width: 100%;
  background: #a0aec0;
  color: #ffffff;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 32px;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  transition: background 0.2s ease, box-shadow 0.2s ease;
  padding: 0.75rem 1.5rem;
}
.timer-reset:hover {
  background: #718096;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.08);
}
.timer-reset:active {
  background: #4a5568;
}

/* Notification (fixed at top, centered) */
.notification {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #48bb78;
  color: #ffffff;
  padding: 1rem 2rem;
  border-radius: 32px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  display: none;
  font-size: 1rem;
  font-weight: 600;
  z-index: 3000;
  transition: opacity 0.3s ease;
}
.notification.error {
  background: #f56565;
}
.notification.show {
  display: block;
  opacity: 1;
}
.notification.hide {
  opacity: 0;
}

/* P-card indicator */
.p-card {
  display: none;
  position: absolute;
  top: 10px;
  right: 10px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-size: 0.8rem;
  line-height: 24px;
  text-align: center;
  color: #000000;
  background: #f6e05e;
  z-index: 10;
}
.p-card.yellow,
.p-card.red,
.p-card.black {
  display: inline-block;
}
.p-card.red {
  background: #f56565;
}
.p-card.black {
  background: #4a5568;
}

/* Dark Theme */
body.dark-theme {
  background: #1a202c;
}
body.dark-theme .app-container,
body.dark-theme .fencer-card,
body.dark-theme .timer-card,
body.dark-theme .settings,
body.dark-theme .period-controls {
  background: #2d3748;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
body.dark-theme .time-display,
body.dark-theme .fencer-score {
  color: #e2e8f0;
}
body.dark-theme .score-adjust,
body.dark-theme .period-btn {
  background: #4a5568;
  color: #e2e8f0;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}
body.dark-theme .score-adjust:hover,
body.dark-theme .period-btn:hover {
  background: #2d3748;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12);
}
body.dark-theme .score-adjust:active,
body.dark-theme .period-btn:active {
  background: #1a202c;
}
body.dark-theme .touch-btn,
body.dark-theme .timer-reset {
  color: #e2e8f0;
}
body.dark-theme .timer-toggle.start {
  background: #38a169;
}
body.dark-theme .timer-toggle.pause {
  background: #e53e3e;
}
body.dark-theme .timer-toggle:hover {
  background: #2d8f5f;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.12);
}
body.dark-theme .timer-toggle:active {
  background: #276749;
}
body.dark-theme .extra-btn {
  background: #4a5568;
}
body.dark-theme .extra-btn:hover {
  background: #2d3748;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.12);
}
body.dark-theme .extra-btn:active {
  background: #1a202c;
}
body.dark-theme .timer-reset {
  background: #4a5568;
}
body.dark-theme .timer-reset:hover {
  background: #2d3748;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.12);
}
body.dark-theme .timer-reset:active {
  background: #1a202c;
}
body.dark-theme .notification {
  background: #38a169;
}
body.dark-theme .notification.error {
  background: #e53e3e;
}
body.dark-theme .p-card {
  background: #f6e05e; /* “yellow” remains visible in dark mode */
}
body.dark-theme .p-card.red {
  background: #f56565;
}
body.dark-theme .p-card.black {
  background: #4a5568;
}

/* Responsive for smaller screens */
@media (min-width: 361px) {
  .fencers {
    flex-direction: row;
  }
  .fencer-card {
    width: 50%;
  }
  .app-container {
    max-width: 480px;
    gap: 1.5rem;
    padding: 2rem;
  }
}

@media (max-width: 360px) {
  .app-container {
    margin: 1rem auto;
    padding: 1rem;
    gap: 0.75rem;
  }
  .fencer-card,
  .timer-card {
    padding: 1rem;
  }
  .fencer-score {
    font-size: 2.2rem;
  }
  .time-display {
    font-size: 1.8rem;
  }
  .score-adjust,
  .period-btn {
    width: 2rem;
    height: 2rem;
    font-size: 0.9rem;
  }
  .touch-btn,
  .timer-reset {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
  }
  .extra-btn,
  .timer-toggle {
    font-size: 0.9rem;
  }
  .p-card {
    width: 16px;
    height: 16px;
    font-size: 0.7rem;
    line-height: 16px;
    top: 8px;
    right: 8px;
  }
}

/* Disable hover states on mobile devices (coarse pointers) */
@media (pointer: coarse) {
  #theme-btn:hover {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    background: #e5e7eb;
  }
  body.dark-theme #theme-btn:hover {
    background: #4a5568;
  }
  .score-adjust:hover,
  .period-btn:hover {
    background: #e5e7eb;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  }
  body.dark-theme .score-adjust:hover,
  body.dark-theme .period-btn:hover {
    background: #4a5568;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  }
  .touch-btn.green-btn:hover {
    background: #f56565;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  }
  .touch-btn.red-btn:hover {
    background: #48bb78;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  }
  .extra-btn:hover {
    background: #a0aec0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  }
  body.dark-theme .extra-btn:hover {
    background: #4a5568;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  }
  .timer-toggle:hover {
    background: inherit; /* Keeps the original background (start or pause) */
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  }
  body.dark-theme .timer-toggle.start:hover {
    background: #38a169;
  }
  body.dark-theme .timer-toggle.pause:hover {
    background: #e53e3e;
  }
  .timer-reset:hover {
    background: #a0aec0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  }
  body.dark-theme .timer-reset:hover {
    background: #4a5568;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  }
}