/* ===========================================
   ChronoDex Controller — Mobile-First CSS
   =========================================== */

body {
  background: #1a1a2e;
  color: #eee;
  min-height: 100vh;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}

/* --- Join Screen --- */

#join-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: clamp(10px, 3vw, 16px);
  padding: 1.5rem 1rem;
  overflow: hidden;
  position: relative;
  transition: flex 0.4s ease, padding 0.4s ease, opacity 0.3s ease, gap 0.4s ease;
}

#join-screen.collapsed {
  flex: 0 0 auto;
  padding: 6px 10px;
  gap: 6px;
  flex-direction: row;
  align-items: center;
  min-height: 0;
  justify-content: flex-start;
  border-bottom: 1px solid #333;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 50;
  background: #1a1a2e;
}

#join-screen.collapsed h1,
#join-screen.collapsed p,
#join-screen.collapsed #join-btn,
#join-screen.collapsed #join-error {
  display: none;
}

#join-screen.collapsed #room-code-input {
  font-size: 0.85rem;
  padding: 4px 8px;
  width: 7ch;
  letter-spacing: 0.15em;
  border-radius: 6px;
  pointer-events: none;
  opacity: 0.7;
}

/* Nav links */
#nav-links {
  display: flex;
  gap: 10px;
  align-items: center;
}

#nav-links a {
  color: #6ec6ff;
  text-decoration: none;
  font-size: 1rem;
  opacity: 0.7;
  transition: opacity 0.15s;
  padding: 4px;
}

#nav-links a:hover {
  opacity: 1;
}

/* Before joining: position nav at top-right */
#join-screen:not(.collapsed) #nav-links {
  position: absolute;
  top: 10px;
  right: 10px;
}

#connected-badge {
  display: none;
}

#join-screen.collapsed #connected-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.7rem;
  color: #2d6a4f;
  font-weight: 700;
  margin-left: auto;
}

#join-screen h1 {
  font-size: clamp(1.3rem, 5vw, 1.8rem);
  margin: 0;
  white-space: nowrap;
}

#join-screen p {
  opacity: 0.7;
  text-align: center;
  font-size: clamp(0.8rem, 2.5vw, 1rem);
}

#room-code-input {
  font-size: clamp(2rem, 8vw, 3rem);
  text-align: center;
  width: 6ch;
  padding: clamp(8px, 2vw, 12px);
  border: 2px solid #444;
  border-radius: 12px;
  background: #16213e;
  color: #fff;
  letter-spacing: 0.3em;
  flex-shrink: 0;
}

#room-code-input:focus {
  outline: none;
  border-color: #6ec6ff;
}

#join-btn {
  font-size: clamp(1rem, 3vw, 1.3rem);
  padding: clamp(10px, 2.5vw, 14px) clamp(32px, 8vw, 48px);
  border: none;
  border-radius: 12px;
  background: #0f3460;
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: filter 0.15s;
  min-height: 44px;
}

#join-btn:hover {
  filter: brightness(1.3);
}

#join-error {
  color: #e76f51;
  font-weight: bold;
  font-size: 0.85rem;
}

/* --- Control Panel --- */

#control-panel {
  display: none;
  flex-direction: column;
  flex: 1;
  padding: 6px;
  overflow: visible;
}

#control-panel.active {
  display: flex;
}

/* Header: global actions bar */
#control-panel header {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 6px;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: center;
}

#panel-nav {
  display: flex;
  gap: 6px;
  margin-right: auto;
}

#open-display-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 6px 10px;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
}

#open-display-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

#global-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn-global {
  padding: 8px 10px;
  border: none;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  color: #fff;
  transition: filter 0.15s;
  min-height: 36px;
  white-space: nowrap;
}

.btn-global:hover { filter: brightness(1.3); }
.btn-global:active { transform: scale(0.95); }

.btn-start-all { background: #2d6a4f; }
.btn-pause-all { background: #e76f51; }
.btn-reset-all { background: #6c1d1d; }

.btn-global i { margin-right: 3px; }

/* --- Timer Grid --- */

#timer-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  margin-bottom: 6px;
  align-content: start;
}

/* --- Timer Block --- */

.timer-block {
  border-radius: 10px;
  padding: 10px 8px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: opacity 0.15s, border-color 0.15s, box-shadow 0.15s;
  border: 2px solid transparent;
}

.timer-block.swap-source {
  border-color: #6ec6ff;
  box-shadow: 0 0 12px rgba(110, 198, 255, 0.4);
}

.timer-block.swap-target {
  cursor: pointer;
  border-color: rgba(110, 198, 255, 0.3);
}

.timer-block.swap-target:hover {
  border-color: #6ec6ff;
  box-shadow: 0 0 8px rgba(110, 198, 255, 0.3);
}

.block-name-input {
  background: rgba(0,0,0,0.25);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 4px;
  color: #fff;
  padding: 5px 6px;
  font-size: clamp(0.75rem, 2vw, 0.85rem);
  text-align: center;
  width: 100%;
  min-width: 0;
  min-height: 32px;
}

.block-name-input:focus {
  outline: none;
  border-color: #6ec6ff;
}

.block-time {
  font-size: clamp(1.4rem, 5vw, 1.8rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.block-time.negative {
  color: #ff6b6b;
}

.block-buttons {
  display: flex;
  gap: 4px;
  margin-top: 2px;
}

.btn {
  padding: 8px 14px;
  border: none;
  border-radius: 5px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  color: #fff;
  transition: filter 0.15s;
  min-height: 36px;
}

.btn:hover { filter: brightness(1.3); }
.btn:active { transform: scale(0.95); }

.btn i { margin-right: 3px; }

.btn-play { background: #2d6a4f; }
.btn-pause { background: #e76f51; }
.btn-reset { background: rgba(255,255,255,0.15); }
.btn-reset:hover { background: rgba(255,255,255,0.25); }
.btn-swap { background: rgba(255,255,255,0.10); }
.btn-swap:hover { background: rgba(110,198,255,0.25); }
.btn-swap.active { background: #0f3460; }

/* Settings rows */
.block-settings-row {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  justify-content: center;
  flex-wrap: wrap;
}

.dur-label {
  font-size: 0.6rem;
  opacity: 0.5;
}

.color-input {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  background: none;
  padding: 0;
}

.text-color-input {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  background: none;
  padding: 0;
}

.font-select {
  background: #1a1a2e;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 4px;
  color: #fff;
  padding: 5px 6px;
  font-size: 0.7rem;
  flex: 1;
  min-width: 0;
  min-height: 32px;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 4px center;
  padding-right: 18px;
}

.font-select option {
  background: #1a1a2e;
  color: #fff;
  padding: 4px;
}

.font-select:focus {
  outline: none;
  border-color: #6ec6ff;
}

.settings-label {
  font-size: 0.55rem;
  opacity: 0.45;
  flex-shrink: 0;
}

.duration-input {
  background: rgba(0,0,0,0.3);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 4px;
  color: #fff;
  padding: 5px 4px;
  font-size: 0.75rem;
  width: 48px;
  min-width: 48px;
  min-height: 32px;
  text-align: center;
}

.duration-input:focus {
  outline: none;
  border-color: #6ec6ff;
}

/* Opacity / font-scale slider */
.opacity-row {
  flex-wrap: nowrap;
}

.opacity-slider-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.opacity-value {
  font-size: 0.65rem;
  opacity: 0.7;
  font-weight: 600;
}

.opacity-slider {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255,255,255,0.2);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

.opacity-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #6ec6ff;
  cursor: pointer;
}

.opacity-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #6ec6ff;
  cursor: pointer;
  border: none;
}

.btn-remove-small {
  background: rgba(108,29,29,0.7);
  border: none;
  border-radius: 4px;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  width: 28px;
  height: 28px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: filter 0.15s;
}

.btn-remove-small:hover { filter: brightness(1.4); }

/* Add timer button */
.btn-add {
  width: 100%;
  padding: 10px;
  border: 1px dashed #444;
  border-radius: 8px;
  background: transparent;
  color: #666;
  font-size: 0.85rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s;
  min-height: 44px;
}

.btn-add:hover {
  border-color: #6ec6ff;
  color: #6ec6ff;
}

.btn-add:active {
  border-color: #6ec6ff;
  color: #6ec6ff;
}

.btn-add i { margin-right: 4px; }

/* Media row (Logo + Background on one line) */
#media-row {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  margin-top: 4px;
}

.media-group {
  flex: 1;
  display: flex;
  gap: 3px;
  align-items: center;
  min-width: 0;
}

.media-label {
  font-size: 0.65rem;
  font-weight: 700;
  opacity: 0.6;
  white-space: nowrap;
  flex-shrink: 0;
}

#logo-url-input,
#bg-url-input {
  flex: 1;
  min-width: 0;
  background: rgba(0,0,0,0.3);
  border: 1px solid #444;
  border-radius: 5px;
  color: #fff;
  padding: 5px 6px;
  font-size: 0.7rem;
  min-height: 32px;
}

#logo-url-input:focus,
#bg-url-input:focus {
  outline: none;
  border-color: #6ec6ff;
}

.media-group button {
  background: rgba(255,255,255,0.1);
  border: none;
  border-radius: 5px;
  color: #fff;
  padding: 0;
  width: 28px;
  height: 28px;
  font-size: 0.65rem;
  cursor: pointer;
  transition: filter 0.15s, background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.media-group button:hover { filter: brightness(1.3); }

#logo-set-btn,
#bg-set-btn { background: #0f3460; }

#logo-upload-btn,
#bg-upload-btn { background: #2d6a4f; }

#logo-clear-btn,
#bg-clear-btn { background: #6c1d1d; }

#control-status {
  text-align: center;
  padding: 4px;
  font-size: 0.7rem;
  opacity: 0.4;
  flex-shrink: 0;
}

#support-message {
  text-align: center;
  padding: 8px 12px;
  font-size: 0.75rem;
  opacity: 0.5;
  line-height: 1.6;
  flex-shrink: 0;
  border-top: 1px solid rgba(255,255,255,0.1);
  margin-top: 4px;
}

#support-message a {
  display: inline-block;
  margin-top: 4px;
  color: #00b9fe;
  text-decoration: none;
  font-weight: 700;
  transition: opacity 0.15s;
}

#support-message a:hover {
  opacity: 0.8;
}

/* ===========================================
   Tablet — 2 colonnes (>= 480px)
   =========================================== */

@media (min-width: 480px) {
  body {
    height: 100vh;
    min-height: 0;
    overflow: hidden;
  }

  #control-panel {
    overflow: hidden;
  }

  #timer-list {
    grid-template-columns: repeat(2, 1fr);
    flex: 1;
    overflow-y: auto;
  }

  .timer-block {
    padding: 8px 6px 6px;
    gap: 3px;
  }

  .block-settings-row {
    flex-wrap: nowrap;
  }
}

/* ===========================================
   Desktop — espacement élargi (>= 768px)
   =========================================== */

@media (min-width: 768px) {
  #join-screen {
    gap: 16px;
    padding: 2rem;
  }

  #control-panel {
    padding: 8px;
  }

  #control-panel header {
    gap: 6px;
    margin-bottom: 8px;
  }

  #timer-list {
    gap: 8px;
  }

  .timer-block {
    gap: 4px;
  }

  .btn-global {
    font-size: 0.75rem;
    padding: 8px 12px;
  }

  .btn {
    padding: 6px 16px;
  }

  .color-input {
    width: 24px;
    height: 24px;
  }

  .text-color-input {
    width: 20px;
    height: 20px;
  }

  .opacity-slider::-webkit-slider-thumb {
    width: 14px;
    height: 14px;
  }

  .opacity-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
  }

  .opacity-slider {
    height: 4px;
  }

  .btn-remove-small {
    width: 22px;
    height: 22px;
  }
}
