/* Toolbar buttons, dialogs, form controls, toast, confetti. */

/* Auto-complete pill: the shared svg rules for small icons. */
.icon-btn svg,
.auto-pill svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Auto-complete: floats above the toolbar, enters from slightly below. */
.auto-pill {
  position: absolute;
  bottom: 16px;
  left: 50%;
  z-index: 3500;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px 10px 14px;
  border: 0;
  border-radius: 999px;
  background: var(--mustard);
  color: var(--espresso);
  font: 700 15px/1 var(--font-sans);
  box-shadow: 0 8px 22px rgba(42, 30, 26, 0.22), inset 0 -2px 0 rgba(42, 30, 26, 0.12);
  cursor: pointer;
  opacity: 0;
  transform: translate(-50%, 10px) scale(0.96);
  pointer-events: none;
  transition: opacity 200ms var(--ease-out), transform 220ms var(--ease-out);
}
.auto-pill svg { stroke-width: 2.4; width: 18px; height: 18px; }
.auto-pill.on { opacity: 1; transform: translate(-50%, 0) scale(1); pointer-events: auto; }
.auto-pill.on:active { transform: translate(-50%, 0) scale(0.97); transition-duration: 120ms; }
.auto-pill:focus-visible { outline: 3px solid var(--espresso); outline-offset: 2px; }

/* ---- buttons ---- */
.btn {
  appearance: none;
  border: 0;
  border-radius: 12px;
  padding: 12px 18px;
  min-height: 44px;
  font: 700 15px/1.1 var(--font-sans);
  letter-spacing: 0.005em;
  cursor: pointer;
  transition: transform var(--t-press) var(--ease-out), background-color 150ms ease, color 150ms ease, box-shadow 150ms ease;
}
.btn:active { transform: scale(0.97); }
/* Buttons step up a pixel on hover, press down on click. */
@media (hover: hover) and (pointer: fine) {
  .btn:hover { transform: translateY(-1px); }
  .btn:hover:active { transform: translateY(0) scale(0.97); }
}
.btn:focus-visible, .icon-btn:focus-visible { outline: 3px solid var(--terracotta); outline-offset: 2px; }
.btn-primary { background: var(--terracotta); color: #fff; }
.btn-secondary { background: rgba(91, 107, 47, 0.12); color: var(--olive-deep); }
.btn-ghost { background: transparent; color: var(--espresso-soft); box-shadow: inset 0 0 0 1.5px var(--line); }
.btn-ghost.armed { color: var(--terracotta-deep); box-shadow: inset 0 0 0 1.5px var(--terracotta); }
@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover { background: var(--terracotta-deep); }
  .btn-secondary:hover { background: rgba(91, 107, 47, 0.2); }
  .btn-ghost:hover { background: rgba(42, 30, 26, 0.05); }
}

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--espresso-soft);
  width: 40px;
  height: 40px;
  margin: -8px -8px 0 0;
  display: grid;
  place-items: center;
  border-radius: 10px;
  cursor: pointer;
  transition: transform var(--t-press) var(--ease-out), background-color 150ms ease;
}
.icon-btn:active { transform: scale(0.94); }
@media (hover: hover) and (pointer: fine) {
  .icon-btn:hover { background: rgba(42, 30, 26, 0.06); }
}

/* ---- dialogs (modals stay centred; scale from the middle) ---- */
.dialog {
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: 22px 22px 20px;
  border: 0;
  border-radius: 20px;
  background: var(--paper);
  color: var(--espresso);
  box-shadow: 0 24px 60px rgba(42, 30, 26, 0.3), 0 0 0 1px var(--line);
}
.dialog::backdrop { background: rgba(42, 30, 26, 0.42); }

.dialog[open] { animation: dlg-in var(--t-modal-in) var(--ease-out); }
.dialog[open]::backdrop { animation: fade-in var(--t-modal-in) var(--ease-out); }
.dialog.closing { animation: dlg-out var(--t-modal-out) var(--ease-out) forwards; }
.dialog.closing::backdrop { animation: fade-out var(--t-modal-out) var(--ease-out) forwards; }

@keyframes dlg-in { from { opacity: 0; transform: translateY(6px) scale(0.96); } }
@keyframes dlg-out { to { opacity: 0; transform: scale(0.97); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .dialog[open], .dialog.closing { animation: fade-in 150ms ease; }
  .dialog.closing { animation-name: fade-out; }
}

.dialog h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 24px;
  font-weight: 600;
  color: var(--espresso);
}
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 14px; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }
.dialog-confirm p { margin: 10px 0 0; color: var(--espresso-soft); line-height: 1.45; }

/* ---- form controls ---- */
.field { border: 0; margin: 0 0 16px; padding: 0; }
.field legend {
  padding: 0;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--espresso-soft);
}
.field-note { margin: 8px 0 0; font-size: 13px; color: var(--olive-deep); }

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 4px;
  gap: 4px;
  border-radius: 12px;
  background: rgba(42, 30, 26, 0.07);
}
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span {
  display: block;
  padding: 10px 8px;
  border-radius: 9px;
  text-align: center;
  font-weight: 650;
  font-size: 15px;
  color: var(--espresso-soft);
  transition: background-color 160ms ease, color 160ms ease, box-shadow 160ms ease;
  pointer-events: none;
}
.segmented input:checked + span { background: var(--paper); color: var(--terracotta-deep); box-shadow: 0 1px 3px rgba(42, 30, 26, 0.15); }
.segmented input:focus-visible + span { outline: 3px solid var(--terracotta); outline-offset: 1px; }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  margin-bottom: 8px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-weight: 650;
  cursor: pointer;
}
.switch {
  appearance: none;
  position: relative;
  flex: none;
  width: 48px;
  height: 28px;
  margin: 0;
  border-radius: 999px;
  background: rgba(42, 30, 26, 0.22);
  cursor: pointer;
  transition: background-color 180ms ease;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(42, 30, 26, 0.3);
  transition: transform 200ms var(--ease-out);
}
.switch:checked { background: var(--olive); }
.switch:checked::after { transform: translateX(20px); }
.switch:focus-visible { outline: 3px solid var(--terracotta); outline-offset: 2px; }

.menu-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }

/* ---- stats ---- */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0 0 16px; }
.stats-grid > div { padding: 12px; border-radius: 12px; background: rgba(42, 30, 26, 0.05); }
.stats-grid dt { font-size: 12.5px; color: var(--espresso-soft); }
.stats-grid dd { margin: 4px 0 0; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
#btn-reset-stats { width: 100%; }

/* ---- help ---- */
.help-body { line-height: 1.5; font-size: 15px; }
.help-body p { margin: 0 0 10px; }
.help-body ul { margin: 0 0 12px; padding-left: 20px; }
.help-body li { margin-bottom: 6px; }
.help-body h3 { margin: 16px 0 6px; font-family: var(--font-serif); font-size: 17px; color: var(--terracotta-deep); }
.help-body kbd {
  display: inline-block;
  min-width: 22px;
  padding: 1px 6px;
  margin: 0 1px;
  border-radius: 6px;
  background: #fff;
  box-shadow: inset 0 -1px 0 rgba(42, 30, 26, 0.2), 0 0 0 1px var(--line);
  font: 600 12px/1.6 var(--font-sans);
  text-align: center;
}

/* ---- win ---- */
.dialog-win { text-align: center; }
.win-mark { width: 64px; height: 64px; margin: 2px auto 8px; color: var(--terracotta); }
.win-mark svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; }
.win-text { margin: 6px 0 16px; color: var(--espresso-soft); }
.win-stats { margin: 0; text-align: left; }
.win-stats > div { display: flex; justify-content: space-between; align-items: baseline; padding: 9px 2px; border-bottom: 1px solid var(--line); }
.win-stats dt { color: var(--espresso-soft); }
.win-stats dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.win-total dd { font-size: 22px; color: var(--terracotta-deep); }
.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--mustard);
  color: var(--espresso);
  font-size: 11px;
  font-weight: 700;
  vertical-align: middle;
}
.dialog-win .dialog-actions { justify-content: center; }

/* ---- pause ---- */
.dialog-pause { text-align: center; width: min(340px, calc(100vw - 32px)); }
.pause-mark {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin: 2px auto 10px;
  border-radius: 50%;
  background: var(--olive);
  color: #fff;
}
.pause-mark svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; }
.pause-time { margin: 6px 0 18px; color: var(--espresso-soft); }
.pause-time strong { color: var(--espresso); font-variant-numeric: tabular-nums; font-size: 18px; margin-left: 4px; }
.pause-actions { display: grid; gap: 8px; }
.pause-actions .btn-lg { min-width: 0; width: 100%; }
.timeup-mark { color: var(--olive); }

/* Short screens (landscape phones): keep dialogs within the viewport. */
@media (max-height: 520px) {
  .dialog { padding: 16px 18px; }
  .dialog-pause { width: min(460px, calc(100vw - 32px)); }
  .pause-mark, .win-mark { display: none; }
  .pause-time { margin: 4px 0 12px; }
  .pause-actions { grid-template-columns: repeat(3, 1fr); }
  .pause-actions .btn-lg { grid-column: 1 / -1; padding-block: 12px; }
  .pause-actions .btn { padding-inline: 8px; font-size: 14px; }
  .win-text { margin-bottom: 8px; }
  .win-stats > div { padding: 6px 2px; }
  .dialog-actions { margin-top: 12px; }
}

/* ---- toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  z-index: 50;
  max-width: min(440px, calc(100vw - 32px));
  padding: 11px 16px;
  border-radius: 12px;
  background: var(--espresso);
  color: var(--cream);
  font-size: 14px;
  line-height: 1.35;
  text-align: center;
  box-shadow: 0 10px 26px rgba(42, 30, 26, 0.3);
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
  transition: opacity 150ms ease, transform 150ms var(--ease-out);
}
.toast.on { opacity: 1; transform: translate(-50%, 0); transition-duration: 220ms; }

/* ---- confetti ---- */
/* A manual popover so it can sit in the top layer, above the win dialog. */
.confetti {
  position: fixed;
  inset: 0;
  z-index: 40;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: hidden;
  pointer-events: none;
  display: none;
}
.confetti.on { display: block; }
