/* ---- 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;
}

.hidden { display: none !important; }

html.noScroll, html.noScroll body {
  overflow: hidden !important;
}

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

.top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 12px;
  padding: 0.82rem 0.75rem 0.5rem;
  position: sticky;
  top: 0;
  z-index: 50;
  background: linear-gradient(to bottom, rgba(7,8,15,0.92), rgba(7,8,15,0.70));
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

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

.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: 6px;
  padding: 0.35rem 0.85rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(6, 11, 26, 0.9);
  color: var(--fg);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: rgba(148, 163, 184, 0.12); }
.btn:active { transform: scale(0.97); }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #07080f;
  font-weight: 600;
}
.btn.primary:hover { opacity: 0.9; }

.btn.ghost {
  background: transparent;
  border-color: var(--panel-border);
}

.btn.full {
  width: 100%;
  justify-content: center;
}

/* ---- Panel tabs ---- */

.panel-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 999px;
  padding: 3px;
}

.panel-tab {
  flex: 1;
  padding: 8px 0;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.panel-tab:hover { color: var(--fg); }
.panel-tab.active {
  background: var(--accent);
  color: #07080f;
  font-weight: 600;
}

.tab-content {
  display: none;
  flex-direction: column;
  gap: 12px;
}
.tab-content.active {
  display: flex;
}

/* ---- Presets ---- */

.preset-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn.preset {
  flex: 1;
  min-width: 60px;
  justify-content: center;
  padding: 10px 8px;
  font-size: 0.85rem;
}

/* ---- Timer custom row ---- */

.timer-custom-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.timer-custom-row .input.small {
  width: 80px;
  text-align: center;
}

.timer-sep {
  color: var(--muted);
  font-size: 1.2rem;
  font-weight: 700;
}

/* ---- Icon buttons ---- */

.iconBtn {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: var(--fg);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.iconBtn:hover { background: rgba(148, 163, 184, 0.12); }

.iconBtn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  pointer-events: none;
}

.iconBtn.danger {
  color: var(--bad);
  background: rgba(255, 93, 93, 0.10);
  border-color: rgba(255, 93, 93, 0.35);
}

button:focus { outline: none; }
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---- Popup (dropdown, matches Tally) ---- */

.popup-wrap {
  position: relative;
}

.confirm-popup {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  width: 320px;
  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);
  z-index: 100;
  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;
}

.dtRow {
  display: grid;
  grid-template-columns: 1fr 140px;
  gap: 12px;
}

.input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: rgba(0, 0, 0, 0.35);
  color: var(--fg);
  outline: none;
  font-family: inherit;
  font-size: 0.92rem;
}
.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(125, 211, 252, 0.15);
}

/* date/time picker icon visibility */
input[type="date"], input[type="time"] { color-scheme: light; }
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator {
  filter: invert(1) brightness(2) contrast(1.2) !important;
  opacity: 1 !important;
}

/* ---- Grid + Cards ---- */

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  align-items: start;
  padding: 0 0.75rem;
}

.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 14px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.cardTitle {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cardMeta {
  margin: 4px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  min-height: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- Time display (desktop cards) ---- */

.timeRow {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
}

.unit {
  height: 100px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  min-width: 0;
}

.num {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  font-size: 38px;
  font-weight: 900;
  line-height: 1;
  width: 3ch;
  margin: 0 auto;
  text-align: center;
  color: var(--accent);
}

.lbl {
  margin-top: 6px;
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 0.05em;
}

/* ---- Card actions ---- */

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

.leftActions,
.rightActions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.leftActions > *, .rightActions > * { flex-shrink: 0; }

/* ---- Fullscreen overlay ---- */

.fs {
  position: fixed;
  inset: 0;
  background: var(--bg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  z-index: 9999;
}

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

.fsTitle {
  font-size: 1rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.fsTime {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0;
  white-space: nowrap;
}

.fsUnit {
  position: relative;
  padding: 0;
  margin: 0;
  background: none;
  border: none;
  text-align: center;
}

.fsLbl { display: none; }

.fsNum {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  font-size: clamp(80px, 14vw, 200px);
  font-weight: 900;
  line-height: 1;
  width: 3ch;
  margin: 0 auto;
  text-align: center;
  color: var(--accent);
}

/* Colon between segments */
.fsUnit:not(:last-child) {
  margin-right: clamp(14px, 3vw, 36px);
}
.fsUnit:not(:last-child)::after {
  content: ":";
  position: absolute;
  right: calc(clamp(14px, 3vw, 36px) * -0.6);
  top: 0.06em;
  font-size: clamp(60px, 10vw, 150px);
  font-weight: 700;
  opacity: 0.22;
  line-height: 1;
  color: var(--muted);
}

/* ---- Toast ---- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--fg);
}

/* ---- Done badge ---- */

.done-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--good);
  color: #07080f;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  vertical-align: middle;
}

/* ---- Repeat badge ---- */

.repeat-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
  font-size: 0.7rem;
  color: var(--accent);
  vertical-align: middle;
}
.repeat-badge svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.iconBtn.active-toggle {
  background: rgba(125, 211, 252, 0.2);
  border-color: var(--accent);
  color: var(--accent);
}

/* ---- Card running glow ---- */

.card-running {
  box-shadow: 0 0 20px -4px var(--glow-color, var(--accent)),
              0 0 6px -2px var(--glow-color, var(--accent));
  border-color: color-mix(in srgb, var(--glow-color, var(--accent)) 40%, transparent);
}

/* ---- Number tick animation ---- */

@keyframes numTick {
  0%   { transform: translateY(-6px); opacity: 0.4; }
  100% { transform: translateY(0); opacity: 1; }
}

.num-tick {
  animation: numTick 0.2s ease-out;
}

/* ---- Deadline progress bar ---- */

.deadline-progress {
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.deadline-progress-bar {
  height: 100%;
  border-radius: 999px;
  transition: width 1s linear;
}

/* ---- Templates ---- */

.template-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tpl-header {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 4px;
}

.tpl-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.btn.tpl-use {
  flex: 1;
  justify-content: center;
  padding: 8px 12px;
  font-size: 0.82rem;
}

.tpl-del {
  width: 32px !important;
  height: 32px !important;
  flex-shrink: 0;
}
.tpl-del svg {
  width: 14px !important;
  height: 14px !important;
}

/* ---- World clock (in topbar) ---- */

.wc-local {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
}

.wc-local .wc-time {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  font-size: clamp(1.2rem, 3vw, 1.8rem);
  font-weight: 900;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.wc-fs-btn {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.wc-fs-btn:hover { background: rgba(148, 163, 184, 0.12); color: var(--fg); }

.wc-extras {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-top: 2px;
}

.wc-toggle-btn {
  padding: 6px 12px;
  font-size: 0.78rem;
}

.wc-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.wc-item .wc-time {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent);
}

.wc-label {
  font-size: 0.6rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ---- Lap section ---- */

.lap-section {
  max-height: 120px;
  overflow-y: auto;
}

.lap-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.lap-row {
  display: grid;
  grid-template-columns: 40px 1fr 1fr;
  gap: 8px;
  font-size: 0.8rem;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.2);
}

.lap-num {
  color: var(--muted);
  font-weight: 600;
}

.lap-delta {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: var(--accent);
}

.lap-total {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: var(--muted);
  text-align: right;
}

/* ---- History overlay ---- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9000;
}

.overlay-panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 20px;
  width: min(480px, 92vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.overlay-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.overlay-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0;
}

.history-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-empty {
  color: var(--muted);
  text-align: center;
  padding: 20px 0;
  font-size: 0.9rem;
}

.history-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.2);
  font-size: 0.85rem;
}

.history-title {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-dur {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: var(--accent);
  font-size: 0.8rem;
}

.history-when {
  color: var(--muted);
  font-size: 0.75rem;
  white-space: nowrap;
}

/* ---- Mobile ---- */

@media (max-width: 820px) {
  .grid { grid-template-columns: 1fr; }

  .dtRow { grid-template-columns: 1fr 1fr; }

  .wc-extras { gap: 10px; }

  .confirm-popup {
    position: fixed;
    top: 60px;
    right: 50%;
    transform: translateX(50%) translateY(-4px) scale(0.95);
    width: min(320px, 92vw);
  }
  .confirm-popup.show {
    transform: translateX(50%) translateY(0) scale(1);
  }

  .iconBtn { width: 42px; height: 42px; }
  .iconBtn svg { width: 18px; height: 18px; }

  /* Mobile cards: time in one line */
  .timeRow {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0;
    white-space: nowrap;
  }

  .unit {
    height: auto;
    background: none;
    border: none;
    border-radius: 0;
    position: relative;
    padding: 0;
    margin: 0;
  }

  .lbl { display: none; }

  .num {
    font-size: 2.2rem;
    width: 3ch;
  }

  .unit:not(:last-child) {
    margin-right: 14px;
  }
  .unit:not(:last-child)::after {
    content: ":";
    position: absolute;
    right: -10px;
    top: 0.06em;
    font-size: 1.8rem;
    font-weight: 700;
    opacity: 0.25;
    line-height: 1;
    color: var(--muted);
  }

  /* Card compact */
  .card { padding: 12px; gap: 10px; }
  .cardTitle { font-size: 0.95rem; }
  .cardMeta { font-size: 0.75rem; min-height: 14px; }
  .cardActions { gap: 8px; }

  /* Fullscreen mobile — clamp handles scaling, no overrides needed */
}
