:root {
  --lcd-bg: #000000;
  --lcd-digit: #00ffff;
  --frame-color: #1a1a1a;
  --glass-bg: rgba(30, 30, 30, 0.85);
  --text-primary: #fff;
  --accent-color: #00d4ff;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  user-select: none;
}

body {
  font-family: "Inter", sans-serif;
  min-height: 100vh;
  background-color: #000; /* Pure black background base */
  background-size: cover;
  background-position: center center;
  background-attachment: fixed;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  overflow: hidden;
  transition: background-image 0.5s ease;
}

body::before {
  display: none !important; /* Fully remove any darkening overlay */
}

/* Clock Device Container with scaling */
.clock-wrapper {
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  touch-action: none;
  cursor: grab;
}

.clock-wrapper.dragging {
  transition: none !important;
  cursor: grabbing;
}

.clock-device {
  background: var(--frame-color);
  padding: 15px;
  border-radius: 20px;
  box-shadow:
    0 20px 50px rgba(0, 0, 0, 0.5),
    0 4px 10px rgba(0, 0, 0, 0.4),
    inset 0 1px 1px rgba(255, 255, 255, 0.2);
  position: relative;
  display: inline-block;
  transition:
    transform 0.3s ease,
    background 0.3s ease;
  z-index: 10;
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.lcd-screen {
  background-color: var(--lcd-bg);
  border-radius: 12px;
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.2);
  padding: 20px 30px;
  display: grid;
  grid-template-columns: auto auto;
  gap: 40px;
  position: relative;
  overflow: hidden;
  transition: background-color 0.3s ease;
  align-items: center;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.lcd-screen::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.5' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.05'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 2;
}

.font-digital {
  font-family: "Digital-7 Mono", sans-serif;
  color: var(--lcd-digit);
  line-height: 1;
  transition: color 0.3s ease;
  text-shadow: 0 0 10px var(--lcd-digit);
  position: relative;
  z-index: 1;
}

/* Left Section: Time/Date */
.main-display {
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-right: 2px solid rgba(255, 255, 255, 0.1);
  padding-right: 40px;
}

.time-group {
  display: flex;
  align-items: baseline;
  white-space: nowrap;
}

.period-indicator {
  font-size: 2rem;
  margin-right: 15px;
  opacity: 0;
  width: 0;
  overflow: hidden;
  transition:
    width 0.3s,
    opacity 0.3s;
}

.period-indicator.visible {
  opacity: 1;
  width: auto;
  margin-right: 1rem;
}

.main-time,
.seconds-display {
  font-size: 9rem;
  letter-spacing: -4px;
}

.seconds-display {
  margin-left: 2px;
}

.bottom-info {
  display: flex;
  align-items: center;
  gap: 2rem;
  margin-top: 5px;
  padding-left: 5px;
}

.date-text,
.day-text {
  font-size: 2.5rem;
}

/* Right Section: Env/Alarm */
.side-display {
  padding-left: 10px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  justify-content: center;
}

.env-row {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.env-item {
  display: flex;
  align-items: center;
  gap: 15px;
  justify-content: flex-start;
}

.env-value {
  font-size: 3.5rem;
  min-width: 2.2ch;
  text-align: right;
}

.env-unit {
  font-size: 1.2rem;
  opacity: 0.8;
  font-family: "Inter", sans-serif;
  margin-top: 10px;
}

.env-icon-wrapper {
  width: 30px;
  text-align: center;
  font-size: 1.5rem;
  color: var(--lcd-digit);
}

.bg-alarm-info {
  display: flex;
  align-items: center;
  gap: 15px;
  opacity: 0.9;
  margin-top: 10px;
}

.next-alarm-time {
  font-size: 2.5rem;
}

/* FABs */
.fab-btn {
  position: fixed;
  width: 50px;
  height: 50px;
  background: rgba(30, 30, 30, 0.6);
  backdrop-filter: blur(10px);
  color: #fff;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 20px;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: all 0.3s ease;
  z-index: 100;
}

.fab-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: scale(1.1);
}

.fab-settings {
  bottom: 30px;
  right: 30px;
}

.fab-appearance {
  bottom: 30px;
  left: 30px;
}

.fab-wallpaper {
  top: 30px;
  left: 30px;
}

/* Appearance Bar */
.appearance-bar {
  position: fixed;
  bottom: -500px;
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  max-width: 600px;
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  border-radius: 15px;
  padding: 15px 30px;
  display: flex;
  justify-content: space-around;
  align-items: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: bottom 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 90;
}

.appearance-bar.active {
  bottom: 90px;
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 15px;
  padding: 5px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.control-row:last-child {
  border-bottom: none;
}

.preset-colors {
  display: flex;
  gap: 5px;
  flex: 1;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.color-chip {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: transform 0.2s;
}

.color-chip:hover {
  transform: scale(1.2);
  border-color: #fff;
}

.color-control {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.color-label {
  color: #fff;
  font-size: 0.8rem;
}

input[type="color"] {
  width: 35px;
  height: 35px;
  border: none;
  background: none;
  cursor: pointer;
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
  display: flex;
  justify-content: center;
  align-items: center;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.generic-modal {
  background: #222;
  width: 90%;
  max-width: 500px;
  border-radius: 15px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  overflow: hidden;
  transform: scale(0.95);
  transition: transform 0.2s;
  display: flex;
  flex-direction: column;
  max-height: 80vh;
}

.modal-overlay.active .generic-modal {
  transform: scale(1);
}

.modal-header {
  padding: 15px 20px;
  background: rgba(255, 255, 255, 0.05);
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #fff;
  flex-shrink: 0;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
}

.modal-body::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

/* Chrome/Safari */

.wallpaper-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 15px;
  overflow-y: auto;
  max-height: 60vh;
  padding: 10px;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
}

.wallpaper-grid::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

.wallpaper-item {
  aspect-ratio: 16/9;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.2s;
}

.wallpaper-item:hover {
  transform: scale(1.02);
  border-color: #fff;
}

.wallpaper-item.selected {
  border-color: var(--accent-color);
}

.wallpaper-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  color: #ccc;
}

.settings-row:last-child {
  border-bottom: none;
}

input[type="time"] {
  background: #333;
  color: #fff;
  border: 1px solid #444;
  padding: 5px 10px;
  border-radius: 5px;
}

.btn {
  background: var(--accent-color);
  color: #000;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
}

/* --- New UI Controls --- */

/* Apple Style Switch */
.ios-switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
}

.ios-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #555;
  transition: 0.4s;
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 22px;
  width: 22px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.4s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--accent-color);
}

input:checked + .slider:before {
  transform: translateX(22px);
}

/* Segmented Buttons */
.segmented-control {
  display: flex;
  background: rgba(255, 255, 255, 0.1);
  padding: 3px;
  border-radius: 8px;
  gap: 2px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.segment-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: #888;
  padding: 6px 15px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.3s;
  min-width: 40px;
  text-align: center;
}

.segment-btn:hover {
  color: #fff;
}

.segment-btn.active {
  background: var(--accent-color);
  color: #000;
  font-weight: 600;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

/* Responsive Logic */
@media (max-width: 900px) {
  body {
    background-attachment: scroll; /* Fixes zoom/center issues on iOS */
    background-position: center center;
  }
  .lcd-screen {
    grid-template-columns: 1fr;
    gap: 20px;
    padding: 20px;
    text-align: center;
  }

  .main-display {
    border-right: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-right: 0;
    padding-bottom: 20px;
  }

  .time-group {
    justify-content: center;
  }

  .main-time,
  .seconds-display {
    font-size: 5rem;
  }

  .date-text,
  .day-text {
    font-size: 1.5rem;
  }

  .side-display {
    padding-left: 0;
    padding-top: 10px;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-around;
    gap: 20px;
  }

  .env-row {
    flex-direction: row;
    justify-content: center;
  }

  .env-item {
    gap: 5px;
  }

  .env-value {
    font-size: 2rem;
    text-align: left;
  }

  .env-unit {
    font-size: 0.8rem;
    margin-top: 5px;
  }

  .env-icon-wrapper {
    font-size: 1.2rem;
  }

  .next-alarm-time {
    font-size: 1.8rem;
  }

  .bg-alarm-info {
    margin-top: 0;
  }
}

@media (max-width: 600px) {
  .main-time,
  .seconds-display {
    font-size: 15vw;
  }

  .appearance-bar {
    width: 95%;
    padding: 15px;
    flex-wrap: wrap;
    gap: 15px;
  }

  .appearance-bar:not(.active) {
    bottom: -600px !important;
  }

  .wallpaper-grid {
    display: flex !important;
    flex-wrap: wrap !important;
    justify-content: center !important;
    gap: 10px !important;
    padding: 15px 5px !important;
    width: 100% !important;
  }
  
  .wallpaper-item {
    flex: 0 0 calc(50% - 10px) !important;
    width: calc(50% - 10px) !important;
    aspect-ratio: 16/9 !important;
    margin: 0 !important;
    box-sizing: border-box !important;
  }
}

.footer-copyright {
  position: fixed;
  bottom: 10px;
  width: 100%;
  text-align: center;
  color: rgba(255, 255, 255, 0.4);
  font-size: 0.75rem;
  z-index: 5;
  pointer-events: none;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}
