*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ===== Landing page ===== */

.landing {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  background: #f5f5f7;
  padding: 20px;
}

.landing-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px 32px;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 2px 20px rgba(0, 0, 0, 0.08);
  text-align: center;
}

.landing-card h1 {
  font-size: 28px;
  font-weight: 700;
  color: #1d1d1f;
  margin-bottom: 6px;
}

.subtitle {
  color: #86868b;
  font-size: 15px;
  margin-bottom: 28px;
}

.landing-card label {
  display: block;
  text-align: left;
  font-size: 13px;
  font-weight: 600;
  color: #6e6e73;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.landing-card input {
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid #d2d2d7;
  border-radius: 10px;
  font-size: 17px;
  outline: none;
  transition: border-color 0.2s;
  margin-bottom: 24px;
}

.landing-card input:focus {
  border-color: #0071e3;
}

/* ===== Buttons ===== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 24px;
  border: none;
  border-radius: 12px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.4;
  cursor: default;
  transform: none;
}

.button-group {
  display: flex;
  gap: 12px;
}

.btn-camera {
  flex: 1;
  background: #1d1d1f;
  color: #fff;
}

.btn-viewer {
  flex: 1;
  background: #0071e3;
  color: #fff;
}

.btn-capture {
  background: #0071e3;
  color: #fff;
  width: 100%;
  padding: 16px;
  font-size: 18px;
}

.btn-download {
  background: #f5f5f7;
  color: #1d1d1f;
  width: 100%;
  padding: 14px;
  font-size: 16px;
}

.btn-delete {
  background: #fff;
  color: #ff453a;
  border: 1.5px solid #ff453a;
  width: 100%;
  padding: 12px;
  font-size: 15px;
}

.btn-delete-all {
  background: #ff453a;
  color: #fff;
  width: 100%;
  padding: 12px;
  font-size: 15px;
}

.btn-preview {
  background: #1d1d1f;
  color: #fff;
  width: 100%;
  padding: 14px;
  font-size: 16px;
}

.btn-preview.active {
  background: #ff453a;
}

.btn-toggle {
  background: #e5e5ea;
  color: #1d1d1f;
  padding: 8px 20px;
  font-size: 14px;
  min-width: 64px;
}

.btn-toggle.active {
  background: #30d158;
  color: #fff;
}

/* ===== Camera mode ===== */

.camera-mode {
  background: #000;
  height: 100%;
  overflow: hidden;
  position: relative;
}

.camera-mode #preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 0.3s;
}

.camera-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  padding: calc(var(--safe-top) + 12px) calc(var(--safe-right) + 16px) 12px calc(var(--safe-left) + 16px);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
}

.camera-overlay-bottom {
  top: auto;
  bottom: 0;
  justify-content: center;
  padding: 12px calc(var(--safe-right) + 16px) calc(var(--safe-bottom) + 16px) calc(var(--safe-left) + 16px);
}

.btn-display-toggle {
  pointer-events: auto;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #fff;
  padding: 10px 24px;
  font-size: 14px;
  border-radius: 20px;
}

.display-off {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  gap: 12px;
  color: rgba(255, 255, 255, 0.5);
  font-size: 15px;
  z-index: 1;
}

.camera-status {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 8px 14px;
  border-radius: 20px;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
}

.camera-info {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 8px 14px;
  border-radius: 12px;
  color: rgba(255, 255, 255, 0.8);
  font-size: 13px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-connected {
  background: #30d158;
  box-shadow: 0 0 6px #30d158;
}

.dot-disconnected {
  background: #ff453a;
}

.camera-flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.05s;
}

.camera-flash.active {
  opacity: 0.7;
  transition: none;
}

/* ===== Viewer mode ===== */

.viewer-mode {
  background: #f5f5f7;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.viewer-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(var(--safe-top) + 12px) 16px 12px;
  background: #fff;
  border-bottom: 1px solid #e5e5ea;
}

.back-link {
  font-size: 24px;
  text-decoration: none;
  color: #0071e3;
  line-height: 1;
}

.header-info h1 {
  font-size: 20px;
  font-weight: 700;
  color: #1d1d1f;
}

.cam-status {
  font-size: 13px;
  font-weight: 500;
}

.cam-online {
  color: #30d158;
}

.cam-offline {
  color: #ff453a;
}

.viewer-main {
  flex: 1;
  padding: 16px 16px calc(var(--safe-bottom) + 16px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}

.main-image-wrap {
  background: #fff;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.06);
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.main-image-wrap img {
  width: 100%;
  display: none;
}

.main-image-wrap {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.empty-state {
  padding: 48px 20px;
  text-align: center;
  color: #86868b;
}

.empty-state p:first-child {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 6px;
}

.hint {
  font-size: 14px;
}

.viewer-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ===== Preview image ===== */

.preview-image {
  width: 100%;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
}

.main-image-wrap {
  position: relative;
}

/* ===== Controls panel ===== */

.controls-panel {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.06);
}

.control-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.control-row label {
  font-size: 14px;
  font-weight: 600;
  color: #1d1d1f;
  min-width: 50px;
}

.control-row input[type="range"] {
  flex: 1;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: #e5e5ea;
  border-radius: 3px;
  outline: none;
}

.control-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #0071e3;
  cursor: pointer;
}

.control-value {
  font-size: 14px;
  font-weight: 600;
  color: #6e6e73;
  min-width: 40px;
  text-align: right;
}

/* ===== Gallery ===== */

.gallery {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.gallery-item {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.gallery-item img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
}

.gallery-time {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 11px;
  padding: 4px 6px;
  text-align: center;
}

/* ===== Schedule ===== */

.schedule-section {
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 1px 8px rgba(0, 0, 0, 0.06);
}

.schedule-section h2 {
  font-size: 16px;
  font-weight: 700;
  color: #1d1d1f;
  margin-bottom: 6px;
}

.schedule-status {
  font-size: 13px;
  color: #6e6e73;
  margin-bottom: 14px;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.btn-preset {
  background: #f5f5f7;
  color: #1d1d1f;
  padding: 10px 8px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 10px;
}

.btn-preset.active {
  background: #0071e3;
  color: #fff;
}

.custom-time-row {
  display: flex;
  gap: 8px;
}

.custom-time-row input[type="time"] {
  flex: 1;
  padding: 10px 12px;
  border: 1.5px solid #d2d2d7;
  border-radius: 10px;
  font-size: 16px;
  outline: none;
}

.custom-time-row input[type="time"]:focus {
  border-color: #0071e3;
}

.btn-custom-time {
  background: #1d1d1f;
  color: #fff;
  padding: 10px 16px;
  font-size: 14px;
}

/* ===== Danger zone ===== */

.danger-zone {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid #e5e5ea;
}

.btn-delete-room {
  background: none;
  color: #ff453a;
  width: 100%;
  padding: 12px;
  font-size: 14px;
  font-weight: 500;
}

/* ===== Swipe navigation ===== */

.position-indicator {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  padding: 4px 12px;
  border-radius: 12px;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}

.position-indicator.visible {
  opacity: 1;
}

.date-label {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 6px 16px;
  border-radius: 12px;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}

.date-label.visible {
  opacity: 1;
}

.gallery-item.gallery-active {
  box-shadow: 0 0 0 3px #0071e3;
}

@keyframes shakeH {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

@keyframes shakeV {
  0%, 100% { transform: translateY(0); }
  20% { transform: translateY(-8px); }
  40% { transform: translateY(8px); }
  60% { transform: translateY(-4px); }
  80% { transform: translateY(4px); }
}

.shake-h {
  animation: shakeH 0.4s ease;
}

.shake-v {
  animation: shakeV 0.4s ease;
}

/* ===== Desktop arrow navigation ===== */

.nav-arrow {
  display: none;
  position: absolute;
  z-index: 3;
  width: 36px;
  height: 36px;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s, background 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.nav-arrow:hover {
  background: rgba(0, 0, 0, 0.6);
}

.main-image-wrap:hover .nav-arrow {
  opacity: 1;
}

@media (hover: hover) and (pointer: fine) {
  .nav-arrow {
    display: flex;
  }
}

.nav-left {
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
}

.nav-right {
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
}

.nav-up {
  top: 8px;
  left: 50%;
  transform: translateX(-50%) rotate(90deg);
}

.nav-down {
  bottom: 36px;
  left: 50%;
  transform: translateX(-50%) rotate(-90deg);
}
