/* =====================================================
   TIMEPRO — style.css
   Rainy cafe window — warm, dim, melancholy
   ===================================================== */

/* ---------- Google Fonts ---------- */
@import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&family=Syne:wght@400;600;700;800&display=swap');

/* ---------- CSS Custom Properties ---------- */
:root {
  /* Cafe palette — deep walnut, fog, candlelight */
  --bg:          #18130e;
  --bg-2:        #1f1812;
  --bg-3:        #251e15;
  --surface:     #2e2318;
  --surface-2:   #392b1c;
  --border:      rgba(200,170,120,0.08);
  --border-2:    rgba(200,170,120,0.15);

  --accent:      #c8974a;          /* warm amber candlelight */
  --accent-glow: rgba(200,151,74,0.28);
  --accent-2:    #8fb8a0;          /* misty sage */
  --green:       #8fb8a0;
  --green-glow:  rgba(143,184,160,0.25);
  --amber:       #e8c078;

  --text:        #e8ddd0;
  --text-muted:  #9a8878;
  --text-dim:    #4a3e32;

  --ring-size:   240px;
  --nav-h:       72px;
  --header-h:    60px;

  --font-display: 'Space Mono', monospace;
  --font-ui:      'Syne', sans-serif;

  --radius:      12px;
  --radius-lg:   20px;
  --radius-full: 9999px;

  --transition:  0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --spring:      0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

html {
  height: 100%;
  font-size: 16px;
}

body {
  height: 100%;
  min-height: 100dvh;
  background:
    /* subtle vignette */
    radial-gradient(ellipse at 50% 0%, rgba(80,55,25,0.35) 0%, transparent 70%),
    radial-gradient(ellipse at 20% 100%, rgba(40,30,15,0.5) 0%, transparent 60%),
    /* base cafe brown */
    linear-gradient(160deg, #1c1710 0%, #18130e 45%, #141009 100%);
  color: var(--text);
  font-family: var(--font-ui);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---------- Background Canvas ---------- */
#bgCanvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 1;   /* always visible — ambient rain */
  transition: opacity 1.5s ease;
}
#bgCanvas.active {
  opacity: 1;
}

/* ---------- App Shell ---------- */
#app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
}

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding: 0 20px;
  background: rgba(10,10,15,0.85);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
}
.logo-icon {
  color: var(--accent);
  font-size: 20px;
  line-height: 1;
  filter: drop-shadow(0 0 8px var(--accent-glow));
}
.logo-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.15em;
  color: var(--text);
}

.header-stats {
  display: flex;
  gap: 10px;
}
.stat-chip {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
}
.stat-label {
  font-family: var(--font-display);
  font-size: 8px;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}
.stat-value {
  font-family: var(--font-display);
  font-size: 12px;
  color: var(--accent);
}

/* ---------- Main Content ---------- */
.main-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ---------- Tab System ---------- */
.tab-content {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity var(--transition), transform var(--transition);
  scrollbar-width: none;
}
.tab-content::-webkit-scrollbar { display: none; }
.tab-content.active {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0);
}

/* ---------- Timer Wrapper ---------- */
.timer-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 20px 24px;
  gap: 18px;
  min-height: 100%;
}

/* ---------- Progress Ring ---------- */
.progress-ring-container {
  position: relative;
  width: var(--ring-size);
  height: var(--ring-size);
  flex-shrink: 0;
}

.progress-ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-bg {
  fill: none;
  stroke: var(--surface);
  stroke-width: 6;
}

.ring-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 754;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.5s ease, stroke 0.5s ease;
  filter: drop-shadow(0 0 8px var(--accent-glow));
}

.ring-fill.ring-pom {
  stroke: var(--accent-2);
  filter: drop-shadow(0 0 8px var(--green-glow));
}

.timer-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.timer-display {
  font-family: var(--font-display);
  font-size: clamp(42px, 12vw, 56px);
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1;
  text-shadow: 0 0 40px rgba(200,151,74,0.25);
  transition: color 0.3s ease;
}

.timer-label {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
}

/* ---------- Preset Buttons ---------- */
.preset-row {
  display: flex;
  gap: 10px;
}

.preset-btn {
  flex: 1;
  padding: 9px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-family: var(--font-display);
  font-size: 12px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition), transform 0.1s;
  min-width: 72px;
}
.preset-btn:hover, .preset-btn:active {
  background: var(--surface-2);
  color: var(--accent);
  border-color: var(--accent);
}
.preset-btn:active { transform: scale(0.96); }

/* ---------- Time Input ---------- */
.time-input-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.time-input-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.time-input {
  width: 80px;
  padding: 12px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  -moz-appearance: textfield;
}
.time-input::-webkit-outer-spin-button,
.time-input::-webkit-inner-spin-button { -webkit-appearance: none; }
.time-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.time-input-label {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  font-weight: 600;
}

.time-separator {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
  color: var(--text-dim);
  margin-top: -16px;
}

/* ---------- Controls Row ---------- */
.controls-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  width: 100%;
}

.ctrl-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  transition: transform 0.1s, background var(--transition), box-shadow var(--transition), opacity var(--transition);
  user-select: none;
}
.ctrl-btn:active { transform: scale(0.92); }

.ctrl-primary {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 0 24px var(--accent-glow), 0 4px 16px rgba(0,0,0,0.5);
}
.ctrl-primary:hover {
  box-shadow: 0 0 40px var(--accent-glow), 0 4px 20px rgba(0,0,0,0.6);
}

.ctrl-reset,
.ctrl-log,
.ctrl-skip {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.ctrl-reset:hover,
.ctrl-log:hover,
.ctrl-skip:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border-2);
}

/* ---------- Pomodoro Specific ---------- */
.pom-status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 10px 16px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.pom-state-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.pom-state-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
  animation: pulse-dot 2s ease infinite;
}
.pom-state-badge.break .pom-state-dot {
  background: var(--amber);
  box-shadow: 0 0 8px var(--amber);
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.6; transform: scale(0.85); }
}

.pom-counter {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-display);
}

.pom-dots {
  display: flex;
  gap: 10px;
}
.pom-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  transition: background var(--transition), box-shadow var(--transition);
}
.pom-dot.filled {
  background: var(--green);
  box-shadow: 0 0 8px var(--green-glow);
  border-color: var(--green);
}

/* ---------- Pomodoro Settings ---------- */
.pom-settings {
  display: flex;
  gap: 12px;
  width: 100%;
}

.pom-setting-item {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pom-setting-label {
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
}

.pom-setting-input-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pom-adj-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
  flex-shrink: 0;
}
.pom-adj-btn:hover  { background: var(--accent); border-color: var(--accent); }
.pom-adj-btn:active { transform: scale(0.9); }

.pom-setting-input {
  width: 40px;
  background: none;
  border: none;
  color: var(--text);
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  outline: none;
  -moz-appearance: textfield;
}
.pom-setting-input::-webkit-outer-spin-button,
.pom-setting-input::-webkit-inner-spin-button { -webkit-appearance: none; }

.pom-setting-unit {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
}

/* ---------- Stats Tab ---------- */
.stats-wrapper {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.stats-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}

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

.stats-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color var(--transition);
}
.stats-card:hover { border-color: var(--border-2); }

.stats-card-icon {
  font-size: 22px;
  line-height: 1;
}

.stats-card-value {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.stats-card-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
}

/* ---------- Weekly Chart ---------- */
.weekly-chart {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
}

.weekly-chart-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 16px;
}

.weekly-bars {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 70px;
  margin-bottom: 8px;
}

.weekly-bar-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
}

.weekly-bar {
  width: 100%;
  border-radius: 4px 4px 0 0;
  background: var(--accent);
  opacity: 0.6;
  min-height: 4px;
  transition: height 0.5s cubic-bezier(0.4, 0, 0.2, 1), opacity var(--transition);
}
.weekly-bar.today {
  opacity: 1;
  box-shadow: 0 0 12px var(--accent-glow);
}

.weekly-labels {
  display: flex;
  gap: 8px;
}
.weekly-label {
  flex: 1;
  text-align: center;
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--font-display);
}
.weekly-label.today { color: var(--accent); font-weight: 700; }

/* ---------- Log Section ---------- */
.log-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.log-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.log-clear-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  color: var(--text-muted);
  font-size: 11px;
  padding: 4px 12px;
  cursor: pointer;
  font-family: var(--font-ui);
  transition: border-color var(--transition), color var(--transition);
}
.log-clear-btn:hover {
  border-color: var(--accent-2);
  color: var(--accent-2);
}

.log-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.log-empty {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  padding: 24px 0;
}

.log-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  animation: slideIn 0.3s ease;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.log-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.log-item-duration {
  font-family: var(--font-display);
  font-size: 12px;
  color: var(--accent);
  font-weight: 700;
}
.log-item-time {
  font-size: 10px;
  color: var(--text-dim);
}
.log-item-text {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ---------- Bottom Navigation ---------- */
.bottom-nav {
  display: flex;
  height: var(--nav-h);
  background: rgba(10,10,15,0.92);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  padding: 0 8px;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 8px 0;
  border-radius: var(--radius);
  transition: color var(--transition), background var(--transition);
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.nav-btn:hover {
  color: var(--text-muted);
  background: var(--surface);
}
.nav-btn.active {
  color: var(--accent);
}
.nav-btn.active svg {
  filter: drop-shadow(0 0 6px var(--accent-glow));
}

/* ---------- Log Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  padding: 0 0 env(safe-area-inset-bottom, 0);
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal-card {
  width: 100%;
  max-width: 480px;
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-bottom: none;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 28px 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.modal-overlay.open .modal-card {
  transform: translateY(0);
}

.modal-header { display: flex; flex-direction: column; gap: 4px; }
.modal-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
}
.modal-subtitle {
  font-size: 13px;
  color: var(--text-muted);
}

.modal-duration {
  font-family: var(--font-display);
  font-size: 14px;
  color: var(--accent);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  text-align: center;
  letter-spacing: 0.08em;
}

.modal-textarea {
  width: 100%;
  height: 100px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  padding: 12px 14px;
  resize: none;
  outline: none;
  line-height: 1.6;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.modal-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.modal-textarea::placeholder { color: var(--text-dim); }

.modal-actions {
  display: flex;
  gap: 10px;
}

.modal-btn {
  flex: 1;
  padding: 14px 0;
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: opacity var(--transition), transform 0.1s;
}
.modal-btn:active { transform: scale(0.97); }

.modal-btn-skip {
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.modal-btn-skip:hover { background: var(--surface-2); }

.modal-btn-save {
  background: var(--accent);
  color: #1a1008;
  box-shadow: 0 4px 16px var(--accent-glow);
}
.modal-btn-save:hover { opacity: 0.9; }

/* ---------- Achievement Overlay ---------- */
.achievement-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.achievement-overlay.show {
  pointer-events: all;
  opacity: 1;
}

.achievement-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  animation: achievementPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes achievementPop {
  from { transform: scale(0.5) rotate(-10deg); opacity: 0; }
  to   { transform: scale(1) rotate(0deg); opacity: 1; }
}

.achievement-emoji {
  font-size: 80px;
  line-height: 1;
  filter: drop-shadow(0 0 30px rgba(108,99,255,0.8));
}
.achievement-text {
  font-size: 28px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 0 40px var(--accent);
  letter-spacing: -0.02em;
}

/* ---------- Running State Styles ---------- */
body.timer-running .timer-display {
  text-shadow: 0 0 40px rgba(200,151,74,0.55);
}

/* ---------- Confetti particles (JS-driven) ---------- */
.confetti-particle {
  position: fixed;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  pointer-events: none;
  z-index: 300;
  animation: confettiFall linear forwards;
}
@keyframes confettiFall {
  0%   { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* ---------- Utility ---------- */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* ---------- Responsive Adjustments ---------- */
@media (max-height: 700px) {
  .timer-wrapper { gap: 12px; padding: 14px 20px 18px; }
  :root { --ring-size: 200px; }
  .timer-display { font-size: 38px; }
  .pom-settings { gap: 8px; }
}

@media (min-width: 480px) {
  #app { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}

/* ---------- Scrollbar styling for stats ---------- */
#tab-stats {
  scrollbar-width: thin;
  scrollbar-color: var(--surface-2) transparent;
}
#tab-stats::-webkit-scrollbar { width: 4px; }
#tab-stats::-webkit-scrollbar-track { background: transparent; }
#tab-stats::-webkit-scrollbar-thumb { background: var(--surface-2); border-radius: 4px; }
