:root {
  --bg: #f4f6f8;
  --card-bg: #ffffff;
  --text: #1c2530;
  --text-muted: #6b7684;
  --focus: #3b6fd6;
  --focus-ring-bg: #e3e9f3;
  --break: #2e9e6b;
  --break-ring-bg: #e1f2ea;
  --long-break: #b1791e;
  --long-break-ring-bg: #f5e9d6;
  --border: #e3e6ea;
  --shadow: 0 10px 30px rgba(30, 40, 60, 0.08);
  --danger: #c0392b;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161c;
    --card-bg: #1b2129;
    --text: #eef1f5;
    --text-muted: #98a2b0;
    --focus: #6d95e6;
    --focus-ring-bg: #26314a;
    --break: #52c790;
    --break-ring-bg: #1e3a2c;
    --long-break: #e0a94b;
    --long-break-ring-bg: #3a2f1c;
    --border: #2a313b;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Segoe UI", Roboto, sans-serif;
  display: flex;
  justify-content: center;
  transition: background 0.4s ease;
}

.app {
  width: 100%;
  max-width: 480px;
  padding: 24px 20px 48px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 6px;
  border-radius: 10px;
  line-height: 1;
}
.icon-btn:hover { background: var(--border); }

.timer-card {
  background: var(--card-bg);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.mode-label {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--focus);
  transition: color 0.4s ease;
}

.ring-wrap {
  position: relative;
  width: min(280px, 68vw);
  height: min(280px, 68vw);
}

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

.ring-bg {
  fill: none;
  stroke: var(--focus-ring-bg);
  stroke-width: 12;
  transition: stroke 0.4s ease;
}

.ring-progress {
  fill: none;
  stroke: var(--focus);
  stroke-width: 12;
  stroke-linecap: round;
  stroke-dasharray: 628.3185;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.35s linear, stroke 0.4s ease;
}

.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.time {
  font-size: clamp(2.6rem, 10vw, 3.4rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.session-count {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.btn {
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  transition: transform 0.15s ease, background 0.2s ease, opacity 0.2s ease;
}
.btn:active { transform: scale(0.96); }

.btn-primary {
  background: var(--focus);
  color: #fff;
  font-size: 1.05rem;
  padding: 16px 40px;
  border-radius: 999px;
}

.btn-secondary {
  background: var(--border);
  color: var(--text);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-text {
  background: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  text-decoration: underline;
  padding: 4px;
}

.phase-dots {
  display: flex;
  gap: 8px;
}
.phase-dots .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
}
.phase-dots .dot.filled {
  background: var(--focus);
}

.stats-row {
  display: flex;
  gap: 16px;
}
.stat {
  flex: 1;
  background: var(--card-bg);
  border-radius: 16px;
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-value {
  font-size: 1.4rem;
  font-weight: 700;
}
.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.settings-panel {
  background: var(--card-bg);
  border-radius: 20px;
  padding: 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.settings-panel h2 {
  margin: 0 0 4px;
  font-size: 1.05rem;
}
.field {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  gap: 12px;
}
.field input[type="number"] {
  width: 80px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}
.checkbox-field {
  justify-content: flex-start;
}
.checkbox-field input {
  width: 18px;
  height: 18px;
}
.settings-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
}
.settings-actions .btn-primary {
  padding: 10px 28px;
  font-size: 0.95rem;
}
.hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 4px 0 0;
  line-height: 1.5;
}

.finish-banner {
  position: fixed;
  inset: 0;
  background: rgba(59, 111, 214, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  animation: flashIn 0.3s ease;
}
.finish-banner.break {
  background: rgba(46, 158, 107, 0.92);
}
.finish-message {
  color: #fff;
  font-size: clamp(1.4rem, 6vw, 2rem);
  font-weight: 700;
  text-align: center;
  padding: 0 24px;
}
@keyframes flashIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (max-width: 360px) {
  .btn-primary { padding: 14px 30px; }
}
