/* ===========================================================
   Kala — layout & components.
   Colours come from the theme custom properties in themes.css
   =========================================================== */

*, *::before, *::after { box-sizing: border-box; }

:root {
  /* Fallbacks; every theme overrides these. */
  --ink: #f2f6f4;
  --ink-dim: rgba(242, 246, 244, .68);
  --accent: #7fd1c0;
  --accent-2: #f5d08a;
  --card: rgba(12, 24, 22, .42);
  --card-brd: rgba(255, 255, 255, .16);
  --shadow: 0 18px 50px rgba(0, 0, 0, .35);
  --radius: 20px;
  --font: "Avenir Next", "Segoe UI", system-ui, -apple-system, Helvetica, Arial, sans-serif;
  --display: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  --scrim: rgba(0, 0, 0, .28);
}

html, body { height: 100%; }

/* Everything below is sized in rem, so this one number scales the whole
   interface — buttons, labels, hints and all — without disturbing the timer
   face, which is pinned in px further down.  It is a percentage rather than a
   pixel size so a larger browser default still counts on top of it. */
html { font-size: 112.5%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: #0b1412;
  -webkit-font-smoothing: antialiased;
  min-height: 100%;
  overflow-x: hidden;
}

/* ---------- background stack ---------- */
.bg { position: fixed; inset: 0; z-index: -1; overflow: hidden; }
.bg-layer { position: absolute; inset: -10%; }
.chakra { position: absolute; inset: 0; display: none; pointer-events: none; }
.chakra .c2-washes { position: absolute; inset: 0; }
.chakra .c2-wash { position: absolute; inset: -12%; opacity: 0; }
.chakra svg { position: absolute; overflow: visible; }
.chakra .c2-column {
  left: 50%; top: 50%; transform: translate(-50%, -50%);
  height: 112%; width: min(70vw, 440px);
}
.chakra .c2-cycle {
  left: 50%; top: 46%; transform: translate(-50%, -50%);
  width: min(125vw, 95vh, 920px); height: min(125vw, 95vh, 920px);
}
.incense-smoke {
  position: absolute; inset: 0; display: none;
  width: 100%; height: 100%; pointer-events: none;
}
.bg-scrim { position: absolute; inset: 0; background: var(--scrim); }

/* Brief glow when a timer ends, so the change is visible as well as audible. */
.flash {
  position: fixed; inset: 0; z-index: 40; pointer-events: none; opacity: 0;
  background: radial-gradient(60% 60% at 50% 42%, color-mix(in srgb, var(--accent) 55%, transparent), transparent 72%);
}
.flash.is-on { animation: flashPulse 1.1s ease-out; }
@keyframes flashPulse {
  0% { opacity: 0; }
  18% { opacity: .55; }
  100% { opacity: 0; }
}

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 20px;
  padding-top: max(14px, env(safe-area-inset-top));
}
.brand {
  margin: 0; font-family: var(--display);
  font-size: 1.15rem; font-weight: 600; letter-spacing: .14em; text-transform: uppercase;
  display: flex; align-items: center; gap: .5rem;
}
.brand-mark {
  width: 1.45rem; height: 1.45rem; border-radius: 22%;
  object-fit: cover; display: block; flex-shrink: 0;
}
.brand-link {
  display: flex; align-items: center; gap: .5rem;
  color: inherit; text-decoration: none;
  transition: opacity .2s ease;
}
.brand-link:hover { opacity: .75; text-decoration: underline; text-underline-offset: 4px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.total-pill {
  font-size: .84rem; letter-spacing: .07em; text-transform: uppercase;
  padding: 8px 14px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--card-brd);
  backdrop-filter: blur(8px); white-space: nowrap;
}

.icon-btn {
  font-size: 1.15rem; line-height: 1; color: var(--ink);
  width: 40px; height: 40px; border-radius: 50%; cursor: pointer;
  background: var(--card); border: 1px solid var(--card-brd);
  backdrop-filter: blur(8px);
  transition: transform .2s ease, background .2s ease;
}
.icon-btn:hover { transform: rotate(35deg) scale(1.06); }

/* ---------- shell ---------- */
.wrap {
  max-width: 860px; margin: 0 auto;
  padding: 6px 18px calc(40px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 18px;
}

.card {
  background: var(--card);
  border: 1px solid var(--card-brd);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px) saturate(1.1);
  padding: 20px;
}

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; font-family: var(--display); font-size: 1.05rem; letter-spacing: .1em; text-transform: uppercase; font-weight: 600; }
.card-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.hint { color: var(--ink-dim); font-size: .88rem; margin: 10px 0 0; line-height: 1.55; }
.muted { color: var(--ink-dim); font-weight: 400; }
kbd {
  font: inherit; font-size: .84rem; padding: 1px 6px; border-radius: 6px;
  border: 1px solid var(--card-brd); background: rgba(255, 255, 255, .1);
}

/* ---------- run card ---------- */
.runcard { display: flex; flex-direction: column; align-items: center; gap: 18px; padding-top: 26px; }
body.is-editing-routine #runCard { display: none; }

.ring-wrap { position: relative; width: min(320px, 78vw); aspect-ratio: 1; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); overflow: visible; }
.ring-track, .ring-fill { fill: none; stroke-width: 8; stroke-linecap: round; }
.ring-track { stroke: rgba(255, 255, 255, .14); }
.ring-fill {
  stroke: var(--accent);
  stroke-dasharray: 552.9;
  stroke-dashoffset: 552.9;
  filter: drop-shadow(0 0 10px color-mix(in srgb, var(--accent) 60%, transparent));
  transition: stroke-dashoffset .12s linear, stroke .5s ease;
}
body.is-overtime .ring-fill { stroke: var(--accent-2); }

/* A ring of glyphs turning inside the progress track. Empty and hidden unless
   a theme asks for it, so it costs nothing the rest of the time. */
.rune-ring {
  position: absolute; inset: 0; width: 100%; height: 100%;
  overflow: visible; pointer-events: none; display: none;
}
.rune-ring polyline { fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; }

.ring-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 14% 12%;
}
.phase-name {
  font-size: .86rem; letter-spacing: .15em; text-transform: uppercase;
  color: var(--accent-2); margin-bottom: 4px;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.big-time {
  font-family: var(--display);
  /* In px, not rem, so the root size above leaves the countdown itself alone. */
  font-size: clamp(46px, 13vw, 70px);
  font-weight: 300; line-height: 1;
  font-variant-numeric: tabular-nums; letter-spacing: .01em;
}
.round-info { margin-top: 8px; font-size: .86rem; color: var(--ink-dim); line-height: 1.35; }

.run-meta { display: flex; gap: 10px; width: 100%; justify-content: center; flex-wrap: wrap; }
.meta-item {
  flex: 1 1 120px; max-width: 200px; text-align: center;
  padding: 10px 12px; border-radius: 14px;
  background: rgba(255, 255, 255, .07); border: 1px solid var(--card-brd);
}
.meta-label { display: block; font-size: .74rem; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-dim); }
.meta-value { display: block; margin-top: 3px; font-size: 1.02rem; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.controls { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* ---------- buttons ---------- */
/* On a phone, a tap should act at once and never zoom or select text. */
button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

.btn {
  font: inherit; font-size: .95rem; letter-spacing: .04em;
  color: var(--ink); cursor: pointer; white-space: nowrap;
  padding: 13px 24px; border-radius: 999px;
  background: rgba(255, 255, 255, .1);
  border: 1px solid var(--card-brd);
  transition: transform .15s ease, background .2s ease, opacity .2s ease;
}
.btn:hover:not(:disabled) { background: rgba(255, 255, 255, .18); transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(0) scale(.985); }
.btn:disabled { opacity: .38; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #10201c; font-weight: 600; border-color: transparent;
  box-shadow: 0 10px 26px -10px color-mix(in srgb, var(--accent) 70%, transparent);
}
.btn-primary:hover:not(:disabled) { background: linear-gradient(135deg, var(--accent), var(--accent-2)); filter: brightness(1.07); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 9px 17px; font-size: .88rem; }
.btn-danger { color: #ffb4ad; border-color: rgba(255, 140, 130, .45); }

/* ---------- timeline ---------- */
.timeline { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }

.block {
  border: 1px dashed var(--card-brd); border-radius: 16px;
  padding: 10px 12px 12px; background: rgba(255, 255, 255, .045);
  position: relative;
}
.block-head { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; flex-wrap: wrap; }
.rep-badge {
  font: inherit; font-size: .84rem; font-weight: 600; color: var(--ink); cursor: pointer;
  padding: 6px 14px; border-radius: 999px;
  background: rgba(255, 255, 255, .12); border: 1px solid var(--card-brd);
  transition: background .2s ease, transform .15s ease;
}
.rep-badge:hover { background: rgba(255, 255, 255, .22); transform: translateY(-1px); }
.block-sub { font-size: .8rem; color: var(--ink-dim); }
.block-tools { margin-left: auto; display: flex; gap: 6px; }
.mini-btn {
  font: inherit; font-size: .8rem; color: var(--ink-dim); cursor: pointer;
  padding: 6px 11px; border-radius: 9px;
  background: transparent; border: 1px solid var(--card-brd);
  transition: color .2s ease, background .2s ease;
}
.mini-btn:hover { color: var(--ink); background: rgba(255, 255, 255, .12); }
.mini-btn:disabled { opacity: .3; cursor: not-allowed; }
/* A delete waiting to be confirmed. */
.mini-btn.is-asking {
  color: #ffd9d9; border-color: rgba(255, 120, 120, .6); background: rgba(190, 50, 50, .28);
}

.bars { display: flex; gap: 6px; align-items: stretch; }

.bar {
  --bar: var(--accent);
  position: relative; flex: 1 1 0; min-width: 54px;
  min-height: 62px; padding: 9px 10px; cursor: pointer; overflow: hidden;
  border-radius: 12px; text-align: left; color: var(--ink);
  font: inherit;
  border: 1px solid rgba(255, 255, 255, .22);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--bar) 85%, transparent), color-mix(in srgb, var(--bar) 45%, transparent));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25);
  transition: transform .15s ease, box-shadow .2s ease, filter .2s ease;
  display: flex; flex-direction: column; justify-content: space-between;
}
.bar:hover { transform: translateY(-2px); filter: brightness(1.12); box-shadow: 0 10px 22px -12px rgba(0, 0, 0, .8); }
.bar-time { font-size: 1.02rem; font-weight: 600; font-variant-numeric: tabular-nums; text-shadow: 0 1px 3px rgba(0, 0, 0, .45); }
.bar-name {
  font-size: .78rem; opacity: .9; margin-top: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 1px 3px rgba(0, 0, 0, .45);
}
.bar-edit { position: absolute; top: 7px; right: 8px; font-size: .7rem; opacity: 0; transition: opacity .2s ease; }
.bar:hover .bar-edit { opacity: .85; }

.bar.is-active {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
  animation: barPulse 2.4s ease-in-out infinite;
}
.bar.is-done { filter: grayscale(.55) brightness(.75); }
@keyframes barPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, .0); }
  50% { box-shadow: 0 0 22px 2px rgba(255, 255, 255, .35); }
}
.bar-progress {
  position: absolute; left: 0; bottom: 0; height: 4px; width: 0;
  background: rgba(255, 255, 255, .9);
}

.add-bar {
  flex: 0 0 44px; min-width: 44px; min-height: 62px;
  border-radius: 12px; cursor: pointer; font: inherit; font-size: 1.2rem;
  color: var(--ink-dim); background: transparent;
  border: 1px dashed var(--card-brd);
  transition: color .2s ease, background .2s ease;
}
.add-bar:hover { color: var(--ink); background: rgba(255, 255, 255, .1); }

.empty-state { text-align: center; padding: 26px 10px; color: var(--ink-dim); }
.empty-state p { margin: 0 0 14px; }

.editing-locked {
  margin-top: 14px; padding: 12px 15px; border-radius: 12px; font-size: .88rem;
  background: rgba(255, 200, 120, .14); border: 1px solid rgba(255, 200, 120, .35);
}
body.is-locked .bar, body.is-locked .rep-badge, body.is-locked .add-bar { cursor: default; }

/* ---------- modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 18px;
  background: rgba(4, 8, 8, .55); backdrop-filter: blur(4px);
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal[hidden] { display: none; }

.modal-card {
  width: 100%; max-width: 420px; max-height: 88vh; overflow: auto;
  background: color-mix(in srgb, var(--card) 88%, #0b1210 60%);
  border: 1px solid var(--card-brd); border-radius: var(--radius);
  box-shadow: 0 30px 70px rgba(0, 0, 0, .55);
  backdrop-filter: blur(22px) saturate(1.2);
  animation: pop .2s cubic-bezier(.2, .9, .3, 1.2);
}
.modal-wide { max-width: 540px; }
@keyframes pop { from { transform: translateY(14px) scale(.97); opacity: 0; } }

.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 18px 8px; }
.modal-head h3 { margin: 0; font-family: var(--display); font-size: 1.02rem; letter-spacing: .1em; text-transform: uppercase; flex: 1; }
.modal-body { padding: 8px 18px 4px; display: flex; flex-direction: column; gap: 18px; }
.modal-foot { display: flex; align-items: center; gap: 8px; padding: 14px 18px 18px; flex-wrap: wrap; }
.spacer { flex: 1; }

.field { display: flex; flex-direction: column; gap: 9px; }
.field[hidden] { display: none; }
.field-label { font-size: .78rem; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-dim); }

input[type="text"], input[type="number"] {
  font: inherit; color: var(--ink);
  background: rgba(255, 255, 255, .09);
  border: 1px solid var(--card-brd); border-radius: 11px;
  padding: 10px 12px; width: 100%;
}
input[type="text"]:focus, input[type="number"]:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; text-align: center; padding: 8px 4px; }
input[type="number"]::-webkit-outer-spin-button, input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.dur-row { display: flex; flex-direction: column; gap: 12px; }
.stepper { display: flex; align-items: stretch; gap: 8px; flex: 1; }
.step-btn {
  font: inherit; font-size: 2.05rem; color: var(--ink); cursor: pointer;
  width: 68px; min-height: 68px; border-radius: 16px;
  background: rgba(255, 255, 255, .1); border: 1px solid var(--card-brd);
}
.step-btn:hover { background: rgba(255, 255, 255, .2); }
.num-box { flex: 1; display: flex; align-items: center; gap: 4px; }
.num-box span { font-size: .9rem; color: var(--ink-dim); }
.num-box input {
  font-size: 1.55rem; min-height: 68px; padding: 10px 6px; border-radius: 16px;
}

.quick-row { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
  font: inherit; font-size: .84rem; color: var(--ink); cursor: pointer;
  padding: 7px 14px; border-radius: 999px;
  background: rgba(255, 255, 255, .09); border: 1px solid var(--card-brd);
}
.quick-row .chip {
  font-size: 1rem; padding: 12px 18px;
}
.chip:hover { background: rgba(255, 255, 255, .2); }
.chip.is-on { background: var(--accent); color: #10201c; font-weight: 600; border-color: transparent; }

.tone-grid, .theme-grid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(138px, 1fr)); }
.opt {
  position: relative; font: inherit; font-size: .88rem; text-align: left; color: var(--ink); cursor: pointer;
  padding: 12px 13px; border-radius: 13px;
  background: rgba(255, 255, 255, .08); border: 1px solid var(--card-brd);
  transition: background .2s ease, transform .15s ease;
}
.opt:hover { background: rgba(255, 255, 255, .17); transform: translateY(-1px); }
.opt.is-on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.opt .opt-name { display: block; font-weight: 600; }
.opt .opt-desc { display: block; font-size: .78rem; color: var(--ink-dim); margin-top: 3px; }
.opt .swatch-strip { display: block; height: 6px; border-radius: 999px; margin-top: 8px; }
.opt-play {
  position: absolute; top: 8px; right: 8px; font-size: .76rem; padding: 4px 9px;
  border-radius: 8px; background: rgba(255, 255, 255, .16); border: 1px solid var(--card-brd);
  color: var(--ink); cursor: pointer;
}
.opt-play:hover { background: rgba(255, 255, 255, .3); }

input[type="range"] { width: 100%; accent-color: var(--accent); }

.field .hint { margin: 0; }
.toggle { display: flex; align-items: center; gap: 11px; font-size: .92rem; cursor: pointer; line-height: 1.4; }
.toggle input { flex: none; width: 21px; height: 21px; accent-color: var(--accent); }

.save-row { display: flex; gap: 8px; }
.routine-list { display: flex; flex-direction: column; gap: 7px; }
.routine-row {
  display: flex; align-items: stretch; gap: 6px; flex-wrap: nowrap;
}
.pr-select {
  flex: 1 1 auto; min-width: 0;
  display: flex; align-items: center; gap: 8px;
  font: inherit; font-size: .92rem; color: var(--ink); cursor: pointer;
  text-align: left; padding: 10px 12px; border-radius: 12px;
  background: rgba(255, 255, 255, .07); border: 1px solid var(--card-brd);
  transition: background .2s ease;
}
.pr-select:hover { background: rgba(255, 255, 255, .16); }
/* The name is the only part that may shrink; min-width lets it actually do so,
   since a flex item will not go below its content width without it. */
.pr-select .pr-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pr-select .pr-meta { flex: none; font-size: .78rem; color: var(--ink-dim); white-space: nowrap; }
.pr-actions { display: flex; gap: 6px; flex: none; }
.pr-icon {
  font: inherit; color: var(--ink); cursor: pointer;
  width: 44px; min-height: 44px; padding: 0; border-radius: 12px;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, .07); border: 1px solid var(--card-brd);
  transition: background .2s ease, color .2s ease, border-color .2s ease;
}
.pr-icon:hover { background: rgba(255, 255, 255, .16); }
.pr-icon svg { display: block; }
.pr-delete { color: #ff8b84; border-color: rgba(255, 120, 110, .5); }
.pr-delete:hover { background: rgba(190, 50, 50, .22); }
.pr-delete.is-asking {
  width: auto; padding: 0 10px; font-size: .8rem;
  color: #ffd9d9; border-color: rgba(255, 120, 120, .6);
  background: rgba(190, 50, 50, .28);
}

/* Sits under the starter routines, and only when some are hidden. */
.restore-btn { align-self: flex-start; margin-top: 2px; }

/* Below this the running time is the first thing worth losing. */
@media (max-width: 400px) {
  .pr-select .pr-meta { display: none; }
}

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  z-index: 90; padding: 12px 20px; border-radius: 999px; font-size: .92rem;
  background: rgba(10, 18, 16, .9); border: 1px solid var(--card-brd); color: #fff;
  box-shadow: 0 14px 34px rgba(0, 0, 0, .5);
  animation: toastIn .25s ease;
}
.toast[hidden] { display: none; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } }

@media (max-width: 560px) {
  .wrap { padding-inline: 12px; }
  .card { padding: 16px 14px; }
  /* The four controls and the three readouts each want to stay on one line at
     the larger text size, so on a phone they trade padding for room. */
  .controls { gap: 8px; }
  .btn { padding: 12px 13px; }
  .run-meta { gap: 8px; }
  .meta-item { flex-basis: 96px; min-width: 0; padding: 10px 8px; }
  .meta-label { letter-spacing: .08em; }
  .meta-value { font-size: .94rem; }
  .bar { min-width: 54px; padding: 8px; }
  .bar-time { font-size: .95rem; }
  .mini-btn { padding: 8px 12px; }   /* easier to hit with a thumb */

  /* At this text size a dialog's buttons no longer share one line, so the
     confirm button takes a row of its own — easier to hit with a thumb than
     the squeezed row it would otherwise sit in. */
  .modal-foot .spacer { display: none; }
  .modal-foot .btn-primary { flex: 1 1 100%; }

  /* The title, the total and the settings button have to share one narrow
     line, and at the larger body size the full-width lettering no longer
     fits, so the heading gives up the room rather than the total. */
  .topbar { padding-inline: 14px; gap: 8px; }
  .brand { font-size: .98rem; letter-spacing: .08em; }
  .brand-mark { width: 1.2rem; height: 1.2rem; }
  .total-pill { font-size: .8rem; letter-spacing: .05em; padding: 7px 11px; }
}

/* The keyboard shortcuts only exist for people who have a keyboard. */
@media (hover: none), (pointer: coarse) {
  #runHint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; animation-iteration-count: 1 !important; }
}
/* The pseudo-elements have to be named separately.  A good deal of the
   background lives in them — the star fields, the
   ridge — and none of it is reachable through .bg-layer alone, so leaving
   them out meant the switch quietly did nothing for those themes. */
body.no-motion .bg-layer,
body.no-motion .bg-layer::before,
body.no-motion .bg-layer::after,
body.no-motion .bg-scrim,
body.no-motion .bg-scrim::before,
body.no-motion .bg-scrim::after,
body.no-motion .rune-ring,
body.no-motion .chakra * { animation: none !important; }
body.no-motion .bar.is-active { animation: none; }
