:root {
  /* Light Theme Base */
  --bg-color: #eff1f5;
  --text-color: #4c4f69;
  --container-bg: #ffffff;
  --primary-color: #d06a6a; /* Default to favorite red */
  --secondary-color: #8c8fa1;
  --ring-bg: #e6e9ef;
  --modal-bg: rgba(255, 255, 255, 0.4);
  --btn-hover: rgba(0,0,0,0.1);
  --border-color: #dce0e8;
}

body.dark {
  /* Dark Theme Base */
  --bg-color: #1e1e2e;
  --text-color: #cdd6f4;
  --container-bg: #181825;
  --secondary-color: #6c7086;
  --ring-bg: #313244;
  --modal-bg: rgba(0, 0, 0, 0.4);
  --btn-hover: rgba(255,255,255,0.1);
  --border-color: #45475a;
}

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

html, body {
  overflow-x: hidden;
  overscroll-behavior: none; /* Prevents pull-to-refresh and bouncy scrolling on mobile */
  width: 100%;
}

body {
  font-family: 'Inter', 'Roboto', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  transition: background-color 0.3s ease, color 0.3s ease;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

/* Fullscreen mode removes container styling */
body.fullscreen-mode .app-container {
  width: 100vw;
  height: 100vh;
  max-width: none;
  border-radius: 0;
  box-shadow: none;
  background-color: transparent;
  padding: 2rem 5vw;
}

/* Mobile Screen Fullscreen implicitly (Portrait or Landscape) */
@media (max-width: 600px), (orientation: landscape) and (max-height: 600px) {
  .app-container {
    width: 100vw !important;
    min-height: 100vh !important;
    max-width: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background-color: transparent !important;
    padding: 1rem !important;
    justify-content: center;
  }
}

.app-container {
  background-color: var(--container-bg);
  padding: 2rem;
  border-radius: 24px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  width: 90%;
  max-width: 400px;
  text-align: center;
  transition: background-color 0.3s ease;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

h1 {
  font-size: 1.5rem;
  font-weight: 600;
}

.controls {
  display: flex;
  gap: 0.5rem;
}

.controls button {
  background: none;
  border: none;
  color: var(--text-color);
  cursor: pointer;
  padding: 0.5rem;
  transition: color 0.2s ease;
}

.controls button:hover {
  color: var(--primary-color);
}

.icon {
  display: block;
}

.icon.hidden {
  display: none;
}

/* Flex layout logic for portrait */
.main-content {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.main-content.modes-first .modes { order: 1; margin-bottom: 2rem; }
.main-content.modes-first .timer-container { order: 2; margin-bottom: 1.5rem; }
.main-content.modes-first .stats-container { order: 3; margin-bottom: 2rem; }
.main-content.modes-first .timer-actions { order: 4; }

.main-content.timer-first .timer-container { order: 1; margin-bottom: 1.5rem; }
.main-content.timer-first .modes { order: 2; margin-bottom: 1.5rem; }
.main-content.timer-first .stats-container { order: 3; margin-bottom: 2rem; }
.main-content.timer-first .timer-actions { order: 4; }


.modes {
  display: flex;
  justify-content: space-around;
  background-color: var(--ring-bg);
  border-radius: 99px;
  padding: 0.25rem;
}

.mode-btn {
  flex: 1;
  background: none;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 99px;
  color: var(--text-color);
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.3s ease, color 0.3s ease;
  font-size: 0.95rem;
}

.mode-btn.active {
  background-color: var(--primary-color);
  color: var(--bg-color);
}

.timer-container {
  position: relative;
  width: 100%;
  max-width: 300px;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
}

.progress-ring {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.progress-ring__circle {
  transition: stroke-dashoffset 0.1s linear, stroke 0.5s ease;
}

.time-display {
  font-size: 4.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-color);
  z-index: 1;
}

/* Stats */
.stats-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  min-height: 48px;
}

.round-dots {
  display: flex;
  gap: 8px;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--primary-color);
  background-color: transparent;
  transition: background-color 0.3s ease, border-color 0.5s ease;
}

.dot.filled {
  background-color: var(--primary-color);
}

.daily-total {
  font-size: 0.9rem;
  color: var(--secondary-color);
}

.daily-total.hidden {
  display: none !important;
}

/* Actions */
.timer-actions {
  display: flex;
  justify-content: center;
  gap: 1rem;
}

.action-btn {
  padding: 0.75rem 2rem;
  border: none;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 100px;
}

.action-btn.primary {
  background-color: var(--primary-color);
  color: var(--bg-color);
}

.action-btn.primary:hover {
  filter: brightness(1.1);
  transform: translateY(-2px);
}

.action-btn.secondary {
  background-color: transparent;
  color: var(--text-color);
  border: 2px solid var(--ring-bg);
}

.action-btn.secondary:hover {
  border-color: var(--secondary-color);
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: var(--modal-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal.hidden {
  opacity: 0;
  visibility: hidden;
}

.modal-content {
  background-color: var(--container-bg);
  padding: 2rem;
  border-radius: 24px;
  width: 90%;
  max-width: 380px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.2);
  transition: background-color 0.3s ease;
}

.modal-content h2 {
  margin-bottom: 1rem;
  text-align: center;
  flex-shrink: 0;
}

.settings-scroll {
  overflow-y: auto;
  padding-right: 0.5rem;
  margin-bottom: 1.5rem;
}

.settings-scroll::-webkit-scrollbar {
  width: 6px;
}

.settings-scroll::-webkit-scrollbar-thumb {
  background-color: var(--ring-bg);
  border-radius: 3px;
}

/* Settings Accordion */
.settings-section {
  background-color: var(--ring-bg);
  border-radius: 12px;
  margin-bottom: 0.75rem;
  overflow: hidden;
  border-bottom: none;
  padding-bottom: 0;
}

.settings-section summary {
  padding: 1rem;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  list-style: none; /* remove default arrow */
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
  color: var(--text-color);
}

.settings-section summary::after {
  content: '▼';
  font-size: 0.7rem;
  transition: transform 0.3s ease;
  color: var(--secondary-color);
}

.settings-section[open] summary::after {
  transform: rotate(180deg);
}

.settings-section summary::-webkit-details-marker {
  display: none;
}

.details-content {
  padding: 0 1rem 1rem 1rem;
  border-top: 1px solid var(--border-color);
  margin-top: 0;
  padding-top: 1rem;
}

.setting-group {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  text-align: left;
}
.setting-group:last-child {
  margin-bottom: 0;
}

.setting-group label {
  font-size: 0.95rem;
}

.setting-group input[type="number"],
.setting-group input[type="time"],
.setting-group select {
  width: 140px;
  padding: 0.5rem;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  background-color: transparent;
  color: var(--text-color);
  text-align: center;
  font-size: 0.9rem;
  font-weight: 500;
  transition: border-color 0.2s ease;
}
.setting-group input[type="number"], .setting-group input[type="time"] {
  width: 95px;
}

.setting-group input[type="color"] {
  width: 50px;
  height: 36px;
  padding: 2px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  background-color: transparent;
  cursor: pointer;
}

.setting-group input:focus,
.setting-group select:focus {
  outline: none;
  border-color: var(--primary-color);
}

.modal-actions {
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-shrink: 0;
}

/* Switch Toggle */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

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

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--border-color);
  transition: .3s;
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--primary-color);
}

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

.stats-box {
  background-color: rgba(0,0,0,0.05);
  border-radius: 8px;
  padding: 0.75rem;
  margin-top: 0.5rem;
}
body.dark .stats-box {
  background-color: rgba(255,255,255,0.05);
}

.stat-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
}

.stat-row:last-child {
  margin-bottom: 0;
}

@media (max-width: 360px) {
  .time-display {
    font-size: 3.5rem;
  }
}

/* Landscape Adaptation using CSS Grid */
@media (orientation: landscape) and (max-height: 600px) {
  .app-container {
    max-width: 700px;
    padding: 1rem 2rem;
  }
  
  header {
    margin-bottom: 1rem;
  }

  .main-content, .main-content.modes-first, .main-content.timer-first {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto;
    grid-template-areas:
      "timer modes"
      "timer stats"
      "timer actions";
    gap: 1rem;
    align-content: center;
    align-items: center;
  }
  
  .timer-container { 
    grid-area: timer;
    margin: 0 !important;
    width: 250px;
    height: 250px;
    max-width: none;
    justify-self: center;
  }
  .modes { grid-area: modes; margin: 0 !important; align-self: end; }
  .stats-container { grid-area: stats; margin: 0 !important; }
  .timer-actions { grid-area: actions; margin: 0 !important; align-self: start; margin-top: -0.5rem !important; }
}
