* {
  box-sizing: border-box;
}

:root {
  --wall-color-1: #fdf5e6;
  --wall-color-2: #faebd7;
  --floor-color: #6d4c41;
  --rug-color: #8d1d1d;
  --rug-border: #d4af37;
  --ui-bg: rgba(255, 250, 240, 0.95);
  --ui-border: #d7ccc8;
  --accent: #8b0000;
  --tree-green-dark: #1e5028;
  --tree-green-mid: #2e6f40;
  --tree-green-light: #3e8f57;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  font-family: "Lora", serif;
  color: #4a3b32;
}

.room-bg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -2;
  transition: background 0.5s;
}

.room-bg.stripes {
  background: repeating-linear-gradient(
    90deg,
    var(--wall-color-1),
    var(--wall-color-1) 40px,
    var(--wall-color-2) 40px,
    var(--wall-color-2) 80px
  );
}

.room-bg.solid {
  background: var(--wall-color-1);
}

.room-bg.brick {
  background-color: #8b4513;
  background-image:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 30px,
      #654321 30px,
      #654321 35px
    ),
    repeating-linear-gradient(
      90deg,
      #a0522d,
      #a0522d 60px,
      #8b4513 60px,
      #8b4513 65px,
      #cd853f 65px,
      #cd853f 125px,
      #8b4513 125px,
      #8b4513 130px
    );
  background-size: 130px 35px;
}

.room-bg.wood-panel {
  background: linear-gradient(
    90deg,
    #5d4037 0%,
    #6d4c41 10%,
    #5d4037 10%,
    #4e342e 20%,
    #5d4037 20%,
    #6d4c41 30%,
    #5d4037 30%,
    #4e342e 40%,
    #5d4037 40%,
    #6d4c41 50%,
    #5d4037 50%,
    #4e342e 60%,
    #5d4037 60%,
    #6d4c41 70%,
    #5d4037 70%,
    #4e342e 80%,
    #5d4037 80%,
    #6d4c41 90%,
    #5d4037 90%,
    #4e342e 100%
  );
}

.room-bg.cabin {
  background:
    repeating-linear-gradient(
      0deg,
      #3e2723 0px,
      #3e2723 2px,
      transparent 2px,
      transparent 40px
    ),
    linear-gradient(180deg, #4e342e 0%, #3e2723 100%);
}

.room-bg.cozy-dark {
  background: radial-gradient(ellipse at center, #2c1810 0%, #1a0f0a 100%);
}

.room-bg.starry {
  background: linear-gradient(180deg, #0c1445 0%, #1a237e 50%, #283593 100%);
}

.room-bg.starry::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 70%;
  background-image:
    radial-gradient(2px 2px at 20px 30px, white, transparent),
    radial-gradient(
      2px 2px at 40px 70px,
      rgba(255, 255, 255, 0.8),
      transparent
    ),
    radial-gradient(1px 1px at 90px 40px, white, transparent),
    radial-gradient(
      2px 2px at 130px 80px,
      rgba(255, 255, 255, 0.9),
      transparent
    ),
    radial-gradient(1px 1px at 160px 20px, white, transparent),
    radial-gradient(2px 2px at 200px 50px, white, transparent),
    radial-gradient(
      1px 1px at 250px 90px,
      rgba(255, 255, 255, 0.7),
      transparent
    ),
    radial-gradient(2px 2px at 280px 30px, white, transparent),
    radial-gradient(1px 1px at 320px 60px, white, transparent),
    radial-gradient(
      2px 2px at 350px 80px,
      rgba(255, 255, 255, 0.8),
      transparent
    );
  background-size: 400px 100px;
  animation: twinkle 4s infinite alternate;
}

@keyframes twinkle {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

.room-bg.festive {
  background:
    radial-gradient(
      circle at 20% 80%,
      rgba(255, 0, 0, 0.1) 0%,
      transparent 30%
    ),
    radial-gradient(
      circle at 80% 20%,
      rgba(0, 255, 0, 0.1) 0%,
      transparent 30%
    ),
    linear-gradient(135deg, #2d1f1f 0%, #1a1212 100%);
}

.floor {
  position: fixed;
  bottom: 0;
  width: 100%;
  height: 30%;
  background: var(--floor-color);
  border-top: 12px solid #3e2723;
  z-index: -2;
  transition: background 0.5s;
}

.app-container {
  display: flex;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

.sidebar {
  width: 240px;
  background: var(--ui-bg);
  border-right: 2px solid var(--ui-border);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow-y: auto;
  max-height: 100vh;
}

.sidebar h3 {
  margin: 0.25rem 0;
  font-size: 0.85rem;
  color: #666;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.section {
  border: 1px solid var(--ui-border);
  border-radius: 8px;
  overflow: scroll;
}

.section-header {
  background: rgba(255, 255, 255, 0.5);
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 0.9rem;
}

.section-header:hover {
  background: rgba(255, 255, 255, 0.8);
}

.section-content {
  padding: 0.5rem;
  display: none;
}

.section.open .section-content {
  display: block;
}

.section-header::after {
  content: "▼";
  font-size: 0.7rem;
  transition: transform 0.2s;
}

.section.open .section-header::after {
  transform: rotate(180deg);
}

.tree-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.tree-option {
  aspect-ratio: 1;
  border: 2px solid var(--ui-border);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  transition: all 0.2s;
  padding: 4px;
}

.tree-option:hover {
  border-color: var(--accent);
  transform: scale(1.05);
}

.tree-option.selected {
  border-color: var(--accent);
  background: #fff5f5;
  box-shadow: 0 0 8px rgba(139, 0, 0, 0.3);
}

.tree-preview {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.bg-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.bg-option {
  aspect-ratio: 1;
  border: 2px solid var(--ui-border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  overflow: scroll;
}

.bg-option:hover {
  border-color: var(--accent);
  transform: scale(1.1);
}

.bg-option.selected {
  border-color: var(--accent);
  box-shadow: 0 0 8px rgba(139, 0, 0, 0.4);
}

.decoration-palette {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.palette-item {
  aspect-ratio: 1;
  border: 2px solid var(--ui-border);
  border-radius: 6px;
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  background: #fff;
  transition: all 0.2s;
  user-select: none;
}

.palette-item:hover {
  border-color: var(--accent);
  transform: scale(1.1);
}

.palette-item.selected {
  border-color: var(--accent);
  background: #ffe;
  box-shadow: 0 0 6px rgba(139, 0, 0, 0.4);
}

.btn {
  padding: 0.5rem 0.75rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

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

.btn-primary:hover {
  background: #a52a2a;
}

.btn-secondary {
  background: #5d4037;
  color: white;
}

.btn-secondary:hover {
  background: #4e342e;
}

.btn-danger {
  background: #c62828;
  color: white;
}

.btn-success {
  background: #2e7d32;
  color: white;
}

.btn-success:hover {
  background: #1b5e20;
}

.btn-small {
  padding: 0.35rem 0.6rem;
  font-size: 0.75rem;
}

.btn-group {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  position: relative;
}

#header {
  text-align: center;
  background: var(--ui-bg);
  padding: 0.75rem 2rem;
  border-radius: 8px;
  border: 1px solid var(--ui-border);
  margin-bottom: 1rem;
}

#header h1 {
  font-family: "Mountains of Christmas", cursive;
  font-size: 2rem;
  margin: 0;
  color: var(--accent);
}

#header p {
  margin: 0.25rem 0 0 0;
  font-style: italic;
  opacity: 0.8;
  font-size: 0.9rem;
}

#tree-container {
  position: relative;
  width: 420px;
  height: 520px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overflow: scroll;
  border-radius: 12px;
}

.rug {
  position: absolute;
  bottom: 10px;
  width: 320px;
  height: 70px;
  background: var(--rug-color);
  border-radius: 50%;
  border: 4px dashed var(--rug-border);
  z-index: 0;
}

.tree-display {
  position: absolute;
  bottom: 40px;
  z-index: 5;
  filter: drop-shadow(0 15px 15px rgba(0, 0, 0, 0.3));
}

.tree-classic {
  position: relative;
  width: 260px;
  height: 320px;
}

.tree-classic .layer {
  position: absolute;
  width: 0;
  height: 0;
  border-left: solid transparent;
  border-right: solid transparent;
  border-bottom: solid;
  left: 50%;
  transform: translateX(-50%);
}

.tree-classic .l1 {
  border-left-width: 130px;
  border-right-width: 130px;
  border-bottom-width: 160px;
  border-bottom-color: var(--tree-green-dark);
  bottom: 30px;
}
.tree-classic .l2 {
  border-left-width: 110px;
  border-right-width: 110px;
  border-bottom-width: 140px;
  border-bottom-color: var(--tree-green-mid);
  bottom: 130px;
}
.tree-classic .l3 {
  border-left-width: 90px;
  border-right-width: 90px;
  border-bottom-width: 120px;
  border-bottom-color: var(--tree-green-light);
  bottom: 220px;
}
.tree-classic .stump {
  position: absolute;
  width: 50px;
  height: 40px;
  background: #5d4037;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  border-radius: 0 0 5px 5px;
}

.tree-pine {
  position: relative;
  width: 200px;
  height: 340px;
}

.tree-pine .layer {
  position: absolute;
  width: 0;
  height: 0;
  border-left: solid transparent;
  border-right: solid transparent;
  border-bottom: solid;
  left: 50%;
  transform: translateX(-50%);
}

.tree-pine .l1 {
  border-left-width: 100px;
  border-right-width: 100px;
  border-bottom-width: 100px;
  border-bottom-color: var(--tree-green-dark);
  bottom: 30px;
}
.tree-pine .l2 {
  border-left-width: 85px;
  border-right-width: 85px;
  border-bottom-width: 90px;
  border-bottom-color: var(--tree-green-mid);
  bottom: 100px;
}
.tree-pine .l3 {
  border-left-width: 70px;
  border-right-width: 70px;
  border-bottom-width: 80px;
  border-bottom-color: #36804d;
  bottom: 165px;
}
.tree-pine .l4 {
  border-left-width: 55px;
  border-right-width: 55px;
  border-bottom-width: 70px;
  border-bottom-color: var(--tree-green-light);
  bottom: 225px;
}
.tree-pine .l5 {
  border-left-width: 40px;
  border-right-width: 40px;
  border-bottom-width: 60px;
  border-bottom-color: #4caf50;
  bottom: 280px;
}
.tree-pine .stump {
  position: absolute;
  width: 40px;
  height: 35px;
  background: #5d4037;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
}

.tree-bushy {
  position: relative;
  width: 240px;
  height: 320px;
}

.tree-bushy .foliage {
  position: absolute;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  width: 220px;
  height: 280px;
  background: radial-gradient(
    ellipse at 50% 60%,
    var(--tree-green-light) 0%,
    var(--tree-green-mid) 50%,
    var(--tree-green-dark) 100%
  );
  border-radius: 50% 50% 45% 45%;
}

.tree-bushy .stump {
  position: absolute;
  width: 50px;
  height: 40px;
  background: #5d4037;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
}

.tree-slim {
  position: relative;
  width: 140px;
  height: 340px;
}

.tree-slim .layer {
  position: absolute;
  width: 0;
  height: 0;
  border-left: solid transparent;
  border-right: solid transparent;
  border-bottom: solid;
  left: 50%;
  transform: translateX(-50%);
}

.tree-slim .l1 {
  bottom: 30px;
  border-left-width: 70px;
  border-right-width: 70px;
  border-bottom-width: 120px;
  border-bottom-color: var(--tree-green-dark);
}
.tree-slim .l2 {
  bottom: 110px;
  border-left-width: 55px;
  border-right-width: 55px;
  border-bottom-width: 100px;
  border-bottom-color: var(--tree-green-mid);
}
.tree-slim .l3 {
  bottom: 180px;
  border-left-width: 40px;
  border-right-width: 40px;
  border-bottom-width: 80px;
  border-bottom-color: var(--tree-green-light);
}
.tree-slim .l4 {
  bottom: 240px;
  border-left-width: 25px;
  border-right-width: 25px;
  border-bottom-width: 60px;
  border-bottom-color: #4caf50;
}
.tree-slim .stump {
  position: absolute;
  width: 30px;
  height: 35px;
  background: #5d4037;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
}

.tree-potted {
  position: relative;
  width: 220px;
  height: 340px;
}

.tree-potted .layer {
  position: absolute;
  width: 0;
  height: 0;
  border-left: solid transparent;
  border-right: solid transparent;
  border-bottom: solid;
  left: 50%;
  transform: translateX(-50%);
}

.tree-potted .l1 {
  bottom: 70px;
  border-left-width: 100px;
  border-right-width: 100px;
  border-bottom-width: 130px;
  border-bottom-color: var(--tree-green-dark);
}
.tree-potted .l2 {
  bottom: 150px;
  border-left-width: 80px;
  border-right-width: 80px;
  border-bottom-width: 110px;
  border-bottom-color: var(--tree-green-mid);
}
.tree-potted .l3 {
  bottom: 225px;
  border-left-width: 60px;
  border-right-width: 60px;
  border-bottom-width: 90px;
  border-bottom-color: var(--tree-green-light);
}

.tree-potted .pot {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100px;
  height: 70px;
  background: linear-gradient(180deg, #8d6e63 0%, #6d4c41 100%);
  border-radius: 0 0 20px 20px;
  border-top: 8px solid #a1887f;
}

.tree-cartoon {
  position: relative;
  width: 220px;
  height: 320px;
}

.tree-cartoon .cloud {
  position: absolute;
  background: var(--tree-green-mid);
  border-radius: 50%;
}

.tree-cartoon .c1 {
  width: 120px;
  height: 100px;
  bottom: 50px;
  left: 50%;
  transform: translateX(-50%);
}
.tree-cartoon .c2 {
  width: 100px;
  height: 90px;
  bottom: 80px;
  left: 25%;
}
.tree-cartoon .c3 {
  width: 100px;
  height: 90px;
  bottom: 80px;
  right: 25%;
}
.tree-cartoon .c4 {
  width: 90px;
  height: 80px;
  bottom: 140px;
  left: 50%;
  transform: translateX(-50%);
}
.tree-cartoon .c5 {
  width: 70px;
  height: 70px;
  bottom: 130px;
  left: 30%;
}
.tree-cartoon .c6 {
  width: 70px;
  height: 70px;
  bottom: 130px;
  right: 30%;
}
.tree-cartoon .c7 {
  width: 80px;
  height: 70px;
  bottom: 190px;
  left: 50%;
  transform: translateX(-50%);
}
.tree-cartoon .c8 {
  width: 60px;
  height: 60px;
  bottom: 240px;
  left: 50%;
  transform: translateX(-50%);
}
.tree-cartoon .c9 {
  width: 40px;
  height: 50px;
  bottom: 280px;
  left: 50%;
  transform: translateX(-50%);
}

.tree-cartoon .stump {
  position: absolute;
  width: 50px;
  height: 55px;
  background: #6d4c41;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  border-radius: 5px;
}

.placed-decoration {
  position: absolute;
  cursor: move;
  user-select: none;
  z-index: 50;
  transition: filter 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.placed-decoration:hover {
  filter: brightness(1.2);
  z-index: 100;
}

.placed-decoration.selected {
  outline: 3px dashed var(--accent);
  outline-offset: 4px;
}

.placed-decoration .resize-handle {
  position: absolute;
  bottom: -6px;
  right: -6px;
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
  cursor: se-resize;
  display: none;
  border: 2px solid white;
}

.placed-decoration.selected .resize-handle {
  display: block;
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--ui-bg);
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 500px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  position: relative;
}

.modal h2 {
  font-family: "Mountains of Christmas", cursive;
  color: var(--accent);
  margin: 0 0 1rem 0;
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 1rem;
  font-size: 1.5rem;
  cursor: pointer;
  color: #999;
  background: none;
  border: none;
}

.modal-close:hover {
  color: var(--accent);
}

.config-section {
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--ui-border);
}

.config-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.config-section h3 {
  margin: 0 0 0.5rem 0;
  font-size: 0.95rem;
  color: #555;
}

.config-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.6rem;
}

.config-row label {
  font-size: 0.85rem;
}

.config-row input[type="color"] {
  width: 45px;
  height: 28px;
  border: 2px solid var(--ui-border);
  border-radius: 4px;
  cursor: pointer;
}

.config-row input[type="range"] {
  width: 100px;
}

.config-row input[type="text"] {
  width: 140px;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--ui-border);
  border-radius: 4px;
  font-size: 0.85rem;
}

.toggle-switch {
  position: relative;
  width: 46px;
  height: 24px;
}

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

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #ccc;
  border-radius: 24px;
  transition: 0.3s;
}

.toggle-slider:before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.3s;
}

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

.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(22px);
}

.photo-preview {
  background: #fefefe;
  padding: 15px 15px 50px 15px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  margin: 1rem auto;
  max-width: 350px;
  transform: rotate(-1deg);
}

.photo-preview img {
  width: 100%;
  display: block;
}

.photo-text {
  padding-top: 15px;
  text-align: center;
}

.photo-title {
  font-family: "Caveat", cursive;
  font-size: 1.6rem;
  color: #333;
  margin: 0;
}

.photo-desc {
  font-family: "Caveat", cursive;
  font-size: 1.1rem;
  color: #666;
  margin: 5px 0 0 0;
}

.photo-input {
  width: 100%;
  padding: 0.5rem;
  margin-bottom: 0.75rem;
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  font-family: "Caveat", cursive;
  font-size: 1.2rem;
}

.photo-input::placeholder {
  color: #aaa;
}

#footer {
  margin-top: auto;
  padding: 0.75rem;
  text-align: center;
  font-size: 0.75rem;
  color: rgba(80, 60, 50, 0.7);
}

.instructions {
  background: #fffde7;
  border: 1px solid #ffe082;
  border-radius: 6px;
  padding: 0.6rem;
  font-size: 0.75rem;
  line-height: 1.4;
}

.instructions strong {
  color: var(--accent);
}
