/* Brand tokens: see the Thinking Time Bomb design handoff. */
:root {
  --accent: #6cbcec;
  --ink: #111418;
  --white: #ffffff;
  --grey: #8a9099;
  --error: #c0392b;
  --skew: skewX(-12.37deg);
  --display: "Archivo", Helvetica, sans-serif;
  --control-width: 168px;
  font-family: var(--display);
  font-weight: 500;
}

body[data-mode="light"] {
  --bg: #f5f7f9;
  --surface: var(--white);
  --text: var(--ink);
  --muted: #6b717a;
  --line: #e1e5ea;
  --tint: #eef1f4;
  --btn-bg: var(--ink);
  --btn-text: var(--white);
  --label: var(--ink);
}

body[data-mode="dark"] {
  --bg: var(--ink);
  --surface: #1a1f26;
  --text: var(--white);
  --muted: var(--grey);
  --line: #2b323b;
  --tint: #20262e;
  --btn-bg: var(--accent);
  --btn-text: var(--ink);
  --label: var(--accent);
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* Elements like .field set their own display, which would override hidden. */
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
  background: var(--bg);
  color: var(--text);
  transition: background-color 0.5s, color 0.5s;
}

button { font: inherit; color: inherit; cursor: pointer; }

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

/* Header and logo */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}

body[data-mode="light"] .logo-dark,
body[data-mode="dark"] .logo-light { display: none; }

.word {
  display: flex;
  align-items: center;
  gap: 0.18em;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--text);
  transform: var(--skew);
}

.word .dot {
  width: 0.24em;
  height: 0.24em;
  border-radius: 50%;
  background: currentColor;
}

.word .accent { color: var(--accent); }

.topbar-actions { display: flex; gap: 8px; }

.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px 8px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.9rem;
  font-weight: 700;
  transition: border-color 0.15s;
}

.nav-btn:hover { border-color: var(--muted); }

/* On phones the logo icon alone leaves room for the labelled buttons. */
@media (max-width: 479px) {
  .word { display: none; }
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
}

.icon-btn:hover { background: var(--tint); }

.icon-btn:focus-visible,
.step:focus-visible { outline-width: 2px; outline-offset: 0; }

.icon-btn svg,
.nav-btn svg,
.step svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

/* Stage */

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 16px 24px;
  text-align: center;
}

.phase-name {
  margin: 0;
  font-weight: 900;
  font-size: 0.85rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--label);
  transform: var(--skew);
}

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

.cycle-dots span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--line);
}

.cycle-dots span.done { background: var(--accent); }
.cycle-dots span.current { box-shadow: inset 0 0 0 2px var(--text); background: transparent; }

/* The bomb */

.bomb-wrap {
  position: relative;
  width: min(220px, 52vw);
  aspect-ratio: 4 / 5;
  margin-top: 4px;
}

.bomb {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.fuse,
.fuse-track {
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
}

.fuse { stroke: var(--text); }
.fuse-track { stroke: var(--line); stroke-dasharray: 1 2.2; }

.spark { fill: var(--accent); }

.spark-inner {
  transform-box: fill-box;
  transform-origin: center;
}

.bomb-top { fill: var(--ink); }
body[data-mode="dark"] .bomb-top { fill: var(--accent); }

.face {
  fill: var(--white);
  stroke: var(--ink);
  stroke-width: 3.5;
}

body[data-mode="dark"] .face { stroke: none; }

.wedge { fill: var(--accent); opacity: 0.35; }

.hand { fill: var(--accent); }

.pin { fill: var(--ink); }

body.running .spark-inner { animation: flicker 0.18s ease-in-out infinite alternate; }

body.final-seconds .bomb { animation: wobble 0.5s ease-in-out infinite; }

@keyframes flicker {
  from { transform: scale(0.75) rotate(0deg); }
  to { transform: scale(1.2) rotate(20deg); }
}

@keyframes wobble {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-3deg); }
  75% { transform: rotate(3deg); }
}

/* "Boom" burst when a focus session ends. */
.burst {
  position: absolute;
  left: 50%;
  top: 63%;
  pointer-events: none;
}

.burst span {
  position: absolute;
  width: 18px;
  height: 18px;
  margin: -9px;
  background: var(--accent);
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  opacity: 0;
  --angle: calc(var(--i) * 45deg);
}

.bomb-wrap.boom .burst span { animation: burst 0.9s cubic-bezier(0.2, 0.7, 0.3, 1) forwards; }
.bomb-wrap.boom .bomb { animation: boom 0.6s ease-out; }

@keyframes burst {
  0% { opacity: 1; transform: rotate(var(--angle)) translateY(0) scale(0.4); }
  100% { opacity: 0; transform: rotate(var(--angle)) translateY(-150px) scale(1.3); }
}

@keyframes boom {
  0% { transform: scale(1); }
  30% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* Time and controls */

.time {
  margin: 0;
  font-weight: 900;
  font-size: clamp(4.5rem, 21vw, 7rem);
  letter-spacing: -0.03em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  transform: var(--skew);
}

/* "Studying" label and course select drawn as one pill. */
.course-pick {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: min(320px, 90vw);
  padding-left: 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s;
}

.course-pick > span {
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.course-pick select {
  appearance: none;
  min-width: 0;
  padding: 8px 36px 8px 0;
  border: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5l3 3 3-3' fill='none' stroke='%238a9099' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 14px center / 12px;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  text-overflow: ellipsis;
  outline: none;
  cursor: inherit;
}

.course-pick:hover { border-color: var(--muted); }
.course-pick:has(select:focus-visible) { outline: 3px solid var(--accent); outline-offset: 3px; }
.course-pick:has(select:disabled) { opacity: 0.7; border-color: var(--line); cursor: default; }

.controls {
  display: grid;
  justify-items: center;
  gap: 6px;
  margin-top: 8px;
}

.btn-primary {
  min-width: 200px;
  padding: 14px 28px;
  border: 0;
  border-radius: 999px;
  background: var(--btn-bg);
  color: var(--btn-text);
  font-weight: 900;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  transition: transform 0.15s, filter 0.15s;
}

.btn-primary:hover { filter: brightness(1.15); }
.btn-primary:active { transform: scale(0.97); }

.secondary { display: flex; gap: 4px; }

.btn-ghost {
  padding: 8px 16px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.btn-ghost:hover { background: var(--tint); color: var(--text); }

.status {
  margin: 4px 0 0;
  min-height: 1.4em;
  max-width: 32ch;
  font-weight: 700;
}

/* Settings drawer */

.drawer {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(400px, 100%);
  max-width: 100%;
  height: 100%;
  max-height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: -12px 0 40px rgba(17, 20, 24, 0.18);
}

.drawer[open] { animation: slide-in 0.25s ease-out; }
.drawer::backdrop { background: rgba(17, 20, 24, 0.4); }

@keyframes slide-in {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.drawer-body {
  display: grid;
  gap: 20px;
  padding: 16px 20px 24px;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer h2 {
  margin: 0;
  outline: none;
  font-weight: 900;
  font-size: 1.4rem;
  letter-spacing: -0.03em;
  transform: var(--skew);
}

fieldset,
.drawer section {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  border: 0;
}

legend { margin-bottom: 12px; }
.section-title { margin: 0; }

legend,
.section-title {
  padding: 0;
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.stepper {
  flex: none;
  display: flex;
  align-items: center;
  width: var(--control-width);
  height: 44px;
  padding: 0 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  transition: border-color 0.15s;
}

.stepper:focus-within { border-color: var(--accent); }
.stepper:has([aria-invalid="true"]) { border-color: var(--error); }

/* The buttons push to the edges, so the value and unit stay centred. */
.stepper .step:first-child { margin-right: auto; }
.stepper .step:last-child { margin-left: auto; }

.stepper input {
  width: 2.2ch;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 900;
  font-size: 1.05rem;
  text-align: right;
  outline: none;
}

.unit {
  padding-left: 4px;
  font-size: 0.85rem;
  color: var(--muted);
}

.step {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  transition: background-color 0.15s, transform 0.1s;
}

.step svg { width: 14px; height: 14px; }

.step:hover:not(:disabled) { background: var(--tint); }
.step:active:not(:disabled) { transform: scale(0.9); }
.step:disabled { opacity: 0.3; cursor: default; }

.field input[type="range"] {
  width: var(--control-width);
  margin: 0;
  accent-color: var(--accent);
}

.switch {
  appearance: none;
  position: relative;
  flex: none;
  width: 44px;
  height: 26px;
  margin: 0;
  border-radius: 999px;
  background: var(--line);
  cursor: pointer;
  transition: background-color 0.2s;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--white);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s;
}

.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(18px); }

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 4px;
  border-radius: 12px;
  background: var(--tint);
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: block;
  padding: 8px;
  border-radius: 9px;
  text-align: center;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
}

.segmented input:checked + span {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(17, 20, 24, 0.12);
}

.segmented input:focus-visible + span { outline: 3px solid var(--accent); }

#test-sound { justify-self: start; padding-left: 0; }

.hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.errors {
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--error);
  font-weight: 700;
}

.errors:empty { display: none; }

.drawer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.drawer-actions .btn-primary { min-width: 120px; padding: 12px 24px; }

/* Pop-out window: the stylesheet is shared with the page. */

/* Nothing to scroll: the burst may fly past the edges, but stays clipped. */
body.mini-body { grid-template-rows: 1fr; overflow: hidden; }

/* The whole window is one button back to the tab: bomb on the left, phase
   and time on the right. Sizes follow the window, so resizing scales both. */
.mini {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  align-content: center;
  gap: 14px;
  width: 100%;
  min-height: 100vh;
  padding: 10px 16px;
  border: 0;
  background: transparent;
  text-align: left;
}

.mini:focus-visible { outline-offset: -4px; }

/* The bomb is 4:5, so its height is capped by the window height. */
.mini .bomb-wrap { width: min(36vw, (100vh - 20px) * 0.8, 220px); margin: 0; }

.mini-info { display: grid; gap: 2px; min-width: 0; }
.mini .mini-time { font-size: clamp(2rem, min(15vw, 30vh), 6rem); }

/* Courses drawer */

.tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.tile {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 12px;
  border-radius: 12px;
  background: var(--tint);
  font-size: 0.8rem;
  color: var(--muted);
}

.tile-value {
  font-size: 1.3rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  color: var(--text);
}

.bars,
.course-list {
  display: grid;
  margin: 0;
  padding: 0;
  list-style: none;
}

.bars { gap: 14px; }

/* Name and value on one line, the bar below spanning both. */
.bars li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 12px;
}

.bar-name {
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-value { color: var(--muted); font-variant-numeric: tabular-nums; }

.bar { grid-column: 1 / -1; }

.bar span {
  display: block;
  min-width: 4px;
  height: 12px;
  border-radius: 0 4px 4px 0;
  background: var(--accent);
}

.course-list li {
  display: flex;
  align-items: center;
  gap: 4px;
}

.course-name {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 700;
}

.course-name:hover { border-color: var(--line); }
.course-name:focus { border-color: var(--accent); outline: none; }

.course-list .icon-btn { color: var(--muted); }
.course-list .icon-btn:hover:not(:disabled) { color: var(--error); }
.course-list .icon-btn:disabled { opacity: 0.3; cursor: default; }

.add-course { display: flex; gap: 8px; }

.add-course input {
  flex: 1;
  min-width: 0;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.add-course input:focus { border-color: var(--accent); outline: none; }
.add-course .btn-primary { min-width: 0; padding: 10px 20px; }

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