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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0a1628;
  color: #d5e4ec;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  overflow: hidden;
}

/* ---------- Pages & Nav ---------- */
.page {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-top: 52px;
  padding-bottom: 70px;
  min-height: 0;
}

.page.active {
  display: flex;
}

#tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: rgba(8, 18, 32, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid rgba(94, 196, 212, 0.08);
  padding: 6px 0 env(safe-area-inset-bottom, 8px);
  z-index: 100;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.35);
  font-size: 0.65rem;
  letter-spacing: 0.04em;
  padding: 8px 0 4px;
  cursor: pointer;
  transition: color 0.2s;
}

.tab.active {
  color: #5ec4d4;
}

/* ---------- Header ---------- */
#app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  background: rgba(8, 18, 32, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(94, 196, 212, 0.08);
  z-index: 100;
}

.header-left {
  width: 80px;
}

.header-title {
  font-size: 1rem;
  font-weight: 400;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  opacity: 0.5;
}

.account-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 5px 12px 5px 14px;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.45);
  font-size: 0.75rem;
  letter-spacing: 0.03em;
  width: auto;
  min-width: 80px;
  justify-content: flex-end;
}

.account-btn.signed-in {
  padding: 4px 4px 4px 10px;
  border-color: rgba(94, 196, 212, 0.3);
}

#account-label {
  white-space: nowrap;
}

#account-icon-wrap {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

/* ---------- Account menu ---------- */
#account-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

#account-overlay.visible {
  display: flex;
}

#account-menu {
  background: #0f1f35;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 1.5rem;
  width: min(300px, 85vw);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.account-menu-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  margin: 0 auto 0.25rem;
}

.account-name {
  font-size: 1rem;
  font-weight: 400;
}

.account-email {
  font-size: 0.8rem;
  opacity: 0.4;
  margin-top: 0.1rem;
}

.account-action {
  width: 100%;
  text-align: center;
}

#signin-btn {
  background: #fff;
  color: #333;
}

#signout-btn {
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.6);
}

/* ---------- Timer screen ---------- */
#timer-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  gap: 2rem;
}

h1 {
  font-size: 1.4rem;
  font-weight: 300;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  opacity: 0.6;
}

/* ---------- Clock ---------- */
#clock-wrap {
  position: relative;
  width: 240px;
  height: 240px;
  cursor: pointer;
}

#clock-face {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.tick {
  stroke: rgba(94, 196, 212, 0.2);
  stroke-width: 1.5;
}

.tick-major {
  stroke: rgba(94, 196, 212, 0.5);
  stroke-width: 2;
}

#second-hand {
  stroke: #5ec4d4;
  stroke-width: 2;
  opacity: 0;
}

#second-hand.active {
  opacity: 1;
}

#clock-inner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

#stopwatch {
  font-size: 2.2rem;
  font-weight: 200;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.05em;
}

#tap-btn {
  background: none;
  border: none;
  color: rgba(94, 196, 212, 0.5);
  font-size: 0.8rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  pointer-events: none;
  padding: 0;
}

#tap-btn.running {
  color: rgba(229, 115, 115, 0.6);
}

/* ---------- Post-stop actions ---------- */
#actions {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  max-width: 280px;
}

#actions.visible {
  display: flex;
}

.session-note {
  width: 100%;
  background: rgba(94, 196, 212, 0.06);
  border: 1px solid rgba(94, 196, 212, 0.15);
  border-radius: 12px;
  padding: 0.65rem 1rem;
  color: #d5e4ec;
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  text-align: center;
  letter-spacing: 0.02em;
}

.session-note::placeholder {
  color: rgba(94, 196, 212, 0.35);
}

.session-note:focus {
  border-color: rgba(94, 196, 212, 0.4);
  background: rgba(94, 196, 212, 0.1);
}

.action-row {
  display: flex;
  gap: 1rem;
}

.action-btn {
  padding: 0.75rem 2rem;
  border-radius: 2rem;
  border: none;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  letter-spacing: 0.03em;
}

#save-btn {
  background: #5ec4d4;
  color: #0a1628;
}

#discard-btn {
  background: transparent;
  color: rgba(255, 255, 255, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

/* ---------- History (timer page) ---------- */
#history {
  padding: 1rem 1.5rem 1.5rem;
  max-height: 30dvh;
  overflow-y: auto;
}

#history:empty { display: none; }

.history-heading {
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.35;
  margin-bottom: 0.5rem;
}

.log-entry {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.55rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.log-entry:last-child { border-bottom: none; }

.log-date {
  font-size: 0.8rem;
  opacity: 0.45;
}

.log-duration {
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

.log-delete {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.2);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 0.3rem;
  line-height: 1;
}

.log-delete:hover { color: #e57373; }

.log-left {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.log-note {
  font-size: 0.75rem;
  opacity: 0.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.log-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-shrink: 0;
}

/* ---------- Stats page ---------- */
.stats-page {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.stats-header {
  font-size: 1.5rem;
  font-weight: 300;
  letter-spacing: 0.08em;
  margin-bottom: 0.25rem;
}

/* Summary cards row */
.card-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

.summary-card {
  background: rgba(94, 196, 212, 0.04);
  border: 1px solid rgba(94, 196, 212, 0.08);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.summary-card .sc-value {
  font-size: 1.6rem;
  font-weight: 300;
}

.summary-card .sc-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.4;
}

/* Stats card */
.stats-card {
  background: rgba(94, 196, 212, 0.04);
  border: 1px solid rgba(94, 196, 212, 0.08);
  border-radius: 12px;
  padding: 1rem;
}

.card-title {
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.4;
  margin-bottom: 0.75rem;
}

.chart-wrap {
  position: relative;
  height: 140px;
}

.chart-wrap-tall {
  height: 180px;
}

/* Streak */
.streak-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.streak-num {
  font-size: 2.4rem;
  font-weight: 200;
  line-height: 1;
}

.streak-unit {
  font-size: 0.85rem;
  opacity: 0.5;
}

.streak-dots {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.streak-dot {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
}

.streak-dot.filled {
  background: rgba(94, 196, 212, 0.45);
}

.streak-dot.today {
  background: #5ec4d4;
}

/* All sessions list */
#all-sessions {
  max-height: 300px;
  overflow-y: auto;
}

.export-btn {
  width: 100%;
  background: rgba(94, 196, 212, 0.08);
  border: 1px solid rgba(94, 196, 212, 0.15);
  color: rgba(94, 196, 212, 0.7);
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  opacity: 0.3;
  font-size: 0.9rem;
}

/* ---------- Confirm dialog ---------- */
#confirm-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

#confirm-overlay.visible {
  display: flex;
}

#confirm-dialog {
  background: #0f1f35;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 1.5rem;
  width: min(300px, 85vw);
  text-align: center;
}

#confirm-dialog p {
  font-size: 1rem;
  margin-bottom: 1.25rem;
  opacity: 0.85;
}

.confirm-actions {
  display: flex;
  gap: 0.75rem;
}

.confirm-cancel {
  flex: 1;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.6);
  border: none;
}

.confirm-delete {
  flex: 1;
  background: #e57373;
  color: #fff;
  border: none;
}
