/* ============================================================
   style.css — Pomodoro Timer
   Mobile-first, no framework dependencies
   ============================================================ */

/* ---------- Reset & tokens ---------- */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-bg:          #ffffff;
  --color-surface:     #f5f5f5;
  --color-surface-alt: #e8e8e8;
  --color-accent:      #222222;
  --color-interaction-hover: #e0e0e0;
  --color-text:        #111111;
  --color-text-muted:  #767676;
  --color-border:      #d0d0d0;

  --radius-sm:  6px;
  --radius-md: 12px;
  --radius-lg: 20px;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.5);

  --font-mono: 'Courier New', Courier, monospace;
  --transition: 0.18s ease;
}

/* ---------- Dark theme tokens ---------- */

:root[data-theme="dark"] {
  --color-bg:          #1a1a1a;
  --color-surface:     #252525;
  --color-surface-alt: #333333;
  --color-accent:      #e0e0e0;
  --color-interaction-hover: #444444;
  --color-text:        #e8e8e8;
  --color-text-muted:  #909090;
  --color-border:      #3a3a3a;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.6);
  --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.8);
}

/* System theme: follow OS preference */
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --color-bg:          #1a1a1a;
    --color-surface:     #252525;
    --color-surface-alt: #333333;
    --color-accent:      #e0e0e0;
    --color-interaction-hover: #444444;
    --color-text:        #e8e8e8;
    --color-text-muted:  #909090;
    --color-border:      #3a3a3a;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.6);
    --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.8);
  }
}

html, body {
  height: 100%;
}

html {
  scrollbar-gutter: stable;
}

body {
  background-color: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Sans',
               'Noto Sans JP', sans-serif;
  font-size: 16px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  align-items: center;
}

body.modal-open {
  overflow: hidden;
  overscroll-behavior: none;
  min-height: 100vh;
}

/* ---------- Layout ---------- */

.main {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  padding: 24px 20px 40px;
  gap: 32px;
}

/* ---------- Header ---------- */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.app-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-text-muted);
  letter-spacing: 0.08em;
}

/* ---------- Icon button ---------- */

.btn-icon {
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition), background var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.btn-icon:hover, .btn-icon:focus-visible {
  color: var(--color-text);
  background: var(--color-surface-alt);
  outline: none;
}

/* ---------- Timer section ---------- */

.timer-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.mode-label {
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

/* ---------- Progress bar ---------- */

.progress-bar-track {
  width: 100%;
  height: 6px;
  background: var(--color-surface-alt);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--color-accent);
  border-radius: 3px;
  transition: width 0.3s linear;
}

.timer-display {
  font-family: var(--font-mono);
  font-size: clamp(4rem, 20vw, 7rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--color-text);
  line-height: 1;
}

.timer-controls {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
}

.tag-section {
  width: 100%;
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  max-width: 100%;
  position: relative;
}

.tag-icon {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  color: var(--color-text-muted);
}

.tag-select {
  width: 270px;
  min-width: 0;
  flex: 0 1 270px;
  position: relative;
}

.tag-select--empty {
  width: 40px;
  flex: 0 0 40px;
}

.tag-select:not(.tag-select--empty) {
  width: auto;
  flex: 0 1 auto;
}

.tag-select summary {
  display: flex;
  align-items: center;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 0.875rem;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  list-style: none;
}

.tag-select summary::-webkit-details-marker {
  display: none;
}

.tag-select--empty summary {
  justify-content: center;
  padding: 0;
  border-radius: 50%;
  font-size: 1.5rem;
}

.tag-select:not(.tag-select--empty) summary {
  justify-content: flex-end;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
}

.tag-select .tag-panel {
  right: 0;
  left: auto;
  width: 200px;
}

.tag-panel {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  left: 0;
  width: 100%;
  padding: 4px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
}

.tag-list {
  max-height: 200px;
  overflow-y: auto;
  list-style: none;
}

.tag-list li {
  display: flex;
}

.tag-list li:hover {
  background: var(--color-surface-alt);
}

.tag-choose,
.tag-remove {
  border: 0;
  background: none;
  color: var(--color-text);
  padding: 8px;
  font: inherit;
  cursor: pointer;
}

.tag-choose {
  flex: 1;
  min-width: 0;
  text-align: left;
  overflow-wrap: anywhere;
}

.tag-choose[aria-pressed="true"] {
  font-weight: 700;
}

.tag-remove {
  color: var(--color-text-muted);
  min-width: 40px;
}

.tag-remove.armed {
  color: var(--color-text);
}

.tag-input {
  width: 100%;
  margin-top: 4px;
  height: 42px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text);
  padding: 8px;
  font: inherit;
}

/* ---------- Buttons ---------- */

.btn {
  font-size: 1rem;
  font-weight: 600;
  padding: 14px 36px;
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: background var(--transition), box-shadow var(--transition), transform var(--transition);
  -webkit-tap-highlight-color: transparent;
  min-width: 120px;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--color-accent);
  color: var(--color-bg);
}

.btn-primary:hover, .btn-primary:focus-visible {
  background: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-bg), 0 0 0 5px var(--color-accent);
  outline: none;
}

.btn-secondary {
  background: var(--color-surface-alt);
  color: var(--color-text);
}

.btn-secondary:hover, .btn-secondary:focus-visible {
  background: var(--color-interaction-hover);
  box-shadow: 0 0 0 2px var(--color-accent);
  outline: none;
}

/* ---------- Stats ---------- */

.stats-section {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-top: 50px;
}

.stats {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stats-heading {
  font-size: 1.00rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.stats-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--color-text-muted);
  font-size: 1.25rem;
}

.stats-value {
  color: var(--color-text);
}

#todayCount,
#todayHours,
#todayMinutes {
  font-size: 1.8rem;
  font-weight: 700;
}

.stats-duration {
  display: inline-flex;
  align-items: center;
}

.stats-sep {
  opacity: 0.4;
}

/* ---------- Missed-completion banner ---------- */

.banner {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-surface-alt);
  color: var(--color-text);
  padding: 14px 20px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 90vw;
  font-size: 0.95rem;
  z-index: 200;
  transition: opacity var(--transition), visibility var(--transition);
  border-left: 4px solid var(--color-accent);
}

.banner--hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.banner-close {
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  line-height: 1;
  flex-shrink: 0;
}

.banner-close:hover {
  color: var(--color-text);
}

/* ---------- Settings modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  overscroll-behavior: contain;
  transition: opacity var(--transition), visibility var(--transition);
}

.modal-backdrop--hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

@media (min-width: 480px) {
  .modal-backdrop {
    align-items: center;
  }
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 16px);
  max-height: calc(100dvh - 16px);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

@media (min-width: 480px) {
  .modal {
    border-radius: var(--radius-lg);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 0;
  flex: 0 0 auto;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 600;
}

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.modal-footer {
  padding: 0 20px 24px;
  flex: 0 0 auto;
}

/* ---------- Setting groups ---------- */

.setting-group {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 16px;
}

.setting-legend {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0 4px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
}

.setting-label {
  font-size: 0.95rem;
  flex: 1;
}

/* ---------- Toggle ---------- */

.setting-toggle {
  position: relative;
  display: inline-flex;
  flex: 0 0 56px;
  width: 56px;
  height: 32px;
}

.setting-toggle .setting-checkbox {
  position: absolute;
  z-index: 1;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.setting-toggle-track {
  position: absolute;
  inset: 0;
  border: 2px solid var(--color-text);
  border-radius: 16px;
  background: var(--color-surface-alt);
  pointer-events: none;
  transition: background 160ms ease, border-color 160ms ease;
}

.setting-toggle-track::after {
  content: '';
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--color-text);
  transition: transform 160ms ease, background 160ms ease;
}

.setting-toggle .setting-checkbox:checked + .setting-toggle-track {
  border-color: var(--color-text);
  background: var(--color-text);
}

.setting-toggle .setting-checkbox:checked + .setting-toggle-track::after {
  transform: translateX(24px);
  background: var(--color-bg);
}

.setting-toggle .setting-checkbox:focus-visible + .setting-toggle-track {
  outline: 3px solid var(--color-accent);
  outline-offset: 3px;
}

/* ---------- Stepper ---------- */

.stepper {
  display: flex;
  align-items: center;
  gap: 0;
}

.stepper-btn {
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  width: 36px;
  height: 36px;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.stepper-btn:first-child {
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.stepper-btn:last-child {
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.stepper-btn:hover {
  background: var(--color-interaction-hover);
  box-shadow: inset 0 0 0 2px var(--color-accent);
}

.stepper-input {
  width: 48px;
  height: 36px;
  text-align: center;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-left: none;
  border-right: none;
  color: var(--color-text);
  font-size: 1rem;
  -moz-appearance: textfield;
}

.stepper-input::-webkit-inner-spin-button,
.stepper-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

/* ---------- Select ---------- */

.setting-select {
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  cursor: pointer;
}

.setting-select:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* ---------- Range slider ---------- */

.setting-range {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--color-surface-alt);
  cursor: pointer;
}

.setting-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-accent);
  cursor: pointer;
}

.setting-range::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-accent);
  border: none;
  cursor: pointer;
}

.setting-range-value {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  min-width: 36px;
  text-align: right;
}

/* ---------- Save button (full width in footer) ---------- */

.modal-footer .btn {
  width: 100%;
}

/* ---------- Focus ring (accessibility) ---------- */

:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}



/* ---------- App description ---------- */

.app-description {
  width: 100%;
  max-width: 400px;
  padding: 0 20px 40px;
}

.app-description ul {
  padding-left: 1.25rem;
}