/* ============================================
   CSS Custom Properties (Theme)
   ============================================ */
:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --surface-light: #0f3460;
  --primary: #e94560;
  --text: #ffffff;
  --text-secondary: #a0a0b0;
  --text-dark: #333333;
  --flip-bg: #2a2a3e;
  --flip-border: #3a3a4e;
  --danger: #ff4444;
  --overlay: rgba(0, 0, 0, 0.5);
  --sticky-yellow: #FFF9C4;
  --sticky-pink: #F8BBD0;
  --sticky-blue: #B3E5FC;
  --sticky-green: #C8E6C9;
  --sticky-orange: #FFE0B2;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
  position: relative;
}

.hidden { display: none !important; }

/* ============================================
   Header
   ============================================ */
#appHeader {
  display: flex;
  justify-content: flex-end;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  z-index: 100;
  flex-shrink: 0;
}

#settingsBtn {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  transition: background 0.2s;
}

#settingsBtn:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* ============================================
   Clock Area
   ============================================ */
#clockArea {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
  min-height: 140px;
  padding: 8px 16px 16px;
}

/* ---- Digital Clock ---- */
.digital-time {
  display: flex;
  align-items: baseline;
  justify-content: center;
}

.digital-segment {
  font-size: clamp(48px, 12vw, 80px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 2px;
  color: var(--text);
}

.digital-colon {
  font-size: clamp(40px, 10vw, 68px);
  font-weight: 700;
  color: var(--primary);
  margin: 0 2px;
  padding-bottom: 4px;
}

.digital-ampm {
  font-size: clamp(16px, 4vw, 24px);
  font-weight: 700;
  color: var(--text);
  margin-right: 8px;
}

.clock-date {
  text-align: center;
  font-size: clamp(14px, 3.5vw, 20px);
  color: var(--text);
  margin-top: 8px;
}

/* ---- Flip Clock ---- */
#flipClock {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.flip-time-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.flip-group {
  display: flex;
  gap: 3px;
}

.flip-sep {
  font-size: clamp(32px, 8vw, 52px);
  font-weight: 700;
  color: var(--primary);
  margin: 0 2px;
  line-height: 1;
}

.flip-ampm {
  font-size: clamp(14px, 3.5vw, 22px);
  font-weight: 700;
  color: var(--text);
  margin-right: 10px;
  align-self: center;
}

/* ---- Flip Unit (Single Digit) ---- */
.flip-unit {
  position: relative;
  width: clamp(40px, 10vw, 60px);
  height: clamp(56px, 14vw, 84px);
  perspective: 400px;
  border-radius: 8px;
  overflow: visible;
  transform-style: preserve-3d;
}

.flip-half {
  position: absolute;
  left: 0;
  right: 0;
  height: 50%;
  overflow: hidden;
  background: var(--flip-bg);
  display: flex;
  justify-content: center;
}

.flip-half.upper {
  top: 0;
  align-items: flex-end;
  border-radius: 8px 8px 0 0;
  border: 1px solid var(--flip-border);
  border-bottom: none;
}

.flip-half.lower {
  bottom: 0;
  align-items: flex-start;
  border-radius: 0 0 8px 8px;
  border: 1px solid var(--flip-border);
  border-top: none;
}

.flip-num {
  font-size: clamp(32px, 9vw, 52px);
  font-weight: 700;
  color: var(--text);
  line-height: 0;
  position: relative;
}

/* Flap (animated half) */
.flip-flap {
  position: absolute;
  left: 0;
  right: 0;
  height: 50%;
  overflow: hidden;
  background: var(--flip-bg);
  display: flex;
  justify-content: center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  z-index: 5;
}

.flip-flap.upper {
  top: 0;
  align-items: flex-end;
  border-radius: 8px 8px 0 0;
  border: 1px solid var(--flip-border);
  border-bottom: none;
  transform-origin: bottom center;
  transform: rotateX(0deg);
}

.flip-flap.lower {
  bottom: 0;
  align-items: flex-start;
  border-radius: 0 0 8px 8px;
  border: 1px solid var(--flip-border);
  border-top: none;
  transform-origin: top center;
  transform: rotateX(90deg);
}

.flip-flap .flip-num { color: var(--text); }

/* Divider line */
.flip-divider {
  position: absolute;
  top: calc(50% - 1px);
  left: 0;
  right: 0;
  height: 2px;
  background: var(--bg);
  z-index: 10;
}

/* Flip Animations */
@keyframes flipDown {
  from { transform: rotateX(0deg); }
  to   { transform: rotateX(-90deg); }
}

@keyframes flipUp {
  from { transform: rotateX(90deg); }
  to   { transform: rotateX(0deg); }
}

.flip-unit.flipping .flip-flap.upper {
  animation: flipDown 0.3s ease-in forwards;
}

.flip-unit.flipping .flip-flap.lower {
  animation: flipUp 0.3s ease-out 0.3s forwards;
}

/* ============================================
   Sticky Board
   ============================================ */
#stickyBoard {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

/* ============================================
   Sticky Note
   ============================================ */
.sticky-note {
  position: absolute;
  border-radius: 4px;
  padding: 16px 12px 12px;
  cursor: grab;
  touch-action: none;
  box-shadow: 2px 3px 8px rgba(0, 0, 0, 0.2);
  transition: box-shadow 0.2s, transform 0.1s;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.sticky-note.dragging {
  cursor: grabbing;
  box-shadow: 4px 6px 20px rgba(0, 0, 0, 0.35);
  transform: scale(1.04);
  z-index: 9998 !important;
}

.sticky-pin {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ff5252;
  position: absolute;
  top: 5px;
  left: 50%;
  margin-left: -4px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  z-index: 1;
}

.sticky-content {
  color: var(--text-dark);
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  flex: 1;
  overflow: hidden;
  pointer-events: none;
}

/* Resize Handle */
.sticky-resize {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 20px;
  height: 20px;
  cursor: nwse-resize;
  touch-action: none;
}

.sticky-resize::after {
  content: '';
  position: absolute;
  bottom: 3px;
  right: 3px;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 0 10px 10px;
  border-color: transparent transparent rgba(0, 0, 0, 0.15) transparent;
}

/* ============================================
   FAB (Floating Action Button)
   ============================================ */
#addStickyBtn {
  position: fixed;
  bottom: calc(58px + env(safe-area-inset-bottom, 0px));
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  font-size: 28px;
  font-weight: 300;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(233, 69, 96, 0.4);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
}

#addStickyBtn:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 16px rgba(233, 69, 96, 0.5);
}

#addStickyBtn:active {
  transform: scale(0.95);
}

/* ============================================
   Ad Area
   ============================================ */
#adArea {
  height: 90px;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  border-top: 1px solid var(--flip-border);
  flex-shrink: 0;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

#adArea span {
  color: #555;
  font-size: 12px;
}

#adArea.hidden { display: none; }

/* ============================================
   Dialog (Shared)
   ============================================ */
dialog {
  border: none;
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  padding: 0;
  max-width: 420px;
  width: calc(100% - 40px);
  max-height: 85vh;
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.dialog-content {
  display: flex;
  flex-direction: column;
  max-height: 85vh;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--flip-border);
  flex-shrink: 0;
}

.dialog-header h2,
.dialog-title {
  font-size: 18px;
  font-weight: 700;
}

.dialog-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 28px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.dialog-close:hover { color: var(--text); }

.dialog-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

/* ============================================
   Settings
   ============================================ */
.section-title {
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg);
  padding: 14px 16px;
  border-radius: 8px;
  margin-bottom: 8px;
}

.setting-label {
  font-size: 15px;
  color: var(--text);
}

.setting-value {
  font-size: 15px;
  color: var(--text-secondary);
}

/* Segment Control */
.segment-control {
  display: flex;
  background: var(--bg);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--flip-border);
}

.segment-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.segment-btn.active {
  background: var(--primary);
  color: #fff;
}

/* Toggle Switch */
.toggle {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
}

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

.slider {
  position: absolute;
  inset: 0;
  background-color: #555;
  border-radius: 26px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.slider::before {
  content: '';
  position: absolute;
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.3s;
}

.toggle input:checked + .slider { background-color: var(--primary); }
.toggle input:checked + .slider::before { transform: translateX(20px); }

/* Toggle Button */
.toggle-btn {
  background: var(--surface-light);
  border: 1px solid var(--flip-border);
  color: var(--text);
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.toggle-btn:hover { border-color: var(--primary); }

/* Purchase Buttons */
.purchase-btn {
  width: 100%;
  padding: 14px;
  border-radius: 8px;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 10px;
  transition: opacity 0.2s;
}

.purchase-btn:hover { opacity: 0.9; }

.purchase-btn:disabled {
  background: #444;
  cursor: not-allowed;
  opacity: 0.6;
}

.purchase-btn.outline {
  background: transparent;
  border: 1px solid var(--primary);
  color: var(--primary);
}

/* ============================================
   Editor
   ============================================ */
.editor-content .dialog-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#editorText {
  width: 100%;
  min-height: 120px;
  padding: 12px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-family: inherit;
  color: var(--text-dark);
  resize: vertical;
  outline: none;
}

.color-picker {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.color-dot {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.2s;
}

.color-dot:hover { transform: scale(1.15); }
.color-dot.active { border-color: var(--text-dark); }

.delete-btn {
  width: 100%;
  padding: 12px;
  border-radius: 8px;
  border: none;
  background: var(--danger);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.delete-btn:hover { opacity: 0.9; }

/* ============================================
   Responsive
   ============================================ */
@media (min-width: 768px) {
  #clockArea {
    min-height: 200px;
    padding: 20px;
  }

  .sticky-note {
    min-width: 140px;
    min-height: 100px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .flip-unit.flipping .flip-flap.upper,
  .flip-unit.flipping .flip-flap.lower {
    animation: none;
  }

  .sticky-note {
    transition: none;
  }
}

/* Color Inputs */
.color-input {
  -webkit-appearance: none;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  overflow: hidden;
  padding: 0;
  background: transparent;
}
.color-input::-webkit-color-swatch-wrapper {
  padding: 0;
}
.color-input::-webkit-color-swatch {
  border: 2px solid var(--flip-border);
  border-radius: 50%;
}

/* ---- LED Clock ---- */
#ledClock {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.led-time {
  display: flex;
  align-items: baseline;
  justify-content: center;
  font-family: 'Digital-7 Mono', 'Courier New', monospace;
  color: var(--text);
  text-shadow: 0 0 8px var(--text), 0 0 20px var(--text);
}
.led-segment {
  font-size: clamp(64px, 16vw, 120px);
  line-height: 1;
}
.led-colon {
  font-size: clamp(54px, 14vw, 100px);
  margin: 0 4px;
  line-height: 1;
  position: relative;
  top: -6px;
  transition: opacity 0.05s ease;
}
.led-colon.colon-dim {
  opacity: 0;
}
.led-ampm {
  font-size: clamp(20px, 5vw, 36px);
  margin-right: 12px;
}
