/**
 * Smartphone Controller Styles for scTimer
 *
 * Mobile-optimized touch controller interface for
 * using a phone as a Stackmat-style timer controller.
 */

/* ============================================================================
   BASE CONTAINER
   ============================================================================ */

.smartphone-controller {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh; /* Dynamic viewport height for mobile */
  display: flex;
  flex-direction: column;
  background: var(--bg-color, #f5f5f5);
  color: var(--text-color, #333);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  overflow: hidden;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  z-index: 10000;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .smartphone-controller {
    --bg-color: #121212;
    --text-color: #f0f0f0;
    --zone-bg: #2a2a2a;
    --zone-border: #444;
  }
}

/* Light mode defaults */
.smartphone-controller {
  --zone-bg: #ffffff;
  --zone-border: #ddd;
  --holding-color: #e74c3c;
  --armed-color: #4caf50;
  --running-color: #3498db;
  --stopped-color: #9b59b6;
}

/* ============================================================================
   HEADER
   ============================================================================ */

.controller-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--header-bg, #a57865);
  color: white;
  flex-shrink: 0;
}

.controller-logo {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.controller-connection {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
}

.connection-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #888;
  transition: background 0.3s ease;
}

.connection-dot.connected {
  background: #4caf50;
  box-shadow: 0 0 8px rgba(76, 175, 80, 0.6);
}

.connection-dot.reconnecting {
  background: #f39c12;
  animation: pulse 1s infinite;
}

.connection-dot.disconnected {
  background: #e74c3c;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ============================================================================
   STATUS DISPLAY
   ============================================================================ */

.controller-status {
  text-align: center;
  padding: 16px;
  font-size: 1.1rem;
  font-weight: 500;
  background: var(--zone-bg);
  border-bottom: 1px solid var(--zone-border);
  flex-shrink: 0;
  transition: background 0.2s ease, color 0.2s ease;
}

.controller-status.ready {
  background: var(--armed-color);
  color: white;
}

.controller-status.running {
  background: var(--running-color);
  color: white;
}

.controller-status.stopped {
  background: var(--stopped-color);
  color: white;
}

.controller-status.error {
  background: #e74c3c;
  color: white;
}

.controller-status.connecting {
  background: #f39c12;
  color: white;
}

/* ============================================================================
   ACTIONS (INSPECTION BUTTON)
   ============================================================================ */

.controller-actions {
  display: flex;
  justify-content: center;
  padding: 8px 16px;
  background: var(--zone-bg);
  border-bottom: 1px solid var(--zone-border);
  flex-shrink: 0;
}

.inspection-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 28px;
  font-size: 1.1rem;
  font-weight: 600;
  color: white;
  background: #3498db;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease;
  touch-action: manipulation;
}

.inspection-btn:active {
  background: #2980b9;
  transform: scale(0.97);
}

.inspection-btn i {
  font-size: 1.3rem;
}

/* ============================================================================
   TIMER DISPLAY
   ============================================================================ */

.controller-timer {
  text-align: center;
  padding: 20px 16px;
  font-size: 3.5rem;
  font-weight: 700;
  font-family: "SF Mono", "Menlo", "Monaco", "Courier New", monospace;
  font-variant-numeric: tabular-nums;
  letter-spacing: 2px;
  background: var(--zone-bg);
  flex-shrink: 0;
}

@media (min-height: 700px) {
  .controller-timer {
    font-size: 4.5rem;
    padding: 30px 16px;
  }
}

/* ============================================================================
   TOUCH ZONES
   ============================================================================ */

.controller-zones {
  display: flex;
  flex: 1;
  gap: 4px;
  padding: 4px;
  min-height: 0;
}

.touch-zone {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: var(--zone-bg);
  border: 3px solid var(--zone-border);
  border-radius: 16px;
  transition: all 0.15s ease;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

/* Zone icons */
.zone-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  opacity: 0.3;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.zone-icon svg {
  width: 100%;
  height: 100%;
}

.zone-icon i {
  font-size: 48px;
}

.zone-label {
  margin-top: 12px;
  font-size: 1rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 2px;
  opacity: 0.4;
}

/* Touch active state */
.touch-zone.active {
  transform: scale(0.98);
  background: rgba(0, 0, 0, 0.05);
}

.touch-zone.active .zone-icon {
  opacity: 0.5;
  transform: scale(1.1);
}

/* Holding state (red) */
.touch-zone.holding {
  background: var(--holding-color);
  border-color: var(--holding-color);
  color: white;
}

.touch-zone.holding .zone-icon {
  opacity: 0.8;
}

.touch-zone.holding .zone-label {
  opacity: 0.8;
}

/* Armed/Ready state (green) */
.touch-zone.armed {
  background: var(--armed-color);
  border-color: var(--armed-color);
  color: white;
  animation: readyPulse 0.5s ease-in-out infinite alternate;
}

.touch-zone.armed .zone-icon {
  opacity: 1;
}

.touch-zone.armed .zone-label {
  opacity: 1;
}

@keyframes readyPulse {
  from {
    box-shadow: 0 0 20px rgba(76, 175, 80, 0.4);
  }
  to {
    box-shadow: 0 0 40px rgba(76, 175, 80, 0.8);
  }
}

/* Running state */
.touch-zone.running {
  background: var(--zone-bg);
  border-color: var(--running-color);
  opacity: 0.7;
}

.touch-zone.running .zone-icon {
  opacity: 0.2;
}

.touch-zone.running .zone-label {
  opacity: 0.3;
}

/* Stopped state */
.touch-zone.stopped {
  background: var(--stopped-color);
  border-color: var(--stopped-color);
  color: white;
  opacity: 0.9;
}

/* ============================================================================
   INSTRUCTIONS
   ============================================================================ */

.controller-instructions {
  text-align: center;
  padding: 12px 16px;
  font-size: 0.85rem;
  color: var(--text-color);
  opacity: 0.6;
  background: var(--zone-bg);
  border-top: 1px solid var(--zone-border);
  flex-shrink: 0;
}

/* ============================================================================
   RESPONSIVE ADJUSTMENTS
   ============================================================================ */

/* Small phones */
@media (max-height: 600px) {
  .controller-status {
    padding: 10px;
    font-size: 1rem;
  }

  .controller-actions {
    padding: 6px 12px;
  }

  .inspection-btn {
    padding: 10px 20px;
    font-size: 0.95rem;
  }

  .inspection-btn i {
    font-size: 1.1rem;
  }

  .controller-timer {
    padding: 12px;
    font-size: 2.5rem;
  }

  .zone-icon {
    width: 48px;
    height: 48px;
  }

  .zone-icon i {
    font-size: 36px;
  }

  .zone-label {
    font-size: 0.85rem;
    margin-top: 8px;
  }

  .controller-instructions {
    padding: 8px 12px;
    font-size: 0.75rem;
  }
}

/* Landscape orientation */
@media (orientation: landscape) {
  .controller-zones {
    flex-direction: row;
  }

  .controller-timer {
    font-size: 2.5rem;
    padding: 12px;
  }

  .controller-status {
    padding: 8px;
    font-size: 0.9rem;
  }

  .controller-actions {
    padding: 4px 8px;
  }

  .inspection-btn {
    padding: 8px 16px;
    font-size: 0.9rem;
  }

  .controller-instructions {
    display: none;
  }
}

/* Large tablets */
@media (min-width: 768px) and (min-height: 1024px) {
  .controller-timer {
    font-size: 6rem;
    padding: 40px;
  }

  .zone-icon {
    width: 96px;
    height: 96px;
  }

  .zone-icon i {
    font-size: 72px;
  }

  .zone-label {
    font-size: 1.2rem;
  }

  .inspection-btn {
    padding: 18px 36px;
    font-size: 1.3rem;
  }
}

/* ============================================================================
   DARK MODE OVERRIDES
   ============================================================================ */

@media (prefers-color-scheme: dark) {
  .controller-header {
    background: #6d4c41;
  }

  .touch-zone {
    background: #1e1e1e;
    border-color: #333;
  }

  .touch-zone.active {
    background: rgba(255, 255, 255, 0.05);
  }

  .controller-status,
  .controller-timer,
  .controller-actions,
  .controller-instructions {
    background: #1e1e1e;
    border-color: #333;
  }

  .inspection-btn {
    background: #2980b9;
  }

  .inspection-btn:active {
    background: #1f6491;
  }
}

/* ============================================================================
   SAFE AREA HANDLING (NOTCH/HOME INDICATOR)
   ============================================================================ */

@supports (padding-top: env(safe-area-inset-top)) {
  .controller-header {
    padding-top: calc(12px + env(safe-area-inset-top));
  }

  .controller-instructions {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }

  .controller-zones {
    padding-left: calc(4px + env(safe-area-inset-left));
    padding-right: calc(4px + env(safe-area-inset-right));
  }
}

/* ============================================================================
   ANIMATIONS
   ============================================================================ */

/* Smooth state transitions */
.touch-zone,
.controller-status,
.connection-dot {
  transition-property: background, border-color, color, opacity, transform, box-shadow;
  transition-duration: 0.15s;
  transition-timing-function: ease;
}

/* Disable transitions during active touch for immediate feedback */
.touch-zone.active {
  transition-duration: 0.05s;
}
