/* Global box sizing to prevent overflow from padding/borders */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  --header-height: 80px; /* Approximate height of the header bar */
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  margin: 0;
  /* Remove padding from body to allow cards to go to edges if desired */
  /* padding: 20px; */
}

.app { 
  width: 100vw; /* Occupy full viewport width */
  height: calc(100vh - var(--header-height, 0px)); /* Occupy full viewport height minus header */
  position: relative; /* Container for absolutely positioned cards */
  overflow: hidden; /* Hide anything dragging outside of app bounds if needed */
}

.header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  width: 100%;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.header-bar h1 {
  margin: 0;
  font-size: clamp(1.5rem, 3vw, 2.2rem);
  font-weight: 700;
  color: white;
}

.cards-toolbar {
  position: static; /* Remove absolute positioning */
  top: auto;
  right: auto;
  z-index: auto;
  margin-bottom: 0; /* No margin as it's now part of flex layout */
  display: block; /* Ensure button inside behaves normally */
}
.add-card-btn {
  padding: 10px 14px;
  background: #ffffff;
  color: #4a56e2;
  border: 2px solid rgba(255,255,255,0.7);
  border-radius: 10px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .2s ease, background .2s ease;
}
.add-card-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(0,0,0,.12); background: #f8f7ff; }

.cards-grid {
  /* Remove grid layout */
  /* display: grid; */
  /* grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); */
  /* gap: 16px; */
  /* perspective: 1000px; */
  position: relative; /* This might not be strictly needed as cards are absolute to .app, but good practice */
  width: 100%;
  height: 100%;
}

/* Card base and flip */
.card {
  position: absolute; /* Allow free positioning */
  width: clamp(320px, 90vw, 420px);
  min-height: 380px; /* Minimum height for usability */
  max-height: clamp(450px, 85vh, 600px); /* Maximum height to prevent overflow */
  height: auto; /* Let content determine height */
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.4,0.2,0.2,1);
  will-change: transform, left, top; /* Add left, top to will-change for smooth dragging */
  cursor: grab; /* Indicate draggable */
}
.card.flipped { transform: rotateY(180deg); }

.card-side {
  position: absolute; 
  top: 0; left: 0; right: 0;
  width: 100%; 
  /* min-height: 100%; Ensure it fills the card */
  backface-visibility: hidden;
  border-radius: 20px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
  background: white;
  overflow: hidden;
  display: flex; 
  flex-direction: column;
}

.settings-side { transform: rotateY(0deg); }
.display-side { 
  transform: rotateY(180deg); 
  padding: 0 0 12px 0; /* Remove horizontal padding from display-side */
}

/* Headers */
.settings-header, .display-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 18px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  flex-shrink: 0; /* Prevent header from shrinking */
}
.settings-header h2, .display-header h2 {
  margin: 0; font-size: clamp(1rem, 2.4vw, 1.2rem); font-weight: 600;
}

/* Editable title input in settings header */
.card-title-input {
  background: none;
  border: none;
  color: white;
  font-size: clamp(1rem, 2.4vw, 1.2rem);
  font-weight: 600;
  font-family: inherit;
  flex: 1;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background-color 0.2s ease;
}

.card-title-input:focus {
  outline: none;
  background-color: rgba(255, 255, 255, 0.15);
}

.card-title-input::placeholder {
  color: rgba(255, 255, 255, 0.7);
}
.settings-toggle { background: none; border: none; color: white; cursor: pointer; padding: 6px; border-radius: 8px; }
.settings-toggle:hover { background-color: rgba(255,255,255,0.18); }

/* Content areas */
.settings-content { 
  flex: 1; 
  padding: 16px 16px 20px; 
  /* Remove fixed height and scrolling to allow natural expansion */
}

/* time-status element removed from HTML */

.input-group { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.input-group label { font-weight: 600; color: #333; font-size: 0.9em; }

.text-input, .datetime-input {
  padding: 12px; border: 2px solid #e1e5e9; border-radius: 10px; font-size: 14px; width: 100%;
}
.text-input:focus, .datetime-input:focus { outline: none; border-color: #667eea; }

/* Label tools row */
.label-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.label-row .tools { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.icon-group { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.icon-btn { width: 34px; height: 34px; border-radius: 8px; border: 2px solid #e1e5e9; background: #fff; cursor: pointer; display: grid; place-items: center; transition: transform .1s ease, border-color .2s ease, box-shadow .2s ease; }
.icon-btn:hover { transform: translateY(-1px); }
.icon-btn.active { border-color: #667eea; box-shadow: 0 2px 6px rgba(102,126,234,.3); }

.font-select { height: 40px; border: 2px solid #e1e5e9; border-radius: 10px; background: #fff; font-size: 14px; padding: 0 10px; }

.icon-swatch, .icon-swatch.current { width: 28px; height: 28px; border-radius: 8px; border: 2px solid #e1e5e9; background: var(--swatch, #444); cursor: pointer; }
.hidden-color { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.save-btn { padding: 12px 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; border: none; border-radius: 10px; font-size: 15px; font-weight: 600; cursor: pointer; }
.clear-btn { margin-top: 10px; padding: 10px 16px; background: #f44336; color: white; border: none; border-radius: 8px; font-size: 14px; font-weight: 500; cursor: pointer; }
.clear-btn:hover { background: #c62828; }

/* Display side - status text element removed from HTML */
.prefix-text { 
  text-align: center; 
  font-size: 1.05em; 
  color: #444; 
  margin: 0 16px 8px 16px; /* Add horizontal margin for spacing */
  min-height: 0; /* Remove min-height to prevent unnecessary space when empty */
  font-weight: 500; 
  word-break: break-word; 
}
.suffix-text { 
  text-align: center; 
  font-size: 0.95em; 
  color: #666; 
  margin: 8px 16px 0 16px; /* Add horizontal margin for spacing */
  min-height: 0; /* Remove min-height to prevent unnecessary space when empty */
  font-weight: 400; 
  word-break: break-word; 
}

.time-display { display: flex; justify-content: space-between; gap: 8px; margin: 4px 16px; } /* Add horizontal margin for spacing */
.time-unit { display: flex; flex-direction: column; align-items: center; flex: 1; }
.time-unit span:first-child { font-size: clamp(1.6rem, 7vw, 2.4rem); font-weight: bold; color: #333; line-height: 1; }
.time-unit .unit { font-size: 0.75em; color: #666; margin-top: 4px; text-transform: uppercase; letter-spacing: 1px; }

/* Alignment helpers */
.text-left { text-align: left; }
.text-center { text-align: center; }
.text-right { text-align: right; }

/* Small screens: allow config rows to wrap to avoid overflow */
@media (max-width: 420px) {
    .config-row { grid-template-columns: 1fr 1fr; }
    .config-row .align-select { grid-column: span 2; }
}

@media (max-width: 360px) {
    .config-row { grid-template-columns: 1fr; }
}

.icon-group { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.icon-swatch {
  width: 22px; height: 22px; border-radius: 6px; border: 2px solid #e1e5e9; background: var(--swatch, #000);
  cursor: pointer; padding: 0; outline: none; transition: transform .1s ease, box-shadow .2s ease;
}
.icon-swatch.custom { background: conic-gradient(#000, #fff); position: relative; }
.icon-swatch:focus-visible { box-shadow: 0 0 0 3px rgba(102, 126, 234, .35); }
.icon-swatch.active { border-color: #667eea; box-shadow: 0 2px 6px rgba(102,126,234,.3); transform: translateY(-1px); }
.hidden-color { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.icon-btn { width: 34px; height: 34px; border-radius: 8px; border: 2px solid #e1e5e9; background: #fff; cursor: pointer; display: grid; place-items: center; transition: transform .1s ease, border-color .2s ease, box-shadow .2s ease; }
.icon-btn:hover { transform: translateY(-1px); }
.icon-btn.active { border-color: #667eea; box-shadow: 0 2px 6px rgba(102,126,234,.3); }

.font-select { height: 40px; border: 2px solid #e1e5e9; border-radius: 10px; background: #fff; font-size: 14px; padding: 0 10px; }

/* Extended config row: text + color icons + align icons + font */
.config-row-extended { grid-template-columns: 1fr minmax(150px, 1fr) minmax(120px, 1fr) minmax(140px, 1fr); }
@media (max-width: 480px) {
  .config-row-extended { grid-template-columns: 1fr 1fr; }
}

.label-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.label-row .tools { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.icon-swatch.current { width: 28px; height: 28px; border-radius: 8px; border: 2px solid #e1e5e9; background: var(--swatch, #444); }