/* ---- Reset & root ---- */

:root {
  --bg: #07080f;
  --panel: rgba(12, 16, 28, 0.75);
  --panel-border: rgba(148, 163, 184, 0.18);
  --fg: #f5f5ff;
  --muted: #9fa3c5;
  --accent: #7dd3fc;
  --good: #44d17a;
  --bad: #ff5d5d;
  --radius: 16px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  height: 100%;
  color: var(--fg);
  font-family: "Inter", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  background: var(--bg);
  overflow-x: hidden;
}

/* ---- Top bar (grid, matches Pong/Sudoku) ---- */

.top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 0.4rem 0.75rem 0.5rem;
  position: sticky;
  top: 0;
  z-index: 10;
}

.top-side {
  display: flex;
  align-items: center;
  gap: 8px;
}
.top-side-left  { justify-content: flex-start; flex-wrap: wrap; }
.top-side-right { justify-content: flex-end; flex-wrap: wrap; }

.top-center { text-align: center; }
.top-center h1 {
  margin: 0;
  font-size: clamp(1.4rem, 3vw, 2.1rem);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

/* ---- Ghost buttons (pill style, matches site) ---- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 0.35rem 0.85rem;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  background: transparent;
  color: var(--fg);
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
}
.btn.ghost {
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(6, 11, 26, 0.9);
}
.btn.ghost:hover {
  background: rgba(40, 50, 70, 0.8);
  transform: translateY(-1px);
}
.btn.primary {
  background: var(--accent);
  color: #0b0b18;
  border-color: rgba(125, 211, 252, 0.35);
  font-weight: 600;
}
.btn.primary:hover {
  background: #9be0fd;
  transform: translateY(-1px);
}
.btn.danger {
  border-color: rgba(255, 93, 93, 0.3);
  background: rgba(255, 93, 93, 0.12);
}
.btn.danger:hover {
  background: rgba(255, 93, 93, 0.2);
}
.btn:disabled { opacity: 0.35; pointer-events: none; }

/* ---- Main content ---- */

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 18px 44px;
}

.hero {
  padding: 10px 0 6px;
}

.addRow {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.input {
  flex: 1 1 260px;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(6, 11, 26, 0.9);
  color: var(--fg);
  font-family: inherit;
  font-size: 0.78rem;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input:focus {
  border-color: rgba(125, 211, 252, 0.5);
  box-shadow: 0 0 0 3px rgba(125, 211, 252, 0.1);
}

/* ---- Counter grid ---- */

.grid {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}

.card {
  border: 1px solid var(--panel-border);
  border-top: 3px solid var(--accent);
  background: var(--panel);
  border-radius: var(--radius);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
  padding: 14px;
  touch-action: pan-y;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.card:hover {
  border-color: rgba(148, 163, 184, 0.28);
}

.cardTop {
  display: flex;
  align-items: center;
  gap: 10px;
}

.titleInput {
  flex: 1;
  font-size: 0.82rem;
  font-family: inherit;
  font-weight: 500;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.04);
  color: var(--fg);
  outline: none;
  transition: border-color 0.15s ease;
}
.titleInput:focus {
  border-color: rgba(148, 163, 184, 0.25);
}

.iconBtn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.75rem;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.iconBtn.dragHandle {
  cursor: grab;
  font-size: 0.9rem;
  letter-spacing: -1px;
}
.iconBtn.dragHandle:hover {
  border-color: rgba(125, 211, 252, 0.4);
  color: var(--accent);
}
.iconBtn.dragHandle:active {
  cursor: grabbing;
}
.iconBtn.trash:hover {
  border-color: rgba(255, 93, 93, 0.45);
  color: var(--bad);
}

.countRow {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 0;
}
.count {
  font-size: 3.2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
}

.controls {
  display: flex;
  gap: 8px;
}
.controls .btn {
  flex: 1;
  justify-content: center;
  padding: 0.45rem 0.6rem;
  font-size: 0.8rem;
  font-weight: 600;
}

.btn.small {
  padding: 0.4rem 0.7rem;
  font-size: 0.76rem;
}
.btn.tiny {
  padding: 0.3rem 0.6rem;
  font-size: 0.68rem;
  color: var(--muted);
}

/* File import button */
.fileBtn {
  position: relative;
  overflow: hidden;
}
.fileBtn input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* ---- Progress bar (goal) ---- */

.progress-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}
.progress-track {
  flex: 1;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  border-radius: 999px;
  transition: width 0.3s ease;
  min-width: 0;
}
.progress-label {
  font-size: 0.65rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 32px;
  text-align: right;
}

/* ---- Sparkline ---- */

.spark-wrap {
  height: 24px;
  min-height: 24px;
}
.sparkline {
  width: 100%;
  height: 24px;
  display: block;
}

/* ---- Card settings row ---- */

.cardSettings {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.setting-row {
  display: flex;
  align-items: center;
  gap: 4px;
}
.setting-label {
  font-size: 0.65rem;
  color: var(--muted);
  font-weight: 500;
}
.setting-input {
  width: 52px;
  padding: 4px 6px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  color: var(--fg);
  font-family: inherit;
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  outline: none;
  text-align: center;
  transition: border-color 0.15s ease;
}
.setting-input:focus {
  border-color: rgba(125, 211, 252, 0.4);
}
/* Hide number input spinners */
.setting-input::-webkit-inner-spin-button,
.setting-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.setting-input { -moz-appearance: textfield; }

/* ---- Global round timer ---- */

.round-timer-group {
  position: relative;
}

.round-input {
  width: 40px;
  padding: 4px 2px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(6, 11, 26, 0.9);
  color: var(--fg);
  font-family: inherit;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
  outline: none;
}
.round-input:focus {
  border-color: rgba(125, 211, 252, 0.5);
}
.round-input::-webkit-inner-spin-button,
.round-input::-webkit-outer-spin-button {
  -webkit-appearance: none; margin: 0;
}
.round-input { -moz-appearance: textfield; }

.round-display {
  display: flex;
  align-items: center;
  gap: 8px;
}
.round-time {
  font-size: 1.1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  letter-spacing: 0.04em;
  transition: color 0.2s ease;
}
.round-time.round-urgent {
  color: var(--bad);
  animation: urgentPulse 0.5s ease infinite alternate;
}
.round-time.round-done {
  color: var(--bad);
  opacity: 0.6;
}
@keyframes urgentPulse {
  0% { opacity: 1; }
  100% { opacity: 0.5; }
}
.round-ctrl {
  padding: 0.25rem 0.6rem;
  font-size: 0.7rem;
}

/* ---- Race mode ---- */

.race-group {
  position: relative;
}
.race-time {
  font-size: 1.1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--good);
  letter-spacing: 0.04em;
}

.race-finish {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 4px 0;
  animation: raceStamp 0.3s ease-out;
}
.race-finish-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--good);
}
.race-finish-time {
  font-size: 0.8rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
@keyframes raceStamp {
  0% { transform: scale(1.3); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* ---- Per-counter timer bar ---- */

.card-timer-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 4px;
  border-top: 1px solid rgba(148, 163, 184, 0.1);
}
.card-timer-display {
  font-size: 0.9rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  min-width: 42px;
  transition: color 0.2s ease;
}
.card-timer-display.card-timer-done {
  color: var(--bad);
  opacity: 0.6;
}

/* ---- Count animation ---- */

.count-up {
  animation: slideUp 0.25s ease-out;
}
.count-down {
  animation: slideDown 0.25s ease-out;
}

@keyframes slideUp {
  0%   { transform: translateY(12px); opacity: 0.3; }
  100% { transform: translateY(0); opacity: 1; }
}
@keyframes slideDown {
  0%   { transform: translateY(-12px); opacity: 0.3; }
  100% { transform: translateY(0); opacity: 1; }
}

/* ---- Color toggle & dropdown ---- */

.color-toggle-wrap {
  position: relative;
}
.colorToggle {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
  padding: 0;
  transition: border-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}
.colorToggle:hover {
  transform: scale(1.15);
  border-color: rgba(255, 255, 255, 0.5);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.15);
}

.color-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%) translateY(-4px) scale(0.95);
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  background: radial-gradient(circle at 30% 0%, rgba(30, 40, 70, 0.95), rgba(12, 16, 28, 0.98));
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 12px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6);
  z-index: 60;
  opacity: 0;
  transition: opacity 0.15s ease, transform 0.15s ease;
  pointer-events: none;
}
.color-dropdown.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1);
  pointer-events: auto;
}

/* Lift card above siblings when dropdown is open */
.card:has(.color-dropdown.show) {
  z-index: 20;
}

.color-option {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: transform 0.1s ease, border-color 0.15s ease;
}
.color-option:hover {
  transform: scale(1.25);
}
.color-option.active {
  border-color: var(--fg);
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.3);
}

/* ---- Confirm popup ---- */

.popup-group,
.round-timer-group,
.race-group {
  position: relative;
}
.confirm-popup {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0.45rem 0.75rem;
  background: radial-gradient(circle at 30% 0%, rgba(30, 40, 70, 0.95), rgba(12, 16, 28, 0.98));
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 14px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6);
  white-space: nowrap;
  z-index: 50;
  opacity: 0;
  transform: translateY(-4px) scale(0.95);
  transition: opacity 0.15s ease, transform 0.15s ease;
  pointer-events: none;
}
.confirm-popup.show {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.top-side-right .confirm-popup {
  left: auto;
  right: 0;
}
.hidden { display: none !important; }

/* ---- Drag & drop ---- */

.card.dragging {
  opacity: 0.4;
  cursor: grabbing;
}
.card.drag-over {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(125, 211, 252, 0.2), 0 12px 32px rgba(0, 0, 0, 0.4);
}

/* ---- Keyboard focus ---- */

.card.kb-focused {
  box-shadow: 0 0 0 2px var(--accent), 0 12px 32px rgba(0, 0, 0, 0.4);
}

/* ---- Goal celebration ---- */

.card.goal-hit {
  animation: goalPulse 0.6s ease-out;
}
@keyframes goalPulse {
  0%   { box-shadow: 0 0 0 0 rgba(68, 209, 122, 0.5); }
  40%  { box-shadow: 0 0 0 12px rgba(68, 209, 122, 0.2); transform: scale(1.02); }
  100% { box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4); transform: scale(1); }
}

/* ---- Responsive ---- */

@media (max-width: 600px) {
  .top {
    grid-template-columns: 1fr;
    text-align: center;
    gap: 6px;
    padding: 0.3rem 0.5rem;
  }
  .top-side { justify-content: center; flex-wrap: wrap; }
  .top-center h1 { font-size: 1.3rem; }
  .wrap { padding: 16px 10px 32px; }
  .confirm-popup {
    left: 50%;
    right: auto;
    transform: translateX(-50%) translateY(-4px) scale(0.95);
  }
  .confirm-popup.show {
    transform: translateX(-50%) translateY(0) scale(1);
  }
}
