/* ================================================================
   POMO — Terminal Frequency
   Dark precision instrument aesthetic
   ================================================================ */

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

button, input, code {
  font: inherit;
}

/* Ensure the HTML `hidden` attribute always wins over display overrides */
[hidden] {
  display: none !important;
}

a {
  color: inherit;
}

/* Focus ring — keyboard only */
:focus-visible {
  outline: 2px solid var(--work);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* === Design Tokens === */
:root {
  --bg:        #090B0A;
  --surface:   #131716;  /* card — clearly lifted off bg */
  --surface-2: #1C211F;  /* inputs, secondary buttons */
  --surface-3: #242A27;  /* active/hover states */

  --text:     #D0D5CC;
  --text-mid: #8A9490;   /* ≥4.5:1 on --surface */
  --text-lo:  #838B89;   /* ≥4.5:1 on --surface */

  --work:    #C8FF3C;
  --break:   #3CCAFF;
  --neutral: #7A8480;    /* ≥4.5:1 on --surface (idle phase label) */

  --r-card: 18px;
  --r-btn:  10px;
  --r-sm:   8px;
  --r-xs:   6px;
  --r-pill: 100px;
}

/* Phase tokens — scoped to timer card */
#timer-card {
  --ph:    var(--neutral);
  --ph-r:  122, 132, 128;
  --ph-glow: rgba(122, 132, 128, 0.06);
}

#timer-card[data-phase="work"] {
  --ph:    var(--work);
  --ph-r:  200, 255, 60;
  --ph-glow: rgba(200, 255, 60, 0.07);
}

#timer-card[data-phase="break"] {
  --ph:    var(--break);
  --ph-r:  60, 202, 255;
  --ph-glow: rgba(60, 202, 255, 0.07);
}

/* Body-level ambient glow — propagated by app.js */
body {
  --body-glow: rgba(122, 132, 128, 0.025);
}
body[data-phase="work"] {
  --body-glow: rgba(200, 255, 60, 0.05);
}
body[data-phase="break"] {
  --body-glow: rgba(60, 202, 255, 0.05);
}

/* === Base === */
html, body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  position: relative;
}

/* Ambient background radial glow, phase-reactive */
body::before {
  content: '';
  position: fixed;
  top: -38vh;
  left: 50%;
  transform: translateX(-50%);
  width: 110vw;
  max-width: 720px;
  height: 110vw;
  max-height: 720px;
  border-radius: 50%;
  background: radial-gradient(
    circle at center,
    var(--body-glow) 0%,
    transparent 62%
  );
  pointer-events: none;
  z-index: 0;
  transition: background 1.6s ease;
}

/* === Layout === */
.app-shell {
  position: relative;
  z-index: 1;
  width: min(100% - 28px, 500px);
  margin: 0 auto;
  padding-top: 26px;
  padding-bottom: 80px;
  display: grid;
  gap: 10px;
}

/* === Topbar === */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 8px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-shrink: 0;
}

.brand-mark {
  width: 32px;
  height: 32px;
  background: var(--surface-2);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-mid);
  flex-shrink: 0;
}

.brand-name {
  font-family: 'Playfair Display', 'Georgia', serif;
  font-weight: 700;
  font-size: 20px;
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1;
}

/* === Connection badge === */
.connection-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  padding: 3px 8px;
  border-radius: 99px;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
  margin-right: 10px;
}

.connection-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.connection-badge[data-state="live"] {
  color: var(--work);
  background: color-mix(in srgb, var(--work) 12%, transparent);
}

.connection-badge[data-state="connecting"] {
  color: var(--text-mid);
  background: color-mix(in srgb, var(--text-mid) 12%, transparent);
}

.connection-badge[data-state="offline"] {
  color: #C8827A;
  background: color-mix(in srgb, #C8827A 12%, transparent);
}

/* Session row lives in settings panel */
.sp-session-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.sp-join-btn {
  padding: 9px 14px;
  font-size: 11px;
  flex-shrink: 0;
  white-space: nowrap;
}

/* === Card base === */
.card {
  background: var(--surface);
  border-radius: var(--r-card);
  overflow: hidden;
}

/* === Timer Card === */
.timer-card {
  box-shadow: inset 0 0 80px var(--ph-glow);
  transition: box-shadow 1.3s ease;
}

/* === Progress Bar (top strip) === */
.timer-progress {
  height: 3px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 0;
}

.timer-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--ph);
  box-shadow:
    0 0 12px rgba(var(--ph-r), 0.7),
    0 0 4px  rgba(var(--ph-r), 0.9);
  transition:
    width 0.25s linear,
    background 1.3s ease,
    box-shadow 1.3s ease;
}

/* === Card Top Row === */
.card-top {
  padding: 16px 20px 0;
}

/* === Phase Badge === */
.phase-badge {
  display: inline-flex;
  align-items: center;
  color: var(--ph);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  transition: color 1.3s ease;
}

/* Dot via pseudo-element (keeps textContent assignment safe) */
.phase-badge::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
  margin-right: 8px;
}

#timer-card[data-phase="work"] .phase-badge::before {
  animation: pulsedot 2.2s ease-in-out infinite;
}

@keyframes pulsedot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.35; transform: scale(0.75); }
}

/* === Timer Face === */
.timer-face {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 40px 24px 20px;
  gap: 10px;
}

.countdown {
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  font-weight: 700;
  font-size: clamp(72px, 21vw, 112px);
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--text);
  text-shadow: 0 0 100px rgba(var(--ph-r), 0.28);
  transition: text-shadow 1.3s ease;
}

.phase-message {
  font-size: 13.5px;
  color: var(--text-mid);
  font-style: italic;
  letter-spacing: 0.005em;
}

/* === Primary Action Row === */
.primary-action-row {
  padding: 0 20px 16px;
}

/* === Buttons === */
.button {
  border: none;
  border-radius: var(--r-btn);
  padding: 11px 18px;
  min-height: 44px;
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.12s, transform 0.1s;
}

.button:active {
  transform: scale(0.97);
  opacity: 0.82;
}

.button-primary {
  width: 100%;
  padding: 14px 24px;
  font-size: 12.5px;
  background: var(--ph);
  color: #08100A;
  box-shadow:
    0 0 30px rgba(var(--ph-r), 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
  transition:
    background 1.3s ease,
    box-shadow 1.3s ease,
    opacity 0.12s,
    transform 0.1s;
}

.button-primary:hover {
  opacity: 0.88;
}

.button-outline {
  width: 100%;
  padding: 14px 24px;
  font-size: 12.5px;
  background: rgba(var(--ph-r), 0.1);
  color: var(--ph);
  transition:
    background 1.3s ease,
    color 1.3s ease,
    opacity 0.12s,
    transform 0.1s;
}

.button-outline:hover {
  background: rgba(var(--ph-r), 0.16);
}

.button-secondary {
  background: var(--surface-2);
  color: var(--text);
}

.button-secondary:hover {
  background: var(--surface-3);
}

.button-ghost {
  background: transparent;
  color: var(--text-lo);
}

.button-ghost:hover {
  color: var(--text-mid);
}


/* === Secondary Controls === */
.controls {
  padding: 0 20px 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* Controls buttons are clearly a tier below the primary action */
.controls .button {
  padding: 8px 14px;
  font-size: 10.5px;
  letter-spacing: 0.07em;
}

/* When idle — skip & reset are both hidden, collapse the row */
.controls[data-visible-count="1"] {
  display: none;
}

/* === Card Footer === */
.card-footer {
  display: flex;
  align-items: center;
  padding: 12px 20px 16px;
  gap: 16px;
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.meta-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-lo);
}

.meta-value {
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-mid);
}

/* === Settings Icon Button === */
.btn-icon {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border: none;
  border-radius: var(--r-sm);
  color: var(--text-mid);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.btn-icon:hover {
  background: var(--surface-3);
  color: var(--text);
}

/* === Settings Backdrop === */
.settings-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.settings-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

/* === Settings Panel (bottom sheet) === */
.settings-panel {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%) translateY(100%);
  width: min(100vw, 500px);
  max-height: 84vh;
  background: var(--surface);
  border-radius: var(--r-card) var(--r-card) 0 0;
  box-shadow: 0 -12px 48px rgba(0, 0, 0, 0.5);
  z-index: 51;
  overflow-y: auto;
  overscroll-behavior: contain;
  transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
}

.settings-panel.open {
  transform: translateX(-50%) translateY(0);
}

.sp-handle {
  width: 36px;
  height: 4px;
  background: var(--surface-3);
  border-radius: 2px;
  margin: 12px auto 0;
}

.sp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 16px;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

.sp-title {
  font-family: 'Playfair Display', 'Georgia', serif;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.02em;
  color: var(--text);
}

.sp-body {
  padding: 24px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.sp-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sp-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-mid);
}

/* === Settings Fields === */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.field span {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-mid);
}

.field input {
  background: var(--surface-2);
  border: none;
  border-radius: var(--r-sm);
  color: var(--text);
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  font-size: 14px;
  padding: 9px 11px;
  min-height: 44px;
  outline: none;
  width: 100%;
  transition: background 0.15s;
  -moz-appearance: textfield;
}

.field input:focus {
  background: var(--surface-3);
}

.field input::-webkit-inner-spin-button,
.field input::-webkit-outer-spin-button {
  opacity: 0.35;
}

/* === Session URL === */
.session-url {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.session-url-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-mid);
}

.session-url a {
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  font-size: 11px;
  color: var(--work);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
  transition: opacity 0.15s;
}

.session-url a:hover {
  opacity: 0.75;
  text-decoration: underline;
}

/* === Notes === */
.notes {
  font-size: 13px;
  color: var(--text-mid);
  line-height: 1.65;
}

/* === Command Blocks === */
.command-block {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.command-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-lo);
}

.command {
  display: block;
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  font-size: 11px;
  color: var(--text-mid);
  background: var(--bg);
  border-radius: var(--r-xs);
  padding: 9px 11px;
  overflow-x: auto;
  white-space: nowrap;
  line-height: 1.5;
}

/* === Responsive === */
@media (max-width: 540px) {
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 420px) {
  .app-shell {
    padding-top: 20px;
  }

  .topbar {
    flex-wrap: wrap;
  }

  .session-row {
    width: 100%;
  }

  .session-row .field {
    flex: 1;
    min-width: 0;
  }

  .session-row input {
    width: 100%;
  }

  .countdown {
    font-size: clamp(64px, 23vw, 100px);
  }
}

@media (max-width: 320px) {
  .card-top {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .countdown {
    font-size: clamp(56px, 25vw, 88px);
  }
}

/* Blocks */
.blocks-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.block-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--ink);
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: 8px;
}

.block-row-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
  cursor: pointer;
}

.block-row-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.block-row-label {
  font-weight: 600;
}

.block-row-times {
  color: var(--muted);
  font-size: 0.75rem;
}

.block-row-schedule {
  color: var(--work);
  font-size: 0.72rem;
  opacity: 0.8;
}

.block-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--work);
  flex-shrink: 0;
}

.block-row--active {
  background: rgba(200, 255, 60, 0.08);
  border: 1px solid rgba(200, 255, 60, 0.15);
}

.block-row--active .block-row-times {
  color: var(--work);
}

.block-row--past {
  opacity: 0.5;
}

.block-date-header {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 8px 0 2px;
}

.block-date-header--past {
  opacity: 0.5;
}

.block-past-toggle {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 8px 0;
  text-align: left;
}

.block-past-toggle:hover {
  color: var(--ink);
}

.block-empty {
  color: var(--muted);
  font-size: 0.8rem;
  padding: 8px 0;
}

.block-row-delete {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px;
  flex-shrink: 0;
}

.block-row-delete:hover {
  color: #ff6b6b;
}

.blocks-auth-prompt {
  color: var(--muted);
  font-size: 0.8rem;
}

.blocks-auth-prompt p {
  margin: 0;
}

.block-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.block-form-status {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  margin: 2px 0;
}

.block-form-status[data-type="error"] {
  color: #ff6b6b;
}

.block-form-status[data-type="info"] {
  color: var(--muted);
}

.sp-label--toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  text-align: left;
  width: 100%;
}

.sp-label--toggle::after {
  content: ' +';
  opacity: 0.5;
}

.sp-label--toggle[aria-expanded="true"]::after {
  content: ' −';
}

.block-indicator {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--work);
  background: rgba(200, 255, 60, 0.08);
  border: 1px solid rgba(200, 255, 60, 0.12);
  border-radius: var(--r-sm);
  padding: 8px 12px;
  margin-top: 4px;
}

/* Edit block dialog */
dialog.edit-block-dialog {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--surface-2);
  border-radius: var(--r-card);
  padding: 24px;
  max-width: 400px;
  width: calc(100% - 32px);
}

dialog.edit-block-dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.edit-block-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.edit-block-form h3 {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 1rem;
}

.edit-block-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.75rem;
  color: var(--muted);
}

.edit-block-form input {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--surface-3);
  border-radius: var(--r-sm);
  color: var(--ink);
}

.edit-block-times {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.edit-block-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 4px;
}

/* Auth section */
.auth-buttons {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.auth-status {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--ink);
  margin: 0 0 10px;
}

.auth-register-details {
  margin-top: 4px;
}

.auth-register-details summary {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 0;
}

.auth-register-details summary:hover {
  color: var(--ink);
}

.auth-error {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: #ff6b6b;
  margin: 8px 0 0;
}


@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
