/* ========================================
   CSS Variables
   ======================================== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: #222240;
  --text-primary: #e8e8ec;
  --text-secondary: #9898a8;
  --text-muted: #686878;
  --color-idling: #f59e0b;
  --color-working: #ef4444;
  --color-break: #06b6d4;
  --color-ready: #6366f1;
  --color-danger: #dc2626;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.3s ease;
}

/* ========================================
   Reset & Base
   ======================================== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
}

/* ========================================
   App Container
   ======================================== */
#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px 32px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ========================================
   Navigation
   ======================================== */
.nav {
  display: flex;
  gap: 4px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  margin-bottom: 24px;
  position: sticky;
  top: 0;
  background: var(--bg-primary);
  z-index: 10;
}

.nav-btn {
  flex: 1;
  padding: 10px 12px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

.nav-btn.active {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* ========================================
   Views
   ======================================== */
.view {
  display: none;
  flex: 1;
  animation: fadeIn 0.3s ease;
}

.view.active {
  display: flex;
  flex-direction: column;
}

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

.view-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 20px;
}

/* ========================================
   Timer View
   ======================================== */
#timer-view {
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding-top: 20px;
  position: relative;
}

/* ========================================
   PiP Button
   ======================================== */
.pip-btn {
  display: none;
  position: absolute;
  top: 12px;
  right: 0;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border-radius: 50%;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.pip-btn:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.pip-btn.supported {
  display: flex;
}

.phase-label {
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  transition: color var(--transition);
}

.phase-sub {
  font-size: 14px;
  color: var(--text-secondary);
  text-align: center;
  min-height: 20px;
}

/* Phase colors */
.phase-ready { color: var(--color-ready); }
.phase-idling { color: var(--color-idling); }
.phase-working { color: var(--color-working); }
.phase-break { color: var(--color-break); }

/* ========================================
   Timer Ring
   ======================================== */
.timer-container {
  position: relative;
  width: 260px;
  height: 260px;
  margin: 12px 0;
}

.timer-ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.timer-ring-bg {
  fill: none;
  stroke: var(--bg-secondary);
  stroke-width: 8;
}

.timer-ring-progress {
  fill: none;
  stroke: var(--color-ready);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 553;
  stroke-dashoffset: 553;
  transition: stroke 0.5s ease;
}

.timer-display {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.timer-time {
  font-size: 52px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -1px;
}

.timer-sub {
  font-size: 13px;
  color: var(--text-secondary);
  min-height: 18px;
}

/* Working pulse animation */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.pulse {
  animation: pulse 2s ease-in-out infinite;
}

/* ========================================
   Action Buttons
   ======================================== */
.actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  min-height: 52px;
  align-items: center;
}

.btn {
  padding: 14px 32px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

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

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

.btn-primary:hover {
  filter: brightness(1.1);
}

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

.btn-idling:hover {
  filter: brightness(1.1);
}

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

.btn-working:hover {
  filter: brightness(1.1);
}

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

.btn-break:hover {
  filter: brightness(1.1);
}

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-secondary:hover {
  background: var(--bg-card);
}

.btn-danger {
  background: transparent;
  color: var(--color-danger);
  border: 1px solid var(--color-danger);
}

.btn-danger:hover {
  background: rgba(220, 38, 38, 0.1);
}

.btn-sm {
  padding: 8px 16px;
  font-size: 13px;
}

/* Auto transition countdown */
.auto-transition-text {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
  width: 100%;
  margin-top: 4px;
}

/* ========================================
   Dashboard - Stats Grid
   ======================================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 16px 12px;
  text-align: center;
}

.stat-value {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 11px;
  color: var(--text-secondary);
}

/* ========================================
   Dashboard - Bar Chart
   ======================================== */
.chart-section {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.chart-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 16px;
}

.bar-chart {
  display: flex;
  align-items: flex-end;
  justify-content: space-around;
  height: 160px;
  gap: 8px;
}

.bar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  height: 100%;
  justify-content: flex-end;
}

.bar {
  width: 100%;
  max-width: 36px;
  min-height: 2px;
  background: linear-gradient(to top, var(--color-working), #f87171);
  border-radius: 4px 4px 0 0;
  transition: height 0.5s ease;
}

.bar.today {
  background: linear-gradient(to top, var(--color-idling), #fbbf24);
}

.bar-value {
  font-size: 10px;
  color: var(--text-secondary);
  margin-bottom: 4px;
  font-variant-numeric: tabular-nums;
}

.bar-label {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 8px;
}

.bar-label.today-label {
  color: var(--color-idling);
  font-weight: 600;
}

/* ========================================
   Dashboard - Session List
   ======================================== */
.history-section {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 20px;
}

.session-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.session-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.session-time {
  color: var(--text-secondary);
}

.session-duration {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.no-sessions {
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
  padding: 20px;
}

/* ========================================
   Settings
   ======================================== */
.settings-group {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 4px 0;
  margin-bottom: 16px;
}

.settings-group-title {
  font-size: 14px;
  font-weight: 600;
  padding: 12px 16px 4px;
  color: var(--text-secondary);
}

.setting-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
}

.setting-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.setting-label {
  font-size: 15px;
  font-weight: 500;
}

.setting-desc {
  font-size: 12px;
  color: var(--text-secondary);
}

/* Toggle Switch */
.toggle {
  position: relative;
  width: 48px;
  height: 28px;
  flex-shrink: 0;
}

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

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #444;
  border-radius: 28px;
  transition: var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  height: 22px;
  width: 22px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: var(--transition);
}

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

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

/* About */
.about-section {
  margin-top: 32px;
  text-align: center;
}

.about-text {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.8;
}

/* ========================================
   Spec View
   ======================================== */
.spec-section {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.spec-heading {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.spec-text {
  font-size: 14px;
  line-height: 1.8;
  color: var(--text-secondary);
}

/* Principles */
.spec-principles {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

.spec-principle {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.spec-principle p {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
  line-height: 1.6;
}

.spec-principle strong {
  font-size: 14px;
}

.spec-principle-num {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-ready);
  color: white;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 700;
}

/* Flow */
.spec-flow {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.spec-flow-step {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.spec-flow-step p {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
  line-height: 1.6;
}

.spec-flow-step strong {
  font-size: 14px;
}

.spec-flow-badge {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 700;
}

.badge-idling { background: var(--color-idling); }
.badge-working { background: var(--color-working); }
.badge-break { background: var(--color-break); }

.spec-flow-arrow {
  width: 2px;
  height: 16px;
  background: rgba(255, 255, 255, 0.1);
  margin-left: 13px;
}

/* Table */
.spec-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.spec-table th {
  text-align: left;
  padding: 8px 10px;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-secondary);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.spec-table td {
  padding: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  vertical-align: top;
  line-height: 1.6;
}

.spec-table tr:last-child td {
  border-bottom: none;
}

.spec-table td:first-child {
  white-space: nowrap;
  font-weight: 500;
  color: var(--text-primary);
}

.spec-table td:last-child {
  color: var(--text-secondary);
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 380px) {
  .timer-container {
    width: 220px;
    height: 220px;
  }

  .timer-time {
    font-size: 44px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .stat-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-align: left;
  }

  .stat-value {
    margin-bottom: 0;
  }
}

/* ========================================
   Scrollbar
   ======================================== */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}
