:root {
  --bg-color: #f7f9fc;
  --card-bg: rgba(255, 255, 255, 0.85);
  --text-main: #2d3748;
  --text-muted: #718096;
  
  --work-color: #e53e3e;
  --break-color: #38a169;
  
  --primary-btn: #4299e1;
  --primary-hover: #3182ce;
  --secondary-btn: #e2e8f0;
  --secondary-hover: #cbd5e0;
  --accent-btn: #d69e2e;
  --accent-hover: #b7791f;
  
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);

  --transition: all 0.2s ease-in-out;
}

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

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-color);
  background-image: linear-gradient(135deg, #fdfbfb 0%, #ebedee 100%);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.app-container {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  background: transparent;
  display: flex;
  flex-direction: column;
}

@media (min-width: 481px) {
  .app-container {
    min-height: auto;
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    background: var(--card-bg);
    overflow: hidden;
    backdrop-filter: blur(10px);
    margin: 20px;
  }
}

header {
  padding: 1rem 1rem 0;
  background: rgba(255, 255, 255, 0.5);
  border-bottom: 1px solid rgba(0,0,0,0.05);
}

.tabs {
  display: flex;
  gap: 1rem;
}

.tab-btn {
  flex: 1;
  padding: 0.75rem 1rem;
  background: none;
  border: none;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: var(--transition);
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--text-main);
}

.tab-btn.active {
  color: var(--primary-btn);
  border-bottom-color: var(--primary-btn);
}

main {
  flex: 1;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  position: relative;
}

.view-section {
  display: none;
  flex-direction: column;
  gap: 1.5rem;
  animation: fadeIn 0.3s ease;
}

.view-section.active {
  display: flex;
}

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

/* Custom Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(2px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  opacity: 1;
  transition: opacity 0.2s ease;
}

.modal-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-content {
  background: white;
  padding: 2rem;
  border-radius: 16px;
  max-width: 400px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  text-align: center;
  box-shadow: var(--shadow-lg);
  transform: translateY(0);
  transition: transform 0.2s ease;
}

/* スクロールバーのスタイル（装飾） */
.modal-content::-webkit-scrollbar {
  width: 6px;
}
.modal-content::-webkit-scrollbar-thumb {
  background: #cbd5e0;
  border-radius: 3px;
}

.modal-overlay.hidden .modal-content {
  transform: translateY(20px);
}

.modal-content h3 {
  margin-top: 0;
  color: var(--text-main);
  font-size: 1.3rem;
  margin-bottom: 0.5rem;
}

.modal-content p {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 2rem;
}

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

/* Help Button */
.help-btn {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  width: 45px;
  height: 45px;
  border-radius: 50%;
  background: var(--card-bg);
  color: var(--primary-color);
  font-size: 1.3rem;
  font-weight: 700;
  border: 2px solid var(--primary-color);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 500;
  transition: all 0.2s ease;
}

.help-btn:hover {
  transform: scale(1.1);
  box-shadow: var(--shadow-md);
  background-color: var(--primary-color);
  color: white;
}

@media (max-width: 480px) {
  .help-btn {
    top: 1rem;
    right: 1rem;
    width: 38px;
    height: 38px;
    font-size: 1.1rem;
  }
  .tab-btn {
    padding: 0.5rem 0.2rem;
    font-size: 0.9rem;
  }
  header {
    padding-top: 3.5rem;
  }
}

.timer-card, .settings-card, .challenge-area {
  background: #ffffff;
  border-radius: 16px;
  padding: 2rem 1.5rem;
  box-shadow: var(--shadow-md);
  text-align: center;
  transition: var(--transition);
}

.trivia-area {
  background: #ebf8ff;
  border-left: 4px solid #4299e1;
  padding: 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  color: #2b6cb0;
  box-shadow: var(--shadow-sm);
  text-align: left;
  line-height: 1.5;
  transition: opacity 0.3s ease;
}

.state-label {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: var(--transition);
}

.state-label.work { color: var(--work-color); }
.state-label.break { color: var(--break-color); }

.time-display {
  font-size: 5rem;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  margin-bottom: 1.5rem;
  line-height: 1;
  transition: color 0.3s ease;
  color: var(--text-main);
}

.set-info {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
  font-weight: 600;
}

.progress-container {
  width: 100%;
  height: 56px;
  background: transparent;
  margin-bottom: 2rem;
  position: relative;
}

.progress-scene {
  display: none;
  width: 100%;
  height: 100%;
}

.progress-scene.active {
  display: flex;
}

#progress-work {
  align-items: center;
}

.walker-track {
  flex: 1;
  position: relative;
  height: 48px;
  margin-right: 15px;
  background: var(--bg-color);
  border-radius: 24px;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
}

.progress-fill {
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: 0%;
  background: #48bb78; /* Green tint */
  transition: width 0.5s linear;
  opacity: 0.3; /* Adjusted opacity to make the green pop more */
}

#picto-walker {
  position: absolute;
  left: 0%;
  top: 4px;
  /* initial transform, will be updated via JS */
  transform: translateX(0%);
  transition: left 0.5s linear;
  z-index: 2;
}

.css-stickman {
  position: relative;
  width: 24px;
  height: 40px;
}
.css-stickman .head {
  position: absolute;
  width: 16px; height: 16px;
  background: var(--text-main);
  border-radius: 50%;
  top: 0; left: 4px;
  z-index: 2;
}
.css-stickman .body {
  position: absolute;
  width: 6px; height: 16px;
  background: var(--text-main);
  top: 14px; left: 9px;
  border-radius: 3px;
  z-index: 2;
}
.css-stickman .arm, .css-stickman .leg {
  position: absolute;
  width: 6px; height: 14px;
  background: var(--text-main);
  border-radius: 3px;
  transform-origin: top center;
  z-index: 1;
}
.walker .arm-left { top: 15px; left: 9px; animation: swing 0.6s infinite alternate ease-in-out; }
.walker .arm-right { top: 15px; left: 9px; animation: swing-rev 0.6s infinite alternate ease-in-out; z-index: 3; }
.walker .leg-left { top: 28px; left: 9px; animation: swing-leg 0.6s infinite alternate ease-in-out; }
.walker .leg-right { top: 28px; left: 9px; animation: swing-leg-rev 0.6s infinite alternate ease-in-out; z-index: 3;}

@keyframes swing { 0% { transform: rotate(45deg); } 100% { transform: rotate(-45deg); } }
@keyframes swing-rev { 0% { transform: rotate(-45deg); } 100% { transform: rotate(45deg); } }
@keyframes swing-leg { 0% { transform: rotate(35deg); } 100% { transform: rotate(-35deg); } }
@keyframes swing-leg-rev { 0% { transform: rotate(-35deg); } 100% { transform: rotate(35deg); } }

/* Flag CSS */
.css-flag {
   width: 24px; height: 40px; position: relative;
   transform: scale(0.85); /* Make flag slightly smaller */
   transform-origin: bottom right;
}
.css-flag .pole { width: 4px; height: 40px; background: var(--text-muted); position: absolute; left: 4px; border-radius: 2px;}
.css-flag .banner { 
  width: 16px; height: 16px; 
  background: linear-gradient(135deg, transparent 25%, #4a5568 25%, #4a5568 50%, transparent 50%, transparent 75%, #4a5568 75%, #4a5568 100%);
  background-size: 8px 8px;
  position: absolute; top: 2px; left: 8px; border-radius: 0 4px 4px 0; 
  border: 1px solid var(--text-muted);
}

#progress-break {
  align-items: center;
  justify-content: center;
  background: var(--bg-color);
  border-radius: 24px;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
}

.picto-bed {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 48px;
  width: 60px;
}

.sleeper {
  transform: rotate(-90deg) scale(1.1);
  transform-origin: 50% 70%;
  transition: transform 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
  margin-top: 2px;
}
.sleeper .arm { display: none; }
.sleeper .leg-left, .sleeper .leg-right { top: 28px; left: 9px; transform: rotate(0deg); }

.sleeper .pillow {
  position: absolute;
  width: 20px; height: 12px;
  background: white;
  border-radius: 6px;
  top: -2px; left: 2px;
  z-index: 1;
}

.sleeper .blanket {
  position: absolute;
  width: 32px; height: 26px;
  background: var(--primary-btn);
  top: 14px; left: -4px;
  border-radius: 4px;
  z-index: 10;
  transition: top 0.8s ease;
}

.sleeper.wake-up {
  transform: rotate(-20deg) scale(1.1); /* Sit up slightly instead of 0deg to look like getting up from pillow */
}
.sleeper.wake-up .blanket {
  top: 24px; /* Blanket slides down when waking up */
}

.picto-zzz {
  position: absolute;
  top: -5px;
  right: -5px;
  font-size: 0.9rem;
  font-weight: bold;
  color: #718096;
  animation: zzz 2s infinite ease-in-out;
}

/* Calendar Grid Styles */
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.cal-header {
  font-weight: bold;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  padding-bottom: 0.5rem;
}

.cal-cell {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: var(--bg-color);
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.2s ease;
}

.cal-cell:hover {
  background: #e2e8f0;
  transform: scale(1.05);
}

.cal-cell.today {
  border: 2px solid var(--primary-btn);
  font-weight: bold;
}

.cal-cell.has-data {
  background: #c6f6d5; /* Light green tint */
  border: 1px solid #9ae6b4;
}

.cal-cell.has-data:hover {
  background: #9ae6b4;
}

@keyframes zzz {
  0% { opacity: 0; transform: translateY(0) scale(0.8); }
  50% { opacity: 1; transform: translateY(-5px) scale(1.1); }
  100% { opacity: 0; transform: translateY(-10px) scale(1); }
}

.hidden-zzz {
  display: none;
}

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

.btn {
  padding: 0.75rem 1.5rem;
  border-radius: 999px;
  border: none;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.2s, background-color 0.2s;
  box-shadow: var(--shadow-sm);
}

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

.btn.primary {
  background-color: var(--primary-btn);
  color: white;
}
.btn.primary:hover { background-color: var(--primary-hover); }

.btn.secondary {
  background-color: var(--secondary-btn);
  color: var(--text-main);
}
.btn.secondary:hover { background-color: var(--secondary-hover); }

.btn.outline {
  background-color: transparent;
  color: var(--text-muted);
  border: 2px solid var(--secondary-btn);
  box-shadow: none;
}
.btn.outline:hover {
  border-color: var(--text-muted);
  color: var(--text-main);
}

.btn.accent {
  background-color: var(--accent-btn);
  color: white;
}
.btn.accent:hover { background-color: var(--accent-hover); }
.btn.accent:disabled {
  background-color: #e2e8f0;
  color: #a0aec0;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn.danger {
  background-color: #fed7d7;
  color: #c53030;
  box-shadow: none;
}
.btn.danger:hover {
  background-color: #feb2b2;
}

.challenge-area {
  border: 2px dashed var(--break-color);
  background: #f0fff4;
  padding: 1.5rem;
}

.challenge-area.hidden {
  display: none !important;
}

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

.challenge-header h3 {
  font-size: 1.1rem;
  color: var(--break-color);
  margin: 0;
}

.challenge-stats {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-size: 0.8rem;
  color: var(--text-muted);
}

#streak-counter {
  font-weight: 700;
  color: #dd6b20;
  font-size: 0.9rem;
  margin-bottom: 0.25rem;
}

#challenge-text {
  font-size: 1.1rem;
  margin-bottom: 1.5rem;
  font-weight: 600;
}

.settings-card h2 {
  margin-bottom: 1.5rem;
  font-size: 1.5rem;
}

.setting-group {
  margin-bottom: 1.5rem;
  text-align: left;
}

.setting-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

input[type=range] {
  width: 100%;
  accent-color: var(--primary-btn);
  margin-top: 0.5rem;
}

.setting-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  text-align: left;
  font-weight: 600;
}

.danger-zone {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid #e2e8f0;
}

.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
}

.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: .4s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: .4s;
}

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

input:focus + .slider {
  box-shadow: 0 0 1px var(--primary-btn);
}

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

.slider.round {
  border-radius: 34px;
}

.slider.round:before {
  border-radius: 50%;
}
