:root {
  --bg: #111111;
  --timer-bg: #1b1b1f;
  --counter-bg: #13261b;
  --counter-bg-active: #1a3a27;
  --text: #f4f4f5;
  --muted: #a1a1aa;
  --accent: #4ade80;
  --warn: #fbbf24;
  --handle: #52525b;
  --handle-active: #a1a1aa;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.app {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.grid-stack { height: 100%; }

/* Panels */
.panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25em;
  overflow: hidden !important;
  container-type: size;
  text-align: center;
}

.panel-timer { background: var(--timer-bg); }

.panel-counter {
  background: var(--counter-bg);
  cursor: pointer;
  transition: background-color 120ms ease;
}
.panel-counter:active,
.panel-counter.pulse { background: var(--counter-bg-active); }
.panel-counter:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }

.label {
  margin: 0;
  font-size: clamp(0.8rem, 6cqmin, 1.25rem);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--muted);
}

.big {
  display: block;
  font-size: min(45cqh, 26cqw);
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.panel-counter .big { color: var(--accent); }
.panel-timer.idle .big { color: var(--muted); }

.hint {
  margin: 0;
  font-size: clamp(0.8rem, 5cqmin, 1.1rem);
  color: var(--muted);
}

.chip {
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--handle);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.chip:active { background: var(--handle); color: var(--text); }
.chip.accent { border-color: var(--accent); color: var(--accent); }

.top-actions, .target-chip { position: absolute; top: 0.75rem; }
.top-actions { right: 0.75rem; display: flex; gap: 0.5rem; }
.target-chip { left: 0.75rem; font-variant-numeric: tabular-nums; }

.chip.icon { display: grid; place-items: center; padding: 0.45rem 0.7rem; }
.chip.icon svg { display: block; }
#sound-toggle[aria-pressed="true"] .sound-off,
#sound-toggle[aria-pressed="false"] .sound-on { display: none; }
.target-chip.on { border-color: var(--accent); color: var(--text); }

/* Target reached */
.panel-timer.reached .big { color: var(--accent); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }
@media (prefers-reduced-motion: reduce) {
  .panel-timer.reached .big { animation: none; }
}

.status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  min-height: 1.5rem;
}
.note { margin: 0; font-size: 0.85rem; color: var(--muted); }
.note.warn { color: var(--warn); }
[hidden] { display: none !important; }

.progress {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 4px;
  background: rgba(255, 255, 255, 0.06);
}
.progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transform-origin: left;
}

/* Target dialog */
.target-dialog {
  width: min(22rem, calc(100vw - 2rem));
  padding: 1.25rem;
  border: 1px solid var(--handle);
  border-radius: 1rem;
  background: var(--timer-bg);
  color: var(--text);
}
.target-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.target-dialog h2 { margin: 0 0 1rem; font-size: 1.1rem; font-weight: 600; }
.target-dialog button {
  flex: 1;
  padding: 0.7rem 0.5rem;
  border: 1px solid var(--handle);
  border-radius: 0.6rem;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.target-dialog button:active { background: var(--handle); }
.target-dialog button.primary { background: var(--accent); border-color: var(--accent); color: #0b1f12; font-weight: 600; }
.presets, .dialog-actions { display: flex; gap: 0.5rem; }
.presets button { font-variant-numeric: tabular-nums; }
.time-inputs {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 0.5rem;
  margin: 1.25rem 0;
  font-size: 1.5rem;
}
.time-inputs label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.75rem; color: var(--muted); }
.time-inputs input {
  width: 4.5rem;
  padding: 0.5rem;
  border: 1px solid var(--handle);
  border-radius: 0.6rem;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 1.5rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
  user-select: text;
  -webkit-user-select: text;
}

/* Resize handle: a full-length divider with a grip, easy to grab by thumb. */
.grid-stack-item > .ui-resizable-handle {
  background: none;
  transform: none;
  opacity: 1;
  z-index: 10;
  touch-action: none;
}
.grid-stack-item > .ui-resizable-handle::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 999px;
  background: var(--handle);
}
.grid-stack-item > .ui-resizable-handle:active::after,
.grid-stack-item.ui-resizable-resizing > .ui-resizable-handle::after { background: var(--handle-active); }

.grid-stack-item > .ui-resizable-s {
  left: 0; right: 0; bottom: 0;
  width: 100%;
  height: 32px;
  cursor: ns-resize;
}
.grid-stack-item > .ui-resizable-s::after { width: 56px; height: 6px; }

.grid-stack-item > .ui-resizable-e {
  top: 0; bottom: 0; right: 0;
  width: 32px;
  height: 100%;
  cursor: ew-resize;
}
.grid-stack-item > .ui-resizable-e::after { width: 6px; height: 56px; }

/* Hide gridstack's resize placeholder so the counter tracks the handle cleanly. */
.grid-stack > .grid-stack-placeholder > .placeholder-content { display: none; }
