/* ============================================
   Zen Zone — Style Sheet
   Flat paper-cutout aesthetic with soft depth
   ============================================ */

/* --- Registered Custom Properties (enables transitions) --- */
@property --sky-top { syntax: '<color>'; inherits: true; initial-value: #87ACBF; }
@property --sky-mid { syntax: '<color>'; inherits: true; initial-value: #B4CFD8; }
@property --sky-bottom { syntax: '<color>'; inherits: true; initial-value: #D4DFC7; }
@property --hill-distant { syntax: '<color>'; inherits: true; initial-value: #B8C9A3; }
@property --hill-mid { syntax: '<color>'; inherits: true; initial-value: #8FA872; }
@property --hill-fore { syntax: '<color>'; inherits: true; initial-value: #6B8C42; }
@property --leaf-1 { syntax: '<color>'; inherits: true; initial-value: #7CA65A; }
@property --leaf-2 { syntax: '<color>'; inherits: true; initial-value: #9AB87A; }
@property --leaf-3 { syntax: '<color>'; inherits: true; initial-value: #5E8C3A; }
@property --sun-color { syntax: '<color>'; inherits: true; initial-value: #F4D35E; }
@property --sun-glow { syntax: '<color>'; inherits: true; initial-value: rgba(244,211,94,0.4); }

/* --- Constants --- */
:root {
  --paper-bg: #FAF6F0;
  --paper-border: #E0D8CC;
  --text: #4A4238;
  --text-muted: #8A8070;
  --trunk-color: #7A6352;
  --trunk-shadow: #5E4A3A;
}

/* --- Day Palette --- */
body[data-period="day"] {
  --sky-top: #87ACBF;
  --sky-mid: #B4CFD8;
  --sky-bottom: #D4DFC7;
  --hill-distant: #B8C9A3;
  --hill-mid: #8FA872;
  --hill-fore: #6B8C42;
  --leaf-1: #7CA65A;
  --leaf-2: #9AB87A;
  --leaf-3: #5E8C3A;
  --sun-color: #F4D35E;
  --sun-glow: rgba(244, 211, 94, 0.4);
  --window-glow: rgba(220, 200, 160, 0.3);
  --star-opacity: 0;
  --weather-color: rgba(180, 200, 220, 0.6);
}

/* --- Dawn Palette --- */
body[data-period="dawn"] {
  --sky-top: #C9B8D4;
  --sky-mid: #E8A87C;
  --sky-bottom: #D4C5A5;
  --hill-distant: #C4B89A;
  --hill-mid: #9AAA7A;
  --hill-fore: #7A9455;
  --leaf-1: #8AAA62;
  --leaf-2: #A4BC82;
  --leaf-3: #6A9044;
  --sun-color: #F0C040;
  --sun-glow: rgba(240, 192, 64, 0.5);
  --window-glow: rgba(230, 190, 100, 0.5);
  --star-opacity: 0;
  --weather-color: rgba(200, 190, 170, 0.5);
}

/* --- Dusk Palette --- */
body[data-period="dusk"] {
  --sky-top: #8B6B8A;
  --sky-mid: #C97B63;
  --sky-bottom: #5B4E6D;
  --hill-distant: #7A7068;
  --hill-mid: #6A7A52;
  --hill-fore: #506A3A;
  --leaf-1: #5A7A3A;
  --leaf-2: #7A9458;
  --leaf-3: #4A6A2E;
  --sun-color: #E8A050;
  --sun-glow: rgba(232, 160, 80, 0.5);
  --window-glow: rgba(240, 180, 80, 0.7);
  --star-opacity: 0.3;
  --weather-color: rgba(140, 120, 140, 0.5);
}

/* --- Night Palette --- */
body[data-period="night"] {
  --sky-top: #1B1B3A;
  --sky-mid: #2E2E5E;
  --sky-bottom: #3D2C5E;
  --hill-distant: #3A3650;
  --hill-mid: #2E3A28;
  --hill-fore: #1E2A18;
  --leaf-1: #2A3A20;
  --leaf-2: #3A4A30;
  --leaf-3: #1E2E16;
  --sun-color: #E8E8D0;
  --sun-glow: rgba(232, 232, 208, 0.2);
  --window-glow: rgba(255, 200, 80, 0.9);
  --star-opacity: 1;
  --weather-color: rgba(200, 210, 240, 0.4);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #111;
  transition:
    --sky-top 3s ease,
    --sky-mid 3s ease,
    --sky-bottom 3s ease,
    --hill-distant 3s ease,
    --hill-mid 3s ease,
    --hill-fore 3s ease,
    --leaf-1 3s ease,
    --leaf-2 3s ease,
    --leaf-3 3s ease,
    --sun-color 3s ease,
    --sun-glow 3s ease;
}

/* --- Scene Container --- */
#scene {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* --- Sky --- */
#sky {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to bottom,
    var(--sky-top) 0%,
    var(--sky-mid) 50%,
    var(--sky-bottom) 100%
  );
  transition: background 3s ease;
}

/* --- Sun / Moon --- */
#sun-moon {
  position: absolute;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--sun-color);
  box-shadow: 0 0 40px var(--sun-glow), 0 0 80px var(--sun-glow);
  transition:
    left 60s linear,
    bottom 60s linear,
    background 3s ease,
    box-shadow 3s ease;
  z-index: 1;
  pointer-events: none;
}

/* --- Stars --- */
#stars-container {
  position: absolute;
  inset: 0;
  opacity: var(--star-opacity);
  transition: opacity 3s ease;
  pointer-events: none;
}

.star {
  position: absolute;
  width: 2px;
  height: 2px;
  background: #fff;
  border-radius: 50%;
  opacity: 0.8;
}

.star.bright {
  width: 3px;
  height: 3px;
  box-shadow: 0 0 4px rgba(255, 255, 255, 0.5);
  opacity: 1;
}

.star.twinkle {
  animation: twinkle 3s ease-in-out infinite alternate;
}

@keyframes twinkle {
  0% { opacity: 0.4; }
  100% { opacity: 1; }
}

/* --- Weather Overlay --- */
#weather-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 2;
}

.raindrop {
  position: absolute;
  width: 1.5px;
  background: var(--weather-color);
  border-radius: 0 0 2px 2px;
  animation: rainFall linear infinite;
}

@keyframes rainFall {
  0% { transform: translateY(-20px); }
  100% { transform: translateY(110vh); }
}

.snowflake {
  position: absolute;
  width: 4px;
  height: 4px;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  animation: snowFall linear infinite;
}

@keyframes snowFall {
  0% { transform: translateY(-10px) translateX(0); }
  25% { transform: translateY(27vh) translateX(10px); }
  50% { transform: translateY(55vh) translateX(-5px); }
  75% { transform: translateY(82vh) translateX(8px); }
  100% { transform: translateY(110vh) translateX(0); }
}

.fog-layer {
  position: absolute;
  width: 120%;
  height: 30%;
  background: linear-gradient(
    transparent 0%,
    rgba(200, 200, 210, 0.15) 40%,
    rgba(200, 200, 210, 0.15) 60%,
    transparent 100%
  );
  animation: fogDrift ease-in-out infinite alternate;
}

@keyframes fogDrift {
  0% { transform: translateX(-10%); }
  100% { transform: translateX(5%); }
}

/* --- Landscape SVG --- */
#landscape {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 3;
}

/* Hill fills use CSS custom properties via inline style */
.hill-path {
  transition: fill 3s ease;
}

/* --- Village House --- */
.house-wall {
  transition: fill 3s ease;
}

.house-roof {
  transition: fill 3s ease;
}

.house-chimney {
  transition: fill 3s ease;
}

.house-window {
  transition: fill 3s ease;
}

.house-window-glow {
  animation: windowGlow 4s ease-in-out infinite alternate;
  transition: opacity 3s ease;
}

body[data-period="day"] .house-window-glow { opacity: 0.15; }
body[data-period="dawn"] .house-window-glow { opacity: 0.4; }
body[data-period="dusk"] .house-window-glow { opacity: 0.7; }
body[data-period="night"] .house-window-glow { opacity: 1; }

@keyframes windowGlow {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

/* --- Trees --- */
#trees-container g {
  transition: transform 2s ease-in-out;
}

.tree-trunk {
  fill: var(--trunk-color);
  transition: fill 3s ease;
}

.tree-branch {
  stroke: var(--trunk-color);
  stroke-linecap: round;
  transition: stroke 3s ease, opacity 1.5s ease-in;
}

.tree-leaf {
  transition: fill 3s ease, opacity 1.5s ease-in;
}

.tree-leaf[data-shade="0"] { fill: var(--leaf-1); }
.tree-leaf[data-shade="1"] { fill: var(--leaf-2); }
.tree-leaf[data-shade="2"] { fill: var(--leaf-3); }

.tree-element-new {
  opacity: 0;
}

/* --- Timer Panel --- */
#timer-panel {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 100;
  background: rgba(250, 246, 240, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(224, 216, 204, 0.6);
  border-radius: 12px;
  padding: 14px 20px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  box-shadow:
    0 2px 4px rgba(0,0,0,0.06),
    0 4px 12px rgba(0,0,0,0.04);
  user-select: none;
}

#timer-total {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.3px;
}

#timer-display {
  font-size: 28px;
  font-weight: 300;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
  line-height: 1.2;
}

#timer-btn {
  margin-top: 4px;
  padding: 5px 18px;
  border: 1px solid var(--paper-border);
  border-radius: 6px;
  background: var(--paper-bg);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  letter-spacing: 0.5px;
}

#timer-btn:hover {
  background: #F0EBE3;
  border-color: #C8BFB2;
}

#timer-btn.active {
  background: #E8635A;
  color: #fff;
  border-color: #D04F47;
}

#timer-btn.active:hover {
  background: #D04F47;
}

/* --- Config Button --- */
#config-btn {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid rgba(224, 216, 204, 0.6);
  background: rgba(250, 246, 240, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

#config-btn:hover {
  background: rgba(250, 246, 240, 0.9);
  color: var(--text);
}

#config-btn.error::after {
  content: '';
  position: absolute;
  top: 4px;
  right: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #E8635A;
}

/* --- Config Modal --- */
#config-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(30, 28, 24, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
}

#config-modal.visible {
  display: flex;
}

.modal-content {
  background: var(--paper-bg);
  border-radius: 12px;
  padding: 28px 32px;
  width: 380px;
  max-width: 90vw;
  box-shadow:
    0 2px 4px rgba(0,0,0,0.08),
    0 6px 16px rgba(0,0,0,0.06),
    0 12px 32px rgba(0,0,0,0.04);
}

.modal-content h2 {
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 20px;
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
  letter-spacing: 0.3px;
}

.form-group input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--paper-border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus {
  border-color: #A0B8A0;
}

.form-divider {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  margin: 10px 0;
  position: relative;
}

.form-divider::before,
.form-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 30%;
  height: 1px;
  background: var(--paper-border);
}

.form-divider::before { left: 0; }
.form-divider::after { right: 0; }

.form-row {
  display: flex;
  gap: 12px;
}

.form-row .form-group {
  flex: 1;
}

.form-error {
  font-size: 12px;
  color: #C85A52;
  min-height: 18px;
  margin-bottom: 8px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.btn-primary,
.btn-secondary {
  padding: 7px 18px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  border: 1px solid var(--paper-border);
  transition: background 0.2s;
}

.btn-secondary {
  background: transparent;
  color: var(--text-muted);
}

.btn-secondary:hover {
  background: #F0EBE3;
}

.btn-primary {
  background: #6B8C42;
  color: #fff;
  border-color: #5A7A38;
}

.btn-primary:hover {
  background: #5A7A38;
}

/* --- Responsive --- */
@media (max-width: 600px) {
  #timer-panel {
    bottom: 12px;
    left: 12px;
    padding: 10px 14px;
  }

  #timer-display {
    font-size: 22px;
  }

  .modal-content {
    padding: 20px 22px;
  }

  #sun-moon {
    width: 36px;
    height: 36px;
  }
}
