/* ==========================================================================
   ChronoShift Precision Design System
   Aesthetic: Obsidian Chronometer & Precision Glassmorphism
   Focused: Time + Days, Hours, Minutes & Subsequent Chained Offsets
   ========================================================================== */

:root {
  /* Color Palette */
  --bg-dark: #080c14;
  --bg-deep: #05080e;
  --card-bg: rgba(15, 23, 42, 0.72);
  --card-bg-solid: #0f172a;
  --card-bg-hover: rgba(30, 41, 59, 0.75);
  --card-border: rgba(255, 255, 255, 0.08);
  --card-border-active: rgba(16, 185, 129, 0.4);
  --card-border-glow: rgba(6, 182, 212, 0.25);
  
  /* Accent Colors */
  --emerald-primary: #10b981;
  --emerald-glow: rgba(16, 185, 129, 0.25);
  --cyan-primary: #06b6d4;
  --cyan-glow: rgba(6, 182, 212, 0.25);
  --amber-primary: #f59e0b;
  --amber-glow: rgba(245, 158, 11, 0.2);
  --rose-primary: #f43f5e;
  --rose-glow: rgba(244, 63, 94, 0.25);

  /* Typography Colors */
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --text-emerald: #34d399;
  --text-cyan: #38bdf8;

  /* Typography Fonts */
  --font-display: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Shadows & Elevations */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 24px -4px rgba(0, 0, 0, 0.6), 0 0 1px 1px rgba(255, 255, 255, 0.05);
  --shadow-hero: 0 20px 50px -10px rgba(0, 0, 0, 0.8), 0 0 40px -10px rgba(16, 185, 129, 0.15);
  --shadow-glow: 0 0 25px rgba(6, 182, 212, 0.25);

  /* Layout */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-smooth: 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Base Reset & Document Setup */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  color-scheme: dark;
  -webkit-text-size-adjust: 100%;
  overflow-x: clip;
  overflow-x: hidden;
}

button, input, select, textarea {
  touch-action: manipulation;
}

body {
  min-height: 100vh;
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-display);
  overflow-x: clip;
  overflow-x: hidden;
  max-width: 100vw;
  width: 100%;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  position: relative;
}

/* Ambient Subtle Background Glow */
.ambient-glow {
  position: fixed;
  pointer-events: none;
  border-radius: 50%;
  filter: blur(140px);
  z-index: 0;
  opacity: 0.45;
  transition: opacity 1s ease;
}

.glow-1 {
  width: 650px;
  height: 650px;
  top: -150px;
  right: -100px;
  background: radial-gradient(circle, rgba(6, 182, 212, 0.18) 0%, rgba(6, 182, 212, 0) 70%);
}

.glow-2 {
  width: 700px;
  height: 700px;
  bottom: 50px;
  left: -200px;
  background: radial-gradient(circle, rgba(16, 185, 129, 0.14) 0%, rgba(16, 185, 129, 0) 70%);
}

.glow-3 {
  width: 500px;
  height: 500px;
  top: 40%;
  left: 45%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, rgba(139, 92, 246, 0.08) 0%, rgba(139, 92, 246, 0) 70%);
}

/* App Container */
.app-layout {
  position: relative;
  z-index: 1;
  max-width: 1240px;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 3rem 1.5rem;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  gap: 1.5rem;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.2), rgba(6, 182, 212, 0.2));
  border: 1px solid rgba(16, 185, 129, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--emerald-primary);
  box-shadow: 0 0 20px var(--emerald-glow);
}

.brand-text h1 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  display: flex;
  align-items: baseline;
  line-height: 1.1;
}

.brand-dot {
  color: var(--emerald-primary);
}

.brand-tagline {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.header-controls-quick,
.header-controls-pills {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

/* Toggle Group for 12h/24h */
.toggle-group {
  display: inline-flex;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-full);
  padding: 3px;
  gap: 2px;
}

.btn-toggle {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  font-family: var(--font-mono);
  padding: 4px 12px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-toggle.active {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.btn-toggle:hover:not(.active) {
  color: var(--text-main);
}

.icon-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--card-border);
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  border-color: rgba(255, 255, 255, 0.2);
}

.history-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 6px 14px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: var(--text-emerald);
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  transition: all var(--transition-fast);
}

.history-pill-btn:hover {
  background: rgba(16, 185, 129, 0.2);
  border-color: var(--emerald-primary);
  transform: translateY(-1px);
}

.history-pill-btn .badge {
  background: var(--emerald-primary);
  color: #061910;
  font-size: 0.72rem;
  font-family: var(--font-mono);
  font-weight: 700;
  padding: 1px 7px;
  border-radius: var(--radius-full);
}

/* Glassmorphism Card Style */
.glass-card {
  background: var(--card-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

/* Top Live Status Card */
.live-status-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1.25rem;
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.85) 0%, rgba(10, 15, 29, 0.9) 100%);
  border: 1px solid rgba(6, 182, 212, 0.2);
  box-shadow: 0 8px 30px -10px rgba(6, 182, 212, 0.15);
  margin-bottom: 1.5rem;
}

.live-clock-wrapper {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.pulse-indicator {
  position: relative;
  width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pulse-dot {
  width: 10px;
  height: 10px;
  background: var(--emerald-primary);
  border-radius: 50%;
  box-shadow: 0 0 10px var(--emerald-primary);
}

.pulse-ring {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid var(--emerald-primary);
  animation: pulseRipple 2s cubic-bezier(0.24, 0, 0.38, 1) infinite;
}

@keyframes pulseRipple {
  0% { transform: scale(0.8); opacity: 1; }
  100% { transform: scale(2.4); opacity: 0; }
}

.label-tiny {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 2px;
}

.live-clock-display {
  font-family: var(--font-mono);
  font-size: 1.85rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.02em;
  line-height: 1.1;
  text-shadow: 0 0 20px rgba(255, 255, 255, 0.15);
}

.live-date-display {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.time-source-toggle {
  display: inline-flex;
  background: rgba(0, 0, 0, 0.3);
  padding: 4px;
  border-radius: var(--radius-full);
  border: 1px solid var(--card-border);
  gap: 4px;
}

.radio-chip input {
  display: none;
}

.radio-chip .chip-inner {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 7px 16px;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.radio-chip input:checked + .chip-inner {
  background: rgba(6, 182, 212, 0.2);
  color: var(--text-cyan);
  border: 1px solid rgba(6, 182, 212, 0.4);
}

.custom-time-picker-wrapper {
  width: 100%;
  padding-top: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  animation: fadeIn 0.25s ease;
}

.custom-inputs-row {
  display: flex;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
}

.input-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.input-field label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.custom-input {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  outline: none;
  transition: all var(--transition-fast);
}

.custom-input:focus {
  border-color: var(--cyan-primary);
  box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.2);
}

/* Calculator Grid */
.calculator-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 1.5rem;
  margin-bottom: 2rem;
  min-width: 0;
  max-width: 100%;
}

.calc-input-panel,
.calc-result-panel {
  min-width: 0;
  max-width: 100%;
}

@media (max-width: 950px) {
  .calculator-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Card Headers */
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.card-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

/* Smart Input Field */
.smart-input-box {
  margin-bottom: 1.25rem;
}

.smart-input-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.4rem;
}

.smart-input-header label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}

.helper-hint {
  font-size: 0.7rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
}

.smart-input-field {
  position: relative;
  display: flex;
  align-items: center;
}

.smart-input-field svg {
  position: absolute;
  left: 12px;
  color: var(--text-dim);
  pointer-events: none;
}

.smart-input-field input {
  width: 100%;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  padding: 10px 36px 10px 38px;
  border-radius: var(--radius-md);
  outline: none;
  transition: all var(--transition-fast);
}

.smart-input-field input:focus {
  border-color: var(--emerald-primary);
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.2);
}

.btn-clear {
  position: absolute;
  right: 10px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
}

.btn-clear:hover {
  color: #fff;
}

/* Presets */
.presets-section {
  margin-bottom: 1.5rem;
  min-width: 0;
  max-width: 100%;
}

.preset-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
  min-width: 0;
  max-width: 100%;
}

.chip-preset {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.chip-preset:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.chip-preset.active {
  background: rgba(6, 182, 212, 0.18);
  border-color: var(--cyan-primary);
  color: var(--cyan-primary);
  box-shadow: 0 0 12px rgba(6, 182, 212, 0.2);
}

/* ==========================================================================
   DYNAMIC STEPS CONTAINER & MULTI-STEP CARDS
   ========================================================================== */
.steps-container {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.step-card {
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: var(--radius-md);
  padding: 1.15rem;
  position: relative;
  transition: all var(--transition-fast);
  animation: fadeIn 0.25s ease;
}

.step-card:hover {
  border-color: rgba(255, 255, 255, 0.15);
}

.step-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.step-badge-group {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.step-badge {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  background: rgba(6, 182, 212, 0.15);
  color: var(--cyan-primary);
  border: 1px solid rgba(6, 182, 212, 0.3);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  letter-spacing: 0.05em;
}

.step-direction-switch {
  display: inline-flex;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.btn-step-dir {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 700;
  font-family: var(--font-mono);
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-step-dir.active[data-dir="add"] {
  background: rgba(16, 185, 129, 0.2);
  color: var(--emerald-primary);
}

.btn-step-dir.active[data-dir="sub"] {
  background: rgba(244, 63, 94, 0.2);
  color: var(--rose-primary);
}

.btn-remove-step {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 0.8rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.btn-remove-step:hover {
  background: rgba(244, 63, 94, 0.15);
  color: var(--rose-primary);
}

/* Numeric Days, Hours, Minutes Stepper Grid */
.steppers-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}

.stepper-box {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
}

.stepper-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.stepper-header label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}

.unit-badge {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-cyan);
  background: rgba(6, 182, 212, 0.1);
  padding: 1px 6px;
  border-radius: 4px;
}

.stepper-control {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.step-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.step-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.25);
  color: #fff;
}

.step-btn:active {
  transform: scale(0.95);
}

.step-input {
  width: 100%;
  text-align: center;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 700;
  padding: 4px 4px;
  border-radius: var(--radius-sm);
  outline: none;
  transition: all var(--transition-fast);
  -moz-appearance: textfield;
}

.step-input::-webkit-outer-spin-button,
.step-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.step-input:focus {
  border-color: var(--cyan-primary);
  box-shadow: 0 0 10px rgba(6, 182, 212, 0.2);
}

/* Calculation Note Input */
.calculation-note-box {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.calculation-note-box label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}

.calculation-note-box input {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  font-size: 0.88rem;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  outline: none;
  transition: all var(--transition-fast);
}

.calculation-note-box input:focus {
  border-color: rgba(255, 255, 255, 0.25);
  background: rgba(0, 0, 0, 0.45);
}

/* ==========================================================================
   RESULT CARD (HERO ELEMENT)
   ========================================================================== */
.result-card {
  background: linear-gradient(145deg, rgba(16, 24, 40, 0.9) 0%, rgba(10, 16, 28, 0.95) 100%);
  border: 1px solid rgba(16, 185, 129, 0.3);
  box-shadow: var(--shadow-hero);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  position: relative;
  overflow: hidden;
}

.result-glow {
  position: absolute;
  top: -60px;
  right: -60px;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(16, 185, 129, 0.2) 0%, rgba(16, 185, 129, 0) 70%);
  pointer-events: none;
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.result-status-badge {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  background: rgba(16, 185, 129, 0.15);
  color: var(--text-emerald);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.result-status-badge.subtracted {
  background: rgba(244, 63, 94, 0.15);
  color: var(--rose-primary);
  border-color: rgba(244, 63, 94, 0.3);
}

.result-relative-tag {
  font-size: 0.85rem;
  color: var(--text-cyan);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.result-time-container {
  padding: 0.5rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.result-time-hero {
  font-family: var(--font-mono);
  font-size: clamp(2.4rem, 5vw, 3.4rem);
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.03em;
  line-height: 1;
  text-shadow: 0 0 30px rgba(16, 185, 129, 0.25);
  transition: transform 0.2s ease;
}

.result-time-hero.pulse {
  animation: numPop 0.35s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

@keyframes numPop {
  0% { transform: scale(0.96); opacity: 0.8; }
  50% { transform: scale(1.02); }
  100% { transform: scale(1); opacity: 1; }
}

.result-date-display {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

/* Meta Grid in Result */
.result-meta-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

.meta-item {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.05);
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-md);
}

.meta-label {
  display: block;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 2px;
}

.meta-value {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
}

/* Multi-Step Progression Timeline Box */
.timeline-box {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
}

.timeline-steps {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.timeline-step-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
  gap: 0.75rem;
  position: relative;
}

.timeline-step-label {
  color: var(--text-dim);
  font-size: 0.75rem;
}

.timeline-step-offset {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.8rem;
  padding: 1px 7px;
  border-radius: var(--radius-full);
}

.timeline-step-offset.add {
  background: rgba(16, 185, 129, 0.15);
  color: var(--emerald-primary);
}

.timeline-step-offset.sub {
  background: rgba(244, 63, 94, 0.15);
  color: var(--rose-primary);
}

.timeline-step-time {
  font-family: var(--font-mono);
  font-weight: 600;
  color: #fff;
  margin-left: auto;
}

/* Nighttime Alert */
.night-alert {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: #fde68a;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-md);
  font-size: 0.8rem;
  line-height: 1.35;
}

.night-alert svg {
  flex-shrink: 0;
  color: var(--amber-primary);
}

/* Result Actions Buttons */
.result-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.btn-primary, .btn-accent, .btn-countdown, .btn-subtle, .btn-danger-subtle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 10px 18px;
  font-family: var(--font-display);
  font-size: 0.88rem;
  font-weight: 700;
  border-radius: var(--radius-md);
  cursor: pointer;
  border: none;
  transition: all var(--transition-fast);
}

.btn-primary {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #042416;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.35);
  flex: 1 1 140px;
}

.btn-primary:hover {
  background: linear-gradient(135deg, #34d399 0%, #10b981 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.45);
}

.btn-accent {
  background: rgba(6, 182, 212, 0.15);
  border: 1px solid rgba(6, 182, 212, 0.4);
  color: var(--cyan-primary);
}

.btn-accent:hover {
  background: rgba(6, 182, 212, 0.25);
  border-color: var(--cyan-primary);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.8rem;
}

.btn-countdown {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-main);
  flex: 1 1 140px;
}

.btn-countdown:hover {
  background: rgba(255, 255, 255, 0.12);
  transform: translateY(-2px);
}

.btn-subtle {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-muted);
}

.btn-subtle:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.btn-danger-subtle {
  background: rgba(244, 63, 94, 0.1);
  border: 1px solid rgba(244, 63, 94, 0.25);
  color: #fda4af;
}

.btn-danger-subtle:hover {
  background: rgba(244, 63, 94, 0.2);
  border-color: var(--rose-primary);
  color: #fff;
}

/* Active Countdown Card */
.active-timer-card {
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(6, 182, 212, 0.4);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-top: 0.5rem;
  box-shadow: 0 0 25px rgba(6, 182, 212, 0.15);
}

.timer-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.timer-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--cyan-primary);
}

.live-blink-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--cyan-primary);
  animation: blink 1s infinite alternate;
}

@keyframes blink {
  from { opacity: 1; }
  to { opacity: 0.2; }
}

.btn-close-timer {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 1.2rem;
  cursor: pointer;
}

.btn-close-timer:hover {
  color: #fff;
}

.timer-digits {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: 0.05em;
  text-align: center;
  margin: 0.25rem 0;
}

.timer-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 0.75rem;
}

.progress-bar-container {
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--cyan-primary), var(--emerald-primary));
  transition: width 1s linear;
}

/* ==========================================================================
   PERSISTENT HISTORY SECTION
   ========================================================================== */
.history-section {
  margin-top: 1rem;
}

.history-card {
  padding: 1.5rem;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.history-title-area {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.icon-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(16, 185, 129, 0.12);
  color: var(--emerald-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(16, 185, 129, 0.25);
}

.history-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.filter-pills {
  display: inline-flex;
  background: rgba(0, 0, 0, 0.3);
  padding: 2px;
  border-radius: var(--radius-md);
  border: 1px solid var(--card-border);
}

.btn-filter {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-filter.active {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.history-search input {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 0.82rem;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  outline: none;
  width: 180px;
}

.history-search input:focus {
  border-color: var(--cyan-primary);
}

/* History List & Items */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-height: 460px;
  overflow-y: auto;
  padding-right: 4px;
}

.history-list::-webkit-scrollbar {
  width: 6px;
}

.history-list::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 3px;
}

.history-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}

.history-item {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-md);
  padding: 1rem 1.15rem;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 1rem;
  align-items: center;
  transition: all var(--transition-fast);
}

.history-item:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.12);
  transform: translateX(2px);
}

.history-star-btn {
  background: transparent;
  border: none;
  font-size: 1.25rem;
  color: var(--text-dim);
  cursor: pointer;
  transition: all var(--transition-fast);
  line-height: 1;
}

.history-star-btn.starred {
  color: var(--amber-primary);
  text-shadow: 0 0 10px rgba(245, 158, 11, 0.4);
}

.history-main-info {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  overflow: hidden;
}

.history-top-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.history-label-tag {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 4px;
  background: rgba(6, 182, 212, 0.12);
  color: var(--cyan-primary);
  border: 1px solid rgba(6, 182, 212, 0.25);
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-time-eq {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.history-offset-pill {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--radius-full);
}

.history-offset-pill.add {
  background: rgba(16, 185, 129, 0.15);
  color: var(--emerald-primary);
}

.history-offset-pill.sub {
  background: rgba(244, 63, 94, 0.15);
  color: var(--rose-primary);
}

.history-bottom-row {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.history-target-time {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
}

.history-target-date {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.history-recorded-at {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-left: auto;
}

.history-item-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.history-action-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.history-action-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.history-action-btn.btn-trash:hover {
  background: rgba(244, 63, 94, 0.2);
  color: var(--rose-primary);
  border-color: var(--rose-primary);
}

/* Empty History State */
.empty-history-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-dim);
}

.empty-history-icon {
  margin-bottom: 0.75rem;
  opacity: 0.4;
}

.empty-history-state p {
  font-size: 0.9rem;
}

/* Footer */
.app-footer {
  margin-top: auto;
  padding: 1.25rem 0 0.5rem 0;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.footer-left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.footer-sep {
  opacity: 0.4;
}

kbd {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Toast Container */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
}

.toast {
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(16, 185, 129, 0.4);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  transform: translateY(20px);
  opacity: 0;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: auto;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast-icon {
  color: var(--emerald-primary);
}

.toast.toast-info {
  border-color: rgba(6, 182, 212, 0.4);
}

.toast.toast-info .toast-icon {
  color: var(--cyan-primary);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}



/* ==========================================================================
   CLOUDFLARE KV SYNC STYLES & MODAL
   ========================================================================== */
.sync-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 6px 14px;
  background: rgba(6, 182, 212, 0.08);
  border: 1px solid rgba(6, 182, 212, 0.25);
  color: var(--text-cyan);
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.sync-pill-btn:hover {
  background: rgba(6, 182, 212, 0.18);
  border-color: var(--cyan-primary);
  transform: translateY(-1px);
}

.sync-pill-btn.synced {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.35);
  color: var(--text-emerald);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  animation: fadeIn 0.2s ease;
}

.modal-card {
  background: linear-gradient(145deg, #0d1424 0%, #080d1a 100%);
  border: 1px solid rgba(6, 182, 212, 0.3);
  border-radius: var(--radius-lg);
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.8), 0 0 35px rgba(6, 182, 212, 0.15);
  width: 100%;
  max-width: 540px;
  overflow: hidden;
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.modal-title-wrap {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.modal-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: rgba(6, 182, 212, 0.15);
  color: var(--cyan-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(6, 182, 212, 0.3);
}

.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.btn-close-modal {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.btn-close-modal:hover {
  color: #fff;
}

.modal-body {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.sync-status-banner {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.8rem;
  flex-wrap: wrap;
}

.sync-status-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
}

.sync-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
}

.sync-status-dot.active {
  background: var(--emerald-primary);
  box-shadow: 0 0 10px var(--emerald-primary);
}

.sync-time-tag {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
}

.modal-section-box {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.modal-section-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  text-transform: uppercase;
}

.sync-code-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.sync-code-input {
  flex: 1;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  outline: none;
}

.sync-code-input:focus {
  border-color: var(--cyan-primary);
  box-shadow: 0 0 10px rgba(6, 182, 212, 0.2);
}

.modal-hint {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.modal-actions-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.5rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  flex-wrap: wrap;
}

/* ==========================================================================
   MOBILE & TABLET RESPONSIVE SYSTEM
   ========================================================================== */

/* Tablet & Medium Screens (<= 950px) */
@media (max-width: 950px) {
  .calculator-grid {
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
    gap: 1.25rem;
  }

  .live-status-card {
    margin-bottom: 1.25rem;
  }
}

/* Small Tablets & Large Phones (<= 768px) */
@media (max-width: 768px) {
  /* Prevent iOS automatic zoom on focus by enforcing 16px minimum font size */
  input[type="text"],
  input[type="number"],
  input[type="date"],
  input[type="time"],
  select,
  textarea {
    font-size: 16px !important;
  }

  /* Two-row mobile header: brand on left, quick toggles on right, pills spanning row 2 */
  .app-header {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "brand quick"
      "pills pills";
    row-gap: 0.75rem;
    column-gap: 0.5rem;
    align-items: center;
    padding: 0.5rem 0 0.85rem 0;
  }

  .brand {
    grid-area: brand;
    width: auto;
  }

  .brand-text h1 {
    font-size: 1.25rem;
  }

  .brand-tagline {
    font-size: 0.65rem;
    letter-spacing: 0.04em;
  }

  .header-controls {
    display: contents;
  }

  .header-controls-quick {
    grid-area: quick;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.45rem;
  }

  .header-controls-pills {
    grid-area: pills;
    width: 100%;
    display: flex;
    gap: 0.5rem;
  }

  .sync-pill-btn,
  .history-pill-btn {
    flex: 1 1 0;
    justify-content: center;
    padding: 8px 10px;
    font-size: 0.8rem;
    min-width: 0;
  }

  #syncButtonLabel {
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* Mobile Handheld Devices (<= 600px) */
@media (max-width: 600px) {
  .app-layout {
    padding: max(0.75rem, env(safe-area-inset-top)) max(0.75rem, env(safe-area-inset-right)) max(2rem, env(safe-area-inset-bottom)) max(0.75rem, env(safe-area-inset-left));
    gap: 1rem;
  }

  .ambient-glow {
    filter: blur(80px);
    opacity: 0.3;
  }

  .glow-1 {
    width: 320px;
    height: 320px;
    top: -80px;
    right: -80px;
  }

  .glow-2 {
    width: 340px;
    height: 340px;
    left: -120px;
    bottom: -60px;
  }

  .glow-3 {
    display: none;
  }

  /* Compact glass card padding for mobile screens */
  .glass-card {
    padding: 1rem;
    border-radius: var(--radius-md);
  }

  /* Live Anchor Banner */
  .live-status-card {
    padding: 0.95rem;
    gap: 0.85rem;
  }

  .live-clock-wrapper {
    gap: 0.75rem;
    width: 100%;
  }

  .live-clock-display {
    font-size: clamp(1.4rem, 6.2vw, 1.85rem);
    letter-spacing: -0.01em;
  }

  .live-date-display {
    font-size: 0.78rem;
  }

  .time-source-toggle {
    width: 100%;
    display: flex;
    padding: 3px;
  }

  .radio-chip {
    flex: 1;
    display: flex;
  }

  .radio-chip .chip-inner {
    width: 100%;
    justify-content: center;
    padding: 8px 6px;
    font-size: 0.78rem;
    gap: 0.35rem;
  }

  .custom-inputs-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem;
    align-items: flex-end;
  }

  .custom-inputs-row .input-field {
    width: 100%;
  }

  .custom-inputs-row .custom-input {
    width: 100%;
    padding: 8px 6px;
  }

  #btnResetToNow {
    grid-column: 1 / -1;
    width: 100%;
    justify-content: center;
    padding: 9px;
  }

  /* Input Panel & Card Headers */
  .card-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    margin-bottom: 1rem;
  }

  .card-header h3 {
    font-size: 1.1rem;
  }

  .subtitle {
    font-size: 0.78rem;
  }

  #btnAddStep {
    width: 100%;
    justify-content: center;
    padding: 10px 14px;
    font-size: 0.85rem;
  }

  /* Smart input expression bar */
  .smart-input-box {
    margin-bottom: 1rem;
  }

  .smart-input-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }

  .smart-input-field input {
    padding: 10px 32px 10px 36px;
  }

  /* Presets: native-like horizontal swipe */
  .presets-section {
    margin-bottom: 1.15rem;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
  }

  .preset-chips {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 0.45rem;
    padding-bottom: 4px;
    width: 100%;
    max-width: 100%;
  }

  .preset-chips::-webkit-scrollbar {
    display: none;
  }

  .chip-preset {
    flex-shrink: 0;
    padding: 7px 11px;
    font-size: 0.78rem;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
  }

  /* Dynamic Steps */
  .steps-container {
    gap: 0.85rem;
    margin-bottom: 1.15rem;
    min-width: 0;
    max-width: 100%;
  }

  .step-card {
    padding: 0.85rem 0.65rem;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
  }

  .step-header {
    margin-bottom: 0.65rem;
    gap: 0.45rem;
  }

  .step-badge {
    font-size: 0.68rem;
    padding: 2px 6px;
  }

  .btn-step-dir {
    padding: 4px 8px;
    font-size: 0.75rem;
  }

  .btn-remove-step {
    padding: 4px 8px;
    font-size: 0.75rem;
  }

  /* Steppers: keep DAYS, HOURS, MINUTES side-by-side in 3 columns */
  .steppers-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.35rem;
    width: 100%;
    max-width: 100%;
  }

  .stepper-box {
    padding: 0.5rem 0.25rem;
    min-width: 0;
    overflow: hidden;
    box-sizing: border-box;
  }

  .stepper-header {
    margin-bottom: 0.35rem;
  }

  .stepper-header label {
    font-size: 0.62rem;
  }

  .unit-badge {
    font-size: 0.6rem;
    padding: 0 4px;
  }

  .stepper-control {
    gap: 2px;
    justify-content: center;
  }

  .step-btn {
    width: 30px;
    height: 36px;
    font-size: 0.9rem;
    border-radius: 6px;
  }

  .step-input {
    font-size: 1.15rem;
    padding: 4px 0;
  }

  .calculation-note-box input {
    padding: 9px 12px;
  }

  /* Target Result Card */
  .result-card {
    padding: 1.15rem 1rem;
    gap: 1rem;
  }

  .result-header {
    gap: 0.5rem;
  }

  .result-status-badge {
    font-size: 0.68rem;
    padding: 2px 8px;
  }

  .result-relative-tag {
    font-size: 0.8rem;
  }

  .result-time-hero {
    font-size: clamp(2rem, 9.5vw, 3.2rem);
  }

  .result-date-display {
    font-size: 0.92rem;
  }

  .result-meta-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
  }

  .meta-item {
    padding: 0.5rem 0.65rem;
  }

  .meta-label {
    font-size: 0.62rem;
  }

  .meta-value {
    font-size: 0.85rem;
  }

  /* Action buttons: symmetrical 2 + 1 thumb grid */
  .result-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
  }

  #btnCopyResult {
    grid-column: 1 / 2;
    width: 100%;
    padding: 11px 10px;
    font-size: 0.85rem;
  }

  #btnSaveHistory {
    grid-column: 2 / 3;
    width: 100%;
    padding: 11px 10px;
    font-size: 0.85rem;
  }

  #btnStartCountdown {
    grid-column: 1 / -1;
    width: 100%;
    padding: 11px 10px;
    font-size: 0.85rem;
  }

  .active-timer-card {
    padding: 0.85rem;
  }

  .timer-digits {
    font-size: clamp(1.6rem, 7vw, 2.1rem);
  }

  .timeline-step-row {
    font-size: 0.78rem;
    flex-wrap: wrap;
    gap: 0.25rem;
  }

  .timeline-step-time {
    margin-left: 0;
    width: 100%;
    font-size: 0.82rem;
  }

  .night-alert {
    font-size: 0.75rem;
    padding: 0.55rem 0.75rem;
  }

  /* Persistent History Section */
  .history-card {
    padding: 1.15rem 1rem;
  }

  .history-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.85rem;
    margin-bottom: 1rem;
    padding-bottom: 0.85rem;
  }

  .history-title-area {
    gap: 0.75rem;
  }

  .icon-circle {
    width: 36px;
    height: 36px;
    min-width: 36px;
  }

  .history-title-area h2 {
    font-size: 1.15rem;
  }

  .history-title-area .subtitle {
    font-size: 0.78rem;
  }

  .history-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
    width: 100%;
  }

  .filter-pills {
    grid-column: 1 / -1;
    display: flex;
    width: 100%;
  }

  .btn-filter {
    flex: 1;
    text-align: center;
    padding: 7px 10px;
    font-size: 0.8rem;
  }

  .history-search {
    grid-column: 1 / -1;
    width: 100%;
  }

  .history-search input {
    width: 100%;
    padding: 9px 12px;
  }

  #btnExportHistory {
    grid-column: 1 / 2;
    width: 100%;
    justify-content: center;
    padding: 9px 10px;
    font-size: 0.82rem;
  }

  #btnClearHistory {
    grid-column: 2 / 3;
    width: 100%;
    justify-content: center;
    padding: 9px 10px;
    font-size: 0.82rem;
  }

  /* History item: grid area prevents orphaned star and cramped text */
  .history-item {
    display: grid;
    grid-template-columns: 28px 1fr;
    grid-template-areas:
      "star main"
      "actions actions";
    gap: 0.5rem 0.65rem;
    padding: 0.85rem;
  }

  .history-star-btn {
    grid-area: star;
    align-self: flex-start;
    font-size: 1.3rem;
    padding-top: 2px;
  }

  .history-main-info {
    grid-area: main;
    min-width: 0;
  }

  .history-top-row {
    gap: 0.35rem;
    margin-bottom: 0.3rem;
  }

  .history-label-tag {
    max-width: 120px;
    font-size: 0.68rem;
  }

  .history-offset-pill {
    font-size: 0.7rem;
    padding: 1px 6px;
  }

  .history-time-eq {
    font-size: 0.75rem;
  }

  .history-bottom-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.2rem;
  }

  .history-target-time {
    font-size: 1.1rem;
    line-height: 1.1;
  }

  .history-target-date {
    font-size: 0.78rem;
  }

  .history-recorded-at {
    margin-left: 0;
    font-size: 0.68rem;
  }

  .history-item-actions {
    grid-area: actions;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
  }

  .history-action-btn {
    width: 36px;
    height: 36px;
  }

  /* Cloudflare KV Sync Modal on mobile */
  .modal-overlay {
    padding: 1rem;
    align-items: center;
    justify-content: center;
  }

  .modal-card {
    max-height: calc(100vh - 2rem);
    width: 100%;
    max-width: 440px;
    margin: auto;
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .modal-header {
    padding: 1rem 1.15rem;
  }

  .modal-header h3 {
    font-size: 1.05rem;
  }

  .modal-body {
    padding: 1.15rem;
    overflow-y: auto;
    gap: 1rem;
  }

  .sync-status-banner {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.4rem;
  }

  .sync-code-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }

  .sync-code-input {
    grid-column: 1 / -1;
    width: 100%;
  }

  #btnConnectSyncKey {
    grid-column: 1 / -1;
    padding: 10px;
    font-size: 0.85rem;
  }

  #btnCopySyncKey,
  #btnGenerateSyncKey {
    width: 100%;
    padding: 9px;
    font-size: 0.85rem;
  }

  .modal-actions-row {
    flex-direction: column;
    gap: 0.5rem;
  }

  .modal-actions-row button {
    width: 100%;
    justify-content: center;
    padding: 10px;
    font-size: 0.85rem;
  }

  /* Footer & Toasts */
  .app-footer {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.5rem;
    padding: 1rem 0;
  }

  .footer-left {
    flex-direction: column;
    gap: 0.25rem;
  }

  .footer-sep {
    display: none;
  }

  .keyboard-shortcuts-hint {
    display: none;
  }

  .toast-container {
    bottom: max(16px, env(safe-area-inset-bottom));
    left: 16px;
    right: 16px;
    align-items: center;
  }

  .toast {
    width: 100%;
    max-width: 380px;
    justify-content: center;
    padding: 10px 14px;
    font-size: 0.82rem;
  }
}

/* Extra Compact Phones (<= 360px, e.g. iPhone SE 1st gen) */
@media (max-width: 360px) {
  .app-layout {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }

  .header-controls-quick {
    gap: 0.35rem;
  }

  .toggle-group {
    padding: 2px;
  }

  .btn-toggle {
    padding: 3px 8px;
    font-size: 0.72rem;
  }

  .icon-btn {
    width: 32px;
    height: 32px;
  }

  .sync-pill-btn,
  .history-pill-btn {
    padding: 6px 6px;
    font-size: 0.72rem;
    gap: 0.25rem;
  }

  .brand-text h1 {
    font-size: 1.15rem;
  }

  .brand-icon {
    width: 34px;
    height: 34px;
  }

  .step-btn {
    width: 26px;
    height: 34px;
    font-size: 0.82rem;
  }

  .step-input {
    font-size: 1rem;
  }

  .stepper-header label {
    font-size: 0.58rem;
  }

  .unit-badge {
    font-size: 0.55rem;
    padding: 0 2px;
  }

  .result-time-hero {
    font-size: 1.85rem;
  }
}
