/* Fokus-Timer Pro - eigene Palette: Fokus-Dunkel #111827 + Tomatenrot #ef4444 */
:root {
  --tomato: #ef4444;
  --tomato-soft: #f87171;
  --tomato-deep: #dc2626;
  --green: #10b981;
  --blue: #3b82f6;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --gap: 16px;
  --maxw: 640px;
  --ring-circ: 628.3185307; /* 2*pi*100 */
}

/* DARK (Default) */
[data-theme="dark"] {
  --bg: #111827;
  --bg-2: #0b1220;
  --surface: #1f2937;
  --surface-2: #273548;
  --border: #334155;
  --text: #f1f5f9;
  --text-dim: #94a3b8;
  --accent: var(--tomato);
  --accent-contrast: #ffffff;
  --track: #334155;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

/* LIGHT */
[data-theme="light"] {
  --bg: #f5f6f8;
  --bg-2: #eceef2;
  --surface: #ffffff;
  --surface-2: #f1f3f7;
  --border: #d8dde6;
  --text: #111827;
  --text-dim: #5b6677;
  --accent: var(--tomato);
  --accent-contrast: #ffffff;
  --track: #e2e6ed;
  --shadow: 0 8px 24px rgba(17, 24, 39, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  transition: background 0.25s ease, color 0.25s ease;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-contrast);
  padding: 10px 16px;
  border-radius: 0 0 var(--radius-sm) 0;
  z-index: 200;
}
.skip-link:focus { left: 0; }

/* HEADER */
.app-header {
  max-width: var(--maxw);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 8px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px; height: 42px;
  border-radius: 12px;
  color: var(--accent-contrast);
  background: linear-gradient(135deg, var(--tomato-soft), var(--tomato-deep));
  flex: 0 0 auto;
  box-shadow: 0 4px 14px rgba(239, 68, 68, 0.4);
}
.brand h1 {
  font-size: 1.25rem;
  margin: 0;
  font-weight: 800;
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.brand-pro {
  color: var(--accent);
  font-weight: 800;
}

.icon-btn {
  flex: 0 0 auto;
  width: 44px; height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 1.2rem;
  display: grid;
  place-items: center;
  transition: background 0.2s, transform 0.1s;
}
.icon-btn:active { transform: scale(0.94); }
.theme-icon { line-height: 1; }
[data-theme="dark"] .theme-icon-dark { display: none; }
[data-theme="light"] .theme-icon-light { display: none; }

/* TABS */
.tabs {
  max-width: var(--maxw);
  margin: 0 auto;
  display: flex;
  gap: 6px;
  padding: 10px 14px 0;
  flex-wrap: wrap;
}
.tab {
  flex: 1 1 auto;
  min-width: 100px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.tab.is-active {
  color: var(--accent-contrast);
  background: var(--accent);
  border-color: var(--accent);
}

/* MAIN / VIEWS */
main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 16px 18px 48px;
}
.view { display: none; animation: fade 0.25s ease; }
.view.is-active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* PHASE BADGE */
.phase-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 4px auto 0;
  padding: 8px 16px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  background: var(--surface);
}
.phase-badge { display: flex; width: fit-content; }
.phase-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--accent);
}
.phase-badge[data-phase="work"] { color: var(--tomato); }
.phase-badge[data-phase="work"] .phase-dot { background: var(--tomato); }
.phase-badge[data-phase="short"] { color: var(--green); }
.phase-badge[data-phase="short"] .phase-dot { background: var(--green); }
.phase-badge[data-phase="long"] { color: var(--blue); }
.phase-badge[data-phase="long"] .phase-dot { background: var(--blue); }

/* TIMER RING */
.timer-wrap {
  position: relative;
  width: min(78vw, 320px);
  aspect-ratio: 1 / 1;
  margin: 22px auto;
}
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track {
  fill: none;
  stroke: var(--track);
  stroke-width: 12;
}
.ring-progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 12;
  stroke-linecap: round;
  stroke-dasharray: var(--ring-circ);
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.5s linear, stroke 0.3s ease;
}
.timer-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 6px;
}
.timer-display {
  font-size: clamp(2.6rem, 14vw, 4rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.round-info { color: var(--text-dim); font-size: 0.9rem; font-weight: 600; }

/* CONTROLS */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin: 8px 0 20px;
}
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 13px 20px;
  border-radius: 14px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, background 0.2s, opacity 0.2s, filter 0.2s;
}
.btn:active { transform: scale(0.96); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
  min-width: 130px;
  box-shadow: 0 6px 18px rgba(239, 68, 68, 0.35);
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { background: var(--surface); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger {
  background: transparent;
  border-color: var(--tomato);
  color: var(--tomato);
}
.btn-danger:hover { background: rgba(239, 68, 68, 0.12); }

/* TODAY STRIP */
.today-strip {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.today-item {
  flex: 1 1 130px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.today-num {
  display: block;
  font-size: 1.9rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1.1;
}
.today-cap { color: var(--text-dim); font-size: 0.85rem; font-weight: 600; }

/* STATS */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.stat-value {
  display: block;
  font-size: 1.7rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1.15;
  word-break: break-word;
}
.stat-label { color: var(--text-dim); font-size: 0.82rem; font-weight: 600; }

.section-title {
  font-size: 1.05rem;
  margin: 8px 0 4px;
  font-weight: 800;
}
.section-hint {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin: 0 0 14px;
}

.hour-chart {
  display: grid;
  grid-template-columns: repeat(24, 1fr);
  align-items: end;
  gap: 2px;
  height: 180px;
  padding: 8px 6px 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.hour-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  min-width: 0;
  gap: 4px;
}
.hour-bar-fill {
  width: 100%;
  background: linear-gradient(180deg, var(--tomato-soft), var(--tomato));
  border-radius: 4px 4px 0 0;
  min-height: 2px;
  transition: height 0.4s ease;
}
.hour-bar-fill.is-best {
  background: linear-gradient(180deg, #fcd34d, #f59e0b);
}
.hour-bar-label {
  font-size: 0.5rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.stats-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 22px;
}
.stats-footer .btn { flex: 1 1 150px; }

/* SETTINGS */
.settings {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 700; font-size: 0.92rem; }
.field input[type="number"] {
  appearance: none;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  font-size: 1.05rem;
  font-weight: 600;
}
.field-switch {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.field-switch label { margin: 0; }

.switch {
  flex: 0 0 auto;
  width: 52px; height: 30px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  position: relative;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}
.switch-knob {
  position: absolute;
  top: 2px; left: 2px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform 0.2s, background 0.2s;
}
.switch[aria-checked="true"] {
  background: var(--accent);
  border-color: var(--accent);
}
.switch[aria-checked="true"] .switch-knob {
  transform: translateX(22px);
  background: #fff;
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 6px;
}
.settings-actions .btn { flex: 1 1 150px; }

.about-text {
  color: var(--text-dim);
  font-size: 0.84rem;
  margin-top: 24px;
  line-height: 1.6;
}

/* TOASTS */
.toast-wrap {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 300;
  width: min(92vw, 420px);
  pointer-events: none;
}
.toast {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  font-weight: 600;
  font-size: 0.95rem;
  pointer-events: auto;
  animation: toastIn 0.3s ease;
}
.toast.toast-work { border-left-color: var(--tomato); }
.toast.toast-short { border-left-color: var(--green); }
.toast.toast-long { border-left-color: var(--blue); }
.toast.toast-out { animation: toastOut 0.3s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(14px); } }

/* MODAL */
.modal {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
}
.modal-box {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  width: min(92vw, 400px);
  box-shadow: var(--shadow);
  animation: fade 0.2s ease;
}
.modal-title { margin: 0 0 8px; font-size: 1.15rem; font-weight: 800; }
.modal-desc { margin: 0 0 18px; color: var(--text-dim); }
.modal-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.modal-actions .btn { flex: 1 1 120px; }

/* FOCUS STATES */
:focus-visible {
  outline: 3px solid var(--tomato-soft);
  outline-offset: 2px;
  border-radius: 6px;
}

/* RESPONSIVE */
@media (min-width: 520px) {
  .stat-cards { grid-template-columns: repeat(4, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
