/* ===========================
   Calendar App — style.css
   =========================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Roboto:wght@300;400;500;700&family=Noto+Serif:wght@400;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── CSS Variables ──────────────────────────────────────── */
:root {
  --font: 'Inter', sans-serif;
  /* Calendar-specific vars — JS controls these */
  --cal-font-size: 18px;
  --cal-height: 360px;

  --bg-overlay: rgba(10, 10, 20, 0.72);
  --glass: rgba(255, 255, 255, 0.06);
  --glass-border: rgba(255, 255, 255, 0.12);
  --text-primary: #f0f0f0;
  --text-secondary: rgba(200, 200, 220, 0.65);
  --text-muted: rgba(200, 200, 220, 0.38);
  --accent: #6c8ef5;
  --accent-soft: rgba(108, 142, 245, 0.18);
  --accent-glow: rgba(108, 142, 245, 0.35);
  --today-bg: rgba(108, 142, 245, 0.28);
  --today-ring: #6c8ef5;
  --weekend: #f5856c;
  --holiday-vn: #ff5f5f;
  --holiday-int: #5fb8ff;
  --cell-hover: rgba(255, 255, 255, 0.07);
  --selected-bg: rgba(108, 142, 245, 0.45);
  --selected-ring: #6c8ef5;
  --in-range-bg: rgba(108, 142, 245, 0.12);
  --header-bg: rgba(0, 0, 0, 0.35);
  --panel-bg: rgba(10, 12, 24, 0.88);
  --panel-border: rgba(255, 255, 255, 0.1);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  --radius: 14px;
  --radius-sm: 8px;
  --radius-xs: 5px;
  --radius-cell: 8px;
}

/* Theme Presets */
body.theme-light {
  --bg-overlay: rgba(240, 242, 255, 0.88);
  --glass: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(0, 0, 0, 0.08);
  --text-primary: #1a1a2e;
  --text-secondary: rgba(30, 30, 60, 0.65);
  --text-muted: rgba(30, 30, 60, 0.38);
  --accent: #4a6cf7;
  --accent-soft: rgba(74, 108, 247, 0.12);
  --today-bg: rgba(74, 108, 247, 0.15);
  --today-ring: #4a6cf7;
  --selected-bg: rgba(74, 108, 247, 0.35);
  --selected-ring: #4a6cf7;
  --in-range-bg: rgba(74, 108, 247, 0.1);
  --cell-hover: rgba(0, 0, 0, 0.04);
  --header-bg: rgba(255, 255, 255, 0.75);
  --panel-bg: rgba(245, 247, 255, 0.95);
  --panel-border: rgba(0, 0, 0, 0.1);
  --shadow: 0 8px 32px rgba(60, 60, 120, 0.15);
}

body.theme-midnight {
  --bg-overlay: rgba(5, 5, 18, 0.82);
  --accent: #8b5cf6;
  --accent-soft: rgba(139, 92, 246, 0.18);
  --today-bg: rgba(139, 92, 246, 0.28);
  --today-ring: #8b5cf6;
  --selected-bg: rgba(139, 92, 246, 0.42);
  --selected-ring: #8b5cf6;
  --in-range-bg: rgba(139, 92, 246, 0.12);
  --glass: rgba(255, 255, 255, 0.04);
}

body.theme-sakura {
  --bg-overlay: rgba(255, 235, 245, 0.86);
  --glass: rgba(255, 230, 250, 0.7);
  --glass-border: rgba(220, 100, 160, 0.15);
  --text-primary: #3a1a2e;
  --text-secondary: rgba(80, 30, 60, 0.65);
  --text-muted: rgba(80, 30, 60, 0.38);
  --accent: #e05588;
  --accent-soft: rgba(224, 85, 136, 0.15);
  --today-bg: rgba(224, 85, 136, 0.18);
  --today-ring: #e05588;
  --selected-bg: rgba(224, 85, 136, 0.38);
  --selected-ring: #e05588;
  --in-range-bg: rgba(224, 85, 136, 0.1);
  --weekend: #c0392b;
  --cell-hover: rgba(224, 85, 136, 0.07);
  --header-bg: rgba(255, 220, 240, 0.85);
  --panel-bg: rgba(255, 245, 252, 0.96);
  --panel-border: rgba(220, 100, 160, 0.2);
}

body.theme-forest {
  --bg-overlay: rgba(10, 25, 15, 0.82);
  --accent: #4ade80;
  --accent-soft: rgba(74, 222, 128, 0.15);
  --today-bg: rgba(74, 222, 128, 0.22);
  --today-ring: #4ade80;
  --selected-bg: rgba(74, 222, 128, 0.38);
  --selected-ring: #4ade80;
  --in-range-bg: rgba(74, 222, 128, 0.1);
  --glass: rgba(255, 255, 255, 0.04);
  --weekend: #fb923c;
}

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

html {
  /* Fixed UI font — slider changes --cal-font-size instead */
  font-size: 15px;
  /* REQUIRED: without this, height:100% on body/children can't resolve against viewport */
  width: 100%;
  height: 100%;
}

body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  font-size: 1rem;
  color: var(--text-primary);
  transition: color 0.4s ease;
}

/* ── Background Layers ───────────────────────────────────── */
#bg-image {
  position: fixed;
  inset: 0;
  z-index: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  transition: filter 0.5s ease;
}

#bg-color {
  position: fixed;
  inset: 0;
  z-index: 1;
  transition: background 0.4s ease;
}

#bg-overlay-layer {
  position: fixed;
  inset: 0;
  z-index: 2;
  transition: background 0.4s ease;
}

/* ── App Shell ──────────────────────────────────────────── */
#app {
  position: relative;
  z-index: 10;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ─────────────────────────────────────────────── */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--header-bg);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--glass-border);
  gap: 12px;
  flex-shrink: 0;
  transition: background 0.4s;
}

#nav-area {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  background: var(--glass);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 1.1rem;
  transition: all 0.2s;
}

.nav-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  transform: scale(1.07);
}

#today-btn {
  padding: 6px 14px;
  width: auto;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.5px;
}

#month-label {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.3px;
  min-width: 160px;
  text-align: center;
  color: var(--text-primary);
}

#clock-display {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.35rem;
  font-weight: 500;
  letter-spacing: 2px;
  color: var(--text-primary);
  opacity: 0.9;
}

#header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

#settings-toggle {
  width: 34px;
  height: 34px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  background: var(--glass);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: all 0.2s;
}

#settings-toggle:hover,
#settings-toggle.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Duration Bar — floating pill, no layout impact ─────── */
#duration-bar {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  opacity: 0;
  pointer-events: none;
  z-index: 60;

  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 22px;
  background: var(--glass);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: 40px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);

  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  letter-spacing: 0.2px;

  transition: opacity 0.25s ease, transform 0.25s ease;
}

#duration-bar.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

/* ── Main Content ────────────────────────────────────────── */
#main {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* ── Calendar Area ───────────────────────────────────────── */
#calendar-wrapper {
  flex: 1;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  /* vertical center — cross-axis in row direction */
  justify-content: center;
  /* horizontal center — main-axis */
  padding: 20px 24px;
  gap: 16px;
  overflow: auto;
}

.month-block {
  /* Use clamp width so it fills up to 520px in a row-direction flex */
  width: clamp(280px, 100%, 520px);
  flex-shrink: 0;
  height: var(--cal-height, 360px);
  min-height: 220px;
  max-height: 90vh;
  /* Calendar font — slider only changes this, not the UI font */
  font-size: var(--cal-font-size, 18px);
  display: flex;
  flex-direction: column;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  backdrop-filter: blur(16px);
  overflow: hidden;
  box-shadow: var(--shadow);
  animation: fadeSlideIn 0.35s ease;
}

@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ── Month Header ────────────────────────────────────────── */
.month-header {
  padding: 8px 14px 6px;
  text-align: center;
  font-size: 0.85em;
  /* em = relative to month-block cal-font-size */
  font-weight: 700;
  letter-spacing: -0.2px;
  color: var(--accent);
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
}

/* ── Weekday Row ─────────────────────────────────────────── */
.weekday-row {
  display: grid;
  grid-template-columns: 24px repeat(7, 1fr);
  padding: 2px 6px;
  gap: 2px;
  flex-shrink: 0;
}

.weekday-cell {
  text-align: center;
  font-size: 0.7em;
  /* em scales with --cal-font-size on .month-block */
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 3px 0;
  color: var(--text-secondary);
}

.weekday-cell.weekend-label {
  color: var(--weekend);
  opacity: 0.85;
}

.weekday-cell.week-num-label {
  color: var(--text-muted);
  font-size: 0.62em;
}

/* ── Days Grid ───────────────────────────────────────────── */
.days-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 24px repeat(7, 1fr);
  grid-auto-rows: 1fr;
  gap: 1px;
  padding: 2px 6px 5px;
  overflow: hidden;
  min-height: 0;
}

/* ── Day Cell ─────────────────────────────────────────────── */
.day-cell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0px;
  padding: 1px;
  border-radius: var(--radius-cell);
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
  min-height: 0;
  user-select: none;
}

/* Hover: no scale transform — it caused an inner circle visual artifact */
.day-cell:hover {
  background: var(--cell-hover);
  box-shadow: inset 0 0 0 1px var(--glass-border);
}

.day-cell.empty {
  cursor: default;
  pointer-events: none;
}

/* Today */
.day-cell.today {
  background: var(--today-bg);
  box-shadow: inset 0 0 0 1.5px var(--today-ring), 0 0 10px var(--accent-glow);
}

/* Selected */
.day-cell.selected {
  background: var(--selected-bg) !important;
  box-shadow: inset 0 0 0 2px var(--selected-ring), 0 0 14px var(--accent-glow) !important;
}

.day-cell.selected .day-number {
  color: white !important;
  font-weight: 800 !important;
}

/* In range */
.day-cell.in-range {
  background: var(--in-range-bg);
  border-radius: 0;
}

.day-cell.in-range.today {
  border-radius: var(--radius-cell);
}

.day-cell.weekend .day-number {
  color: var(--weekend);
}

.day-cell.holiday-vn .day-number {
  color: var(--holiday-vn);
  font-weight: 700;
}

.day-cell.holiday-int .day-number {
  color: var(--holiday-int);
}

.day-number {
  font-size: 1.05em;
  /* em = scales with .month-block's --cal-font-size */
  font-weight: 600;
  line-height: 1;
  color: var(--text-primary);
}

.day-cell.today .day-number {
  color: var(--accent);
  font-weight: 700;
}

.day-lunar {
  font-size: 0.68em;
  color: var(--text-muted);
  line-height: 1;
  text-align: center;
}

.day-cell.lunar-special .day-lunar {
  color: var(--accent);
  font-weight: 600;
  opacity: 0.9;
}

.day-holiday-badge {
  font-size: 0.62em;
  line-height: 1;
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--holiday-vn);
  opacity: 0.9;
}

.week-num-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6em;
  color: var(--text-muted);
  font-weight: 500;
  cursor: default;
}

/* ── Settings Panel ──────────────────────────────────────── */
#settings-panel {
  width: 0;
  overflow: hidden;
  background: var(--panel-bg);
  border-left: 1px solid var(--panel-border);
  backdrop-filter: blur(24px);
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

#settings-panel.open {
  width: 300px;
}

#settings-inner {
  width: 300px;
  height: 100%;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scrollbar-width: thin;
  scrollbar-color: var(--glass-border) transparent;
}

#settings-inner::-webkit-scrollbar {
  width: 5px;
}

#settings-inner::-webkit-scrollbar-thumb {
  background: var(--glass-border);
  border-radius: 3px;
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-title {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--accent);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--glass-border);
}

.ctrl-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.ctrl-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  flex: 1;
}

/* Toggle switch */
.toggle {
  position: relative;
  width: 38px;
  height: 20px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--glass-border);
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.25s;
}

.toggle input:checked+.toggle-track {
  background: var(--accent);
}

.toggle-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: white;
  transition: transform 0.25s;
}

.toggle input:checked+.toggle-track::after {
  transform: translateX(18px);
}

/* Segmented control */
.seg-ctrl {
  display: flex;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.seg-btn {
  flex: 1;
  padding: 5px 8px;
  font-size: 0.78rem;
  font-weight: 500;
  text-align: center;
  cursor: pointer;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  transition: all 0.2s;
}

.seg-btn.active {
  background: var(--accent);
  color: white;
  font-weight: 600;
}

/* Slider */
input[type=range] {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 4px;
  background: var(--glass-border);
  outline: none;
  cursor: pointer;
}

input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent-glow);
  cursor: pointer;
  transition: transform 0.15s;
}

input[type=range]::-webkit-slider-thumb:hover {
  transform: scale(1.25);
}

/* Color picker */
input[type=color] {
  -webkit-appearance: none;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 2px solid var(--glass-border);
  border-radius: var(--radius-xs);
  cursor: pointer;
  background: none;
}

input[type=color]::-webkit-color-swatch-wrapper {
  padding: 0;
}

input[type=color]::-webkit-color-swatch {
  border: none;
  border-radius: 4px;
}

/* Select */
select {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.78rem;
  padding: 5px 8px;
  cursor: pointer;
  outline: none;
  width: 100%;
}

select option {
  background: #1a1a2e;
  color: #f0f0f0;
}

/* Theme presets */
.theme-presets {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
}

.theme-preset-btn {
  padding: 5px 2px;
  font-size: 0.62rem;
  font-weight: 600;
  text-align: center;
  border-radius: var(--radius-sm);
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: all 0.2s;
}

.theme-preset-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.theme-preset-btn.active {
  border-color: var(--accent) !important;
}

.tp-dark {
  background: #0a0a14;
  color: #f0f0f0;
  border-color: #333;
}

.tp-light {
  background: #f0f2ff;
  color: #1a1a2e;
  border-color: #dde;
}

.tp-mid {
  background: #0d0520;
  color: #c4b5fd;
  border-color: #4c1d95;
}

.tp-sakura {
  background: #fff0f8;
  color: #7a1a4a;
  border-color: #f9a8d4;
}

.tp-forest {
  background: #0a1a0e;
  color: #4ade80;
  border-color: #1a4a1e;
}

/* Background source tabs */
.bg-tabs {
  display: flex;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
}

.bg-tab {
  flex: 1;
  padding: 6px 3px;
  font-size: 0.7rem;
  text-align: center;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  transition: all 0.2s;
  font-weight: 500;
}

.bg-tab.active {
  background: var(--accent);
  color: white;
  font-weight: 600;
}

.bg-section {
  display: none;
  flex-direction: column;
  gap: 10px;
}

.bg-section.active {
  display: flex;
}

/* Buttons */
.btn {
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--text-primary);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
  width: 100%;
}

.btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-accent {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.btn-accent:hover {
  opacity: 0.85;
  color: white;
}

/* Input fields */
input[type=url],
input[type=text] {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.78rem;
  padding: 7px 10px;
  outline: none;
  width: 100%;
  transition: border-color 0.2s;
}

input[type=url]:focus,
input[type=text]:focus {
  border-color: var(--accent);
}

input[type=url]::placeholder,
input[type=text]::placeholder {
  color: var(--text-muted);
}

.hint {
  font-size: 0.68rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--glass-border);
  border-radius: 3px;
}