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

:root {
  --color-bg: #FAF7F2;
  --color-work: #C4714F;
  --color-break: #7A9E7E;
  --color-long: #5A7EA0;
  --color-text: #3A2E26;
  --color-text-muted: #9A8C7E;
  --color-surface: #F0EBE3;
  --color-ring-track: #E4DDD5;
  --color-active: var(--color-work);
  --color-active-dim: #E8C4B0;
  --ring-r: 120;
  --ring-circ: 753.98;
  --progress: 1;
  --font-timer: 'Fraunces', serif;
  --font-ui: 'Lato', sans-serif;
  --tab-offset: 0px;
  --tab-width: 50%;
}

body {
  font-family: var(--font-ui);
  background-color: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Grain overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

/* --- Layout & Shell --- */
#app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 390px;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
  gap: 0;
}

.app-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 2rem;
}

.app-title {
  font-family: var(--font-timer);
  font-weight: 300;
  font-size: 1.1rem;
  letter-spacing: 0.15em;
  color: var(--color-text-muted);
  text-transform: lowercase;
}

/* --- Mode Tabs --- */
.mode-tabs {
  position: relative;
  display: flex;
  width: 100%;
  background: var(--color-surface);
  border-radius: 100px;
  padding: 4px;
  margin-bottom: 2.5rem;
}

.mode-tab {
  flex: 1;
  position: relative;
  z-index: 1;
  padding: 0.55rem 0.5rem;
  text-align: center;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  cursor: pointer;
  border: none;
  background: none;
  border-radius: 100px;
  transition: color 0.3s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.mode-tab.active {
  color: var(--color-bg);
}

.tab-slider {
  position: absolute;
  top: 4px;
  left: 4px;
  height: calc(100% - 8px);
  width: calc(var(--tab-width) - 4px);
  background: var(--color-active);
  border-radius: 100px;
  transform: translateX(var(--tab-offset));
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1),
    background-color 0.5s ease,
    width 0.3s ease;
}

/* --- Timer Ring (SVG) --- */
.ring-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 2rem;
}

.ring-svg {
  filter: drop-shadow(0 8px 24px rgba(196, 113, 79, 0.18));
  transition: filter 0.5s ease;
  overflow: visible;
}

.ring-track {
  fill: none;
  stroke: var(--color-ring-track);
  stroke-width: 10;
  transition: stroke 0.5s ease;
}

.ring-progress {
  fill: none;
  stroke: var(--color-active);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: var(--ring-circ);
  stroke-dashoffset: calc(var(--ring-circ) * (1 - var(--progress)));
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
  transition: stroke-dashoffset 1s linear,
    stroke 0.5s ease;
}

/* --- Timer Display (inside ring) --- */
.timer-face {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
}

.timer-display {
  font-family: var(--font-timer);
  font-weight: 300;
  font-size: 4rem;
  line-height: 1;
  color: var(--color-text);
  cursor: pointer;
  letter-spacing: -0.02em;
  transition: color 0.3s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.timer-display.running {
  animation: pulse-tick 1s ease-in-out infinite;
}

.timer-label {
  font-family: var(--font-ui);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

/* --- Edit Mode (inline duration editing) --- */
.edit-overlay {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.edit-overlay.visible {
  display: flex;
}

.timer-display.hidden,
.timer-label.hidden {
  display: none;
}

.edit-inputs {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.edit-input {
  font-family: var(--font-timer);
  font-weight: 300;
  font-size: 3rem;
  width: 3ch;
  text-align: center;
  background: none;
  border: none;
  border-bottom: 2px solid var(--color-active);
  color: var(--color-text);
  outline: none;
  -webkit-appearance: none;
  -moz-appearance: textfield;
  appearance: none;
}

.edit-input::-webkit-outer-spin-button,
.edit-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
}

.edit-sep {
  font-family: var(--font-timer);
  font-size: 3rem;
  font-weight: 300;
  color: var(--color-text-muted);
}

.edit-hint {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.version-tag {
  position: absolute;
  bottom: 1.2rem;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
  opacity: 0.4;
  text-transform: uppercase;
  pointer-events: none;
}

/* --- Session Name Input --- */
.session-name-input {
  background: transparent;
  border: none;
  color: var(--color-text);
  font-family: var(--font-timer);
  font-size: 1.2rem;
  font-weight: 300;
  text-align: center;
  width: 100%;
  max-width: 80%;
  margin-bottom: -1rem;
  padding: 0.5rem;
  outline: none;
  opacity: 0.5;
  transition: opacity 0.3s ease;
  z-index: 10;
}

.session-name-input:focus {
  opacity: 1;
}

.session-name-input::placeholder {
  color: var(--color-text-muted);
  opacity: 0.7;
}

/* --- Controls --- */
.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: transform 0.15s ease, opacity 0.2s ease;
}

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

.btn-reset {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--color-surface);
  color: var(--color-text-muted);
}

.btn-play {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--color-active);
  color: var(--color-bg);
  box-shadow: 0 6px 24px rgba(196, 113, 79, 0.35);
  transition: background-color 0.5s ease,
    box-shadow 0.5s ease,
    transform 0.15s ease;
}

.btn-play:hover {
  box-shadow: 0 8px 30px rgba(196, 113, 79, 0.45);
}

.btn-skip {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--color-surface);
  color: var(--color-text-muted);
}

.btn-history {
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: background 0.2s;
}

.btn-history:hover {
  background: rgba(0, 0, 0, 0.05);
}

/* --- History Tray --- */
.history-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(4px);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.history-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.history-tray {
  position: fixed;
  top: 0;
  right: -320px;
  width: 320px;
  height: 100%;
  background: var(--color-bg);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.1);
  z-index: 101;
  display: flex;
  flex-direction: column;
  transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.history-tray.active {
  right: 0;
}

.history-header {
  padding: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.history-header h2 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  color: var(--color-text);
}

.history-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.history-item {
  background: var(--color-surface);
  padding: 16px;
  border-radius: 12px;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  animation: slideIn 0.3s ease-out;
}

.history-item-info {
  display: flex;
  flex-direction: column;
}

.history-item-name {
  font-weight: 600;
  color: var(--color-text);
}

.history-item-date {
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.history-item-duration {
  font-family: var(--font-timer);
  font-size: 1.1rem;
  color: var(--color-accent);
}

.history-item.pending {
  border-left: 4px solid #F1C40F;
}

.history-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--color-text-muted);
  font-style: italic;
}

.history-footer {
  padding: 16px 24px;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  border-top: 1px solid rgba(0, 0, 0, 0.05);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(20px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

/* --- Pomodoro Dots --- */
.pomo-dots {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
  max-width: 80%;
}

.pomo-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--color-ring-track);
  transition: background 0.4s ease, transform 0.3s ease;
}

.pomo-dot.filled {
  background: var(--color-work);
  transform: scale(1.15);
}

/* --- Animations & Transitions --- */
@keyframes pulse-tick {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.82;
  }
}

@keyframes pop-in {
  0% {
    transform: scale(0.7);
    opacity: 0;
  }

  80% {
    transform: scale(1.05);
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.dot-pop {
  animation: pop-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Color transition for whole app */
#app {
  transition: background-color 0.5s ease;
}

/* --- Responsive / Desktop centering --- */
@media (min-width: 480px) {
  #app {
    background: var(--color-bg);
    border-radius: 2rem;
    min-height: auto;
    max-height: 780px;
    box-shadow: 0 20px 60px rgba(58, 46, 38, 0.1);
    padding: 3rem 2rem;
  }

  body {
    background: #EDE8E0;
  }
}

/* --- Visual Alerts --- */
@keyframes flash-complete {

  0%,
  100% {
    background-color: var(--color-bg);
  }

  50% {
    background-color: var(--color-active);
    opacity: 0.8;
  }
}

.session-complete-flash {
  animation: flash-complete 0.8s ease-in-out 3;
}

/* --- Auth Modal --- */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: var(--color-bg);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.auth-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.auth-modal {
  background: var(--color-surface);
  padding: 2.5rem 2rem;
  border-radius: 1.5rem;
  width: 90%;
  max-width: 340px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.auth-title {
  font-family: var(--font-timer);
  font-size: 1.6rem;
  font-weight: 300;
  color: var(--color-text);
  margin-bottom: 0.5rem;
}

.auth-subtitle {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-bottom: 1.5rem;
}

.auth-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.auth-input {
  width: 100%;
  padding: 1rem;
  border-radius: 0.8rem;
  border: 1px solid rgba(0, 0, 0, 0.05);
  background: var(--color-bg);
  font-family: var(--font-ui);
  font-size: 0.95rem;
  color: var(--color-text);
  outline: none;
  transition: border-color 0.2s;
}

.auth-input:focus {
  border-color: var(--color-active);
}

.btn-primary {
  width: 100%;
  padding: 1rem;
  border-radius: 0.8rem;
  border: none;
  background: var(--color-text);
  color: var(--color-bg);
  font-family: var(--font-ui);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 0.5rem;
  transition: transform 0.15s ease, opacity 0.2s;
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.auth-error {
  color: #E74C3C;
  font-size: 0.8rem;
  font-weight: 600;
  margin-top: 1rem;
  min-height: 1rem;
}

.btn-text {
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 1rem;
  text-decoration: underline;
}