:root {
  --bg: #fafafa;
  --accent: #eaab45;
  --accent-hover: #dd9a30;
  --on-accent: #312f2c;
  --ink: #312f2c;
  --ink-soft: #8a8378;
  --ink-faint: #c4bdb0;
  --surface: #ffffff;
  --cream: #faefd9;
  --border: #eae6dd;
  --danger: #c0453b;
  --rest: #4fb6e0;
  --rest-long: #b46fe0;
}

:root[data-theme="dark"] {
  --bg: #1b1a17;
  --accent: #f0b558;
  --accent-hover: #f5c273;
  --on-accent: #1b1a17;
  --ink: #f3f0ea;
  --ink-soft: #9c9689;
  --ink-faint: #6b6558;
  --surface: #221f1b;
  --cream: #2e2a22;
  --border: #3a352c;
  --danger: #e0736a;
  --rest: #6ac4e8;
  --rest-long: #c186e8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Libre Franklin", sans-serif;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 96px 20px 64px;
  transition: background 0.25s ease, color 0.25s ease;
}

.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 26px;
  pointer-events: none;
}

.top-bar > * {
  pointer-events: auto;
}

.back-link {
  font-family: "Libre Franklin", sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  transition: color 0.2s ease, border-color 0.2s ease;
}

.back-link:hover {
  color: var(--ink);
  border-color: var(--ink-faint);
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  border: none;
  cursor: pointer;
  background: var(--cream);
  color: var(--ink);
  font-family: "Libre Franklin", sans-serif;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 999px;
  transition: background 0.25s ease, color 0.25s ease;
}

.theme-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

body.in-session {
  align-items: center;
}

/* Views */
.view {
  animation: view-in 0.26s ease both;
}

.hidden,
[hidden] {
  display: none !important;
}

@keyframes view-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.app {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

/* Session layout.
   Tasks sit in the far-left column; the empty third column mirrors it
   so the timer still sits dead centre on the page. */
.session-grid {
  display: grid;
  grid-template-columns: 300px auto 300px;
  justify-content: center;
  align-items: center;
  gap: 84px;
  width: 100%;
}

.session-main {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.session-tasks {
  /* Explicit grid-row is required: session-tasks comes after session-main in
     the DOM but sits in an earlier column, and grid auto-placement can't
     move backward within a row — without this it drops to row 2. */
  grid-column: 1;
  grid-row: 1;
  width: 300px;
  align-self: center;
}

/* Done */
.done-view {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  text-align: center;
}

.done-emoji {
  font-size: 48px;
  animation: pop-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.done-title {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
}

.done-subject {
  margin: 0;
  font-family: "Newsreader", serif;
  font-style: italic;
  font-size: 18px;
  color: var(--ink-soft);
}

.done-stats {
  display: flex;
  gap: 12px;
  width: 100%;
  margin: 6px 0;
}

.done-stat {
  flex: 1;
  background: var(--cream);
  border-radius: 14px;
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.done-stat-value {
  font-family: "IBM Plex Mono", monospace;
  font-size: 24px;
  font-weight: 600;
  color: var(--ink);
}

.done-stat-label {
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.3;
}

@keyframes pop-in {
  from { opacity: 0; transform: scale(0.6); }
  to { opacity: 1; transform: scale(1); }
}

/* Subject input */
.subject-input {
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  text-align: center;
  font-family: "Newsreader", serif;
  font-style: italic;
  font-size: 22px;
  color: var(--ink);
  padding: 8px 4px 14px;
  outline: none;
  transition: border-color 0.2s ease;
}

.subject-input::placeholder {
  color: var(--ink-faint);
  font-style: italic;
}

.subject-input:focus {
  border-color: var(--accent);
}

/* Config steppers */
.config-grid {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

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

.stepper-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
}

.stepper-control {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
}

.stepper-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s ease, color 0.2s ease;
}

.stepper-btn:hover {
  background: var(--cream);
  color: var(--ink);
}

.stepper-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  text-align: center;
  font-family: "IBM Plex Mono", monospace;
  font-size: 18px;
  font-weight: 500;
  color: var(--ink);
  outline: none;
  -moz-appearance: textfield;
}

.stepper-input::-webkit-outer-spin-button,
.stepper-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.session-preview {
  margin: -8px 0 0;
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
  color: var(--ink-soft);
}

/* Ring */
.ring-wrap {
  position: relative;
  width: 320px;
  height: 320px;
}

.ring {
  transform: rotate(-90deg);
}

.ring-track {
  fill: none;
  stroke: var(--border);
  stroke-width: 7;
}

.ring-progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 7;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.3s linear, stroke 0.4s ease;
}

.ring-progress.breathing {
  animation: ring-breathe 4s ease-in-out infinite;
}

@keyframes ring-breathe {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.ring-wrap[data-block="short"] .ring-progress { stroke: var(--rest); }
.ring-wrap[data-block="long"] .ring-progress { stroke: var(--rest-long); }

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

.time-display {
  font-family: "IBM Plex Mono", monospace;
  font-size: 64px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--ink);
  transition: opacity 0.25s ease;
}

.block-label {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
  animation: fade-in 0.4s ease both;
}

.session-main.paused .time-display {
  opacity: 0.55;
}

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

.btn {
  font-family: "Libre Franklin", sans-serif;
  border: none;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.1s ease;
}

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

.btn-ghost {
  height: 48px;
  padding: 0 22px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.btn-ghost:hover {
  color: var(--ink);
  border-color: var(--ink-faint);
}

.btn-main {
  min-width: 152px;
  padding: 14px 28px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.btn-main:hover {
  background: var(--accent-hover);
}

.btn-wide {
  width: 100%;
}

.end-session-link {
  border: none;
  background: transparent;
  color: var(--ink-faint);
  font-family: "Libre Franklin", sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  padding: 6px 10px;
  transition: color 0.2s ease;
}

.end-session-link:hover {
  color: var(--danger);
}

/* Session progress */
.session-progress {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.dots {
  display: flex;
  gap: 8px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.25s ease, transform 0.25s ease;
}

.dot.filled {
  background: var(--accent);
}

.dot.current {
  background: var(--accent);
  transform: scale(1.4);
}

.progress-label {
  margin: 0;
  font-size: 13px;
  color: var(--ink-soft);
}

/* Task section */
.task-section {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
}

.task-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
  transition: margin 0.25s ease;
}

.task-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tasks-collapse-btn {
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, color 0.2s ease, transform 0.25s ease;
}

.tasks-collapse-btn:hover {
  background: var(--cream);
  color: var(--ink);
}

.session-tasks.collapsed .tasks-collapse-btn {
  transform: rotate(-90deg);
}

.session-tasks .task-list {
  max-height: 400px;
  opacity: 1;
  overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.2s ease;
}

.session-tasks.collapsed .task-header {
  margin-bottom: 0;
}

.session-tasks.collapsed .task-list {
  max-height: 0;
  opacity: 0;
}

.task-header h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
}

.task-counter {
  font-family: "IBM Plex Mono", monospace;
  font-size: 13px;
  color: var(--ink-soft);
}

.task-form {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.task-form input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: "Libre Franklin", sans-serif;
  font-size: 14px;
  outline: none;
  background: var(--bg);
  color: var(--ink);
}

.task-form input:focus {
  border-color: var(--accent);
}

.btn-add {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
}

.btn-add:hover {
  background: var(--accent-hover);
}

.task-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.task-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 4px;
  border-bottom: 1px solid var(--border);
}

.task-item:last-child {
  border-bottom: none;
}

.task-check {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1.5px solid var(--ink-faint);
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--on-accent);
  font-size: 11px;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.task-item.done .task-check {
  background: var(--accent);
  border-color: var(--accent);
}

.task-check.pop {
  animation: check-pop 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes check-pop {
  0% { transform: scale(0.8); }
  60% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

/* The strike-through is a background line, not text-decoration, so it can sweep in. */
.task-text {
  flex: 1;
  font-size: 14px;
  color: var(--ink);
  word-break: break-word;
  background-image: linear-gradient(currentColor, currentColor);
  background-repeat: no-repeat;
  background-position: 0 58%;
  background-size: 0% 1.5px;
  transition: background-size 0.3s ease, color 0.3s ease;
}

.task-item.done .task-text {
  background-size: 100% 1.5px;
  color: var(--ink-faint);
}

.task-delete {
  border: none;
  background: transparent;
  color: var(--ink-faint);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 6px;
  line-height: 1;
  transition: color 0.2s ease;
}

.task-delete:hover {
  color: var(--danger);
}

.task-empty {
  font-size: 13px;
  color: var(--ink-faint);
  text-align: center;
  padding: 8px 0;
}

/* Study background picker */
.bg-picker {
  display: flex;
  align-items: center;
  gap: 14px;
}

.bg-preview {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  background-color: var(--cream);
  background-size: cover;
  background-position: center;
  border: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.bg-preview-hint {
  font-size: 10px;
  color: var(--ink-faint);
  text-align: center;
  padding: 0 4px;
  line-height: 1.3;
}

.bg-picker-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.bg-picker-actions .btn-ghost {
  cursor: pointer;
}

.bg-remove-btn:hover {
  color: var(--danger);
  border-color: var(--danger);
}

.bg-hint {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--ink-faint);
}

.bg-error {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--danger);
}

/* The uploaded image only shows once the session is running. */
body.session-bg {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
}

/* A readable disc behind the ring content, since the ring itself has no fill.
   .ring-center is already position:absolute (fills .ring-wrap), so this pseudo
   just needs to center itself within that box without touching the parent. */
body.session-bg .ring-center::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 264px;
  height: 264px;
  border-radius: 50%;
  background: var(--surface);
  opacity: 0.88;
  backdrop-filter: blur(6px);
  z-index: -1;
}

/* Responsive */
@media (max-width: 900px) {
  body.in-session {
    align-items: flex-start;
  }

  .session-grid {
    grid-template-columns: minmax(0, 420px);
    justify-items: center;
    gap: 32px;
  }

  .session-main,
  .session-tasks {
    grid-column: 1;
    grid-row: auto;
  }

  .session-tasks {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .config-grid {
    grid-template-columns: 1fr;
  }

  .ring-wrap {
    width: 260px;
    height: 260px;
  }

  .ring {
    width: 260px;
    height: 260px;
  }

  .time-display {
    font-size: 52px;
  }

  .controls {
    flex-direction: column;
    width: 100%;
  }

  .controls .btn {
    width: 100%;
  }

  .done-stats {
    flex-direction: column;
  }
}

/* Accessibility: a ring pulsing for 25 minutes is hostile to some people. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .ring-progress.breathing {
    animation: none !important;
    opacity: 1;
  }
}
