* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: Arial, "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  background: #f3f7fb;
  color: #1f2937;
  min-width: 0;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.5;
}

body.drawer-open {
  position: fixed;
  overflow: hidden;
  width: 100%;
  left: 0;
  right: 0;
  overscroll-behavior: none;
  touch-action: none;
}

button,
input,
textarea,
select {
  font: inherit;
}

img {
  max-width: 100%;
}

.app {
  max-width: 1320px;
  margin: 0 auto;
  padding: 20px;
}

.app-header {
  background: #ffffff;
  border-radius: 22px;
  padding: 24px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
  margin-bottom: 20px;
  text-align: center;
}

.app-header h1 {
  margin: 0 0 10px;
  font-size: clamp(26px, 4vw, 34px);
  line-height: 1.25;
  word-break: keep-all;
}

.app-header p {
  margin: 0;
  font-size: clamp(15px, 2.2vw, 18px);
  color: #4b5563;
  line-height: 1.6;
  word-break: keep-all;
}

.main-layout {
  display: grid;
  grid-template-columns: minmax(320px, 400px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.panel {
  background: #ffffff;
  border-radius: 22px;
  padding: 20px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
  min-width: 0;
}

.panel h2 {
  margin: 0 0 16px;
  font-size: clamp(22px, 3vw, 26px);
  line-height: 1.3;
  word-break: keep-all;
}

.upload-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 18px;
  font-weight: 800;
  min-width: 0;
  margin: 0;
}

.form-label span {
  word-break: keep-all;
}

.form-label input[type="text"],
.form-label input[type="password"],
.form-label input[type="file"],
.form-label textarea {
  width: 100%;
  min-width: 0;
  padding: 14px;
  border: 2px solid #d1d5db;
  border-radius: 16px;
  background: #ffffff;
  font-size: 16px;
  margin: 0;
}

.form-label textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.6;
}

.password-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.inline-help {
  margin-top: -6px;
  color: #6b7280;
  font-size: 14px;
  line-height: 1.6;
  word-break: keep-all;
  overflow-wrap: break-word;
}

.preview-box {
  background: #f9fafb;
  border: 2px solid #e5e7eb;
  border-radius: 18px;
  padding: 14px;
}

.preview-box.hidden {
  display: none;
}

.preview-title {
  font-size: 16px;
  font-weight: 800;
  margin-bottom: 10px;
}

.preview-image {
  display: block;
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border-radius: 14px;
  background: #ffffff;
  border: 1px solid #e5e7eb;
}

.text-counter {
  margin-top: -8px;
  text-align: right;
  font-size: 14px;
  color: #6b7280;
  font-weight: 700;
}

.location-box {
  background: #f9fafb;
  border: 2px solid #e5e7eb;
  border-radius: 18px;
  padding: 16px;
}

.location-title {
  font-size: 19px;
  font-weight: 800;
  margin-bottom: 8px;
}

.help-text {
  margin: 0 0 14px;
  line-height: 1.7;
  color: #4b5563;
  font-size: 15px;
  word-break: keep-all;
  overflow-wrap: break-word;
}

.button-row {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.button-row.compact .big-button {
  min-height: 50px;
  font-size: 16px;
}

.big-button,
.small-button,
.gallery-action-btn,
.drawer-close-btn,
.gallery-delete-icon-btn,
.action-modal-btn {
  border: none;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.2s ease, background 0.2s ease;
}

.big-button:hover,
.small-button:hover,
.gallery-action-btn:hover,
.drawer-close-btn:hover,
.gallery-delete-icon-btn:hover,
.action-modal-btn:hover {
  opacity: 0.94;
}

.big-button:active,
.small-button:active,
.gallery-action-btn:active,
.drawer-close-btn:active,
.gallery-delete-icon-btn:active,
.action-modal-btn:active {
  transform: scale(0.98);
}

.big-button:disabled,
.small-button:disabled,
.gallery-action-btn:disabled,
.drawer-close-btn:disabled,
.gallery-delete-icon-btn:disabled,
.action-modal-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.big-button {
  width: 100%;
  min-height: 58px;
  border-radius: 18px;
  font-size: 18px;
  font-weight: 800;
  line-height: 1.35;
  padding: 10px 14px;
}

.big-button.primary {
  background: #2563eb;
  color: #ffffff;
}

.big-button.secondary {
  background: #10b981;
  color: #ffffff;
}

.big-button.neutral {
  background: #f59e0b;
  color: #ffffff;
  border: 2px solid #d97706;
  box-shadow: 0 6px 16px rgba(245, 158, 11, 0.28);
}

.big-button.neutral:hover {
  opacity: 1;
  background: #d97706;
}

.small-button {
  min-height: 42px;
  padding: 0 14px;
  border-radius: 12px;
  background: #111827;
  color: #ffffff;
  font-size: 14px;
  font-weight: 700;
}

.gallery-button {
  background: #2563eb;
}

.location-mode-badge {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.5;
}

.location-mode-badge.exif {
  background: #eff6ff;
  color: #1d4ed8;
  border: 2px solid #bfdbfe;
}

.location-mode-badge.manual {
  background: #fef3c7;
  color: #92400e;
  border: 2px solid #f59e0b;
}

.location-mode-badge.current {
  background: #ecfdf5;
  color: #047857;
  border: 2px solid #34d399;
}

.selected-location {
  margin-top: 12px;
  padding: 12px;
  border-radius: 14px;
  border: 2px dashed #cbd5e1;
  background: #ffffff;
  line-height: 1.7;
  font-size: 15px;
  word-break: keep-all;
  overflow-wrap: break-word;
}

.status-message {
  margin-top: 16px;
  min-height: 52px;
  display: flex;
  align-items: center;
  padding: 14px;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.5;
}

.status-message.info {
  background: #eff6ff;
  color: #1d4ed8;
}

.status-message.success {
  background: #ecfdf5;
  color: #047857;
}

.status-message.error {
  background: #fef2f2;
  color: #b91c1c;
}

.map-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.map-panel-head h2 {
  margin: 0;
}

.map-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

#map {
  width: 100%;
  height: min(720px, 70vh);
  min-height: 420px;
  border-radius: 20px;
  overflow: hidden;
  border: 2px solid #e5e7eb;
}

.popup-card {
  width: min(220px, 62vw);
}

.popup-image {
  display: block;
  width: 100%;
  height: 140px;
  object-fit: cover;
  border-radius: 12px;
  margin-bottom: 10px;
}

.popup-desc {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.6;
  margin-bottom: 8px;
  word-break: keep-all;
  overflow-wrap: break-word;
}

.popup-meta,
.popup-date {
  font-size: 12px;
  line-height: 1.5;
}

.popup-meta {
  color: #334155;
  margin-bottom: 6px;
}

.popup-date {
  color: #6b7280;
}

.drawer-backdrop,
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 999;
}

.drawer-backdrop.hidden,
.modal-backdrop.hidden,
.action-modal.hidden,
.edit-modal.hidden {
  display: none;
}

.gallery-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(460px, 94vw);
  height: 100dvh;
  background: #ffffff;
  box-shadow: -10px 0 30px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
}

.gallery-drawer.open {
  transform: translateX(0);
}

.gallery-drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 18px 16px;
  border-bottom: 1px solid #e5e7eb;
}

.gallery-drawer-title-wrap {
  min-width: 0;
}

.gallery-drawer-header h2 {
  margin: 0 0 6px;
  font-size: 24px;
}

.gallery-drawer-header p {
  margin: 0;
  color: #6b7280;
  font-size: 14px;
  font-weight: 700;
}

.drawer-close-btn {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 12px;
  background: #111827;
  color: #ffffff;
  font-size: 14px;
  font-weight: 800;
}

.gallery-toolbar {
  padding: 14px 14px 10px;
  border-bottom: 1px solid #e5e7eb;
  display: grid;
  gap: 10px;
}

.gallery-search-input,
.gallery-sort-select,
.modal-password-input,
.admin-password-input {
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border: 2px solid #d1d5db;
  border-radius: 12px;
  background: #ffffff;
  font-size: 15px;
  margin-top: 2px;
  margin-bottom: 0;
}

.gallery-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.gallery-empty {
  padding: 24px 12px;
  text-align: center;
  color: #6b7280;
  font-size: 16px;
  font-weight: 700;
}

.gallery-item {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  border: 1px solid #e5e7eb;
  border-radius: 18px;
  background: #ffffff;
  padding: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
}

.gallery-thumb {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 14px;
  background: #f3f4f6;
}

.gallery-item-body {
  position: relative;
  padding-right: 34px;
  min-width: 0;
}

.gallery-delete-icon-btn {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: #f3f4f6;
  color: #6b7280;
  font-size: 20px;
  line-height: 1;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.gallery-delete-icon-btn:hover {
  background: #fee2e2;
  color: #dc2626;
  opacity: 1;
}

.gallery-item-desc {
  font-size: 15px;
  font-weight: 800;
  line-height: 1.6;
  margin-bottom: 8px;
  color: #111827;
  overflow-wrap: anywhere;
}

.gallery-item-meta {
  font-size: 13px;
  color: #4b5563;
  line-height: 1.6;
  margin-bottom: 4px;
  overflow-wrap: anywhere;
}

.gallery-item-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.gallery-action-btn {
  flex: 1;
  min-height: 40px;
  border-radius: 12px;
  background: #2563eb;
  color: #ffffff;
  font-size: 14px;
  font-weight: 800;
  padding: 0 10px;
}

.gallery-action-btn.secondary {
  background: #0f766e;
}

.action-modal,
.edit-modal {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 24px 20px;
}

.action-modal-card,
.edit-modal-card {
  width: min(460px, 100%);
  max-height: calc(100dvh - 48px);
  background: #ffffff;
  border-radius: 20px;
  padding: 20px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.2);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin: auto 0;
}

.edit-modal-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.action-modal-card h3,
.edit-modal-card h3 {
  margin: 0 0 10px;
  font-size: 22px;
  line-height: 1.3;
}

.action-modal-text,
.edit-owner-text {
  margin: 0 0 14px;
  color: #4b5563;
  line-height: 1.6;
}

.edit-modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 0;
}

.edit-owner-text {
  margin: 0;
  color: #4b5563;
  line-height: 1.6;
}

.edit-modal-card .form-label {
  margin: 0;
}

.edit-modal-card .form-label input,
.edit-modal-card .form-label textarea {
  margin: 0;
}

.edit-modal-card .inline-help {
  margin-top: -4px;
  margin-bottom: 2px;
  color: #6b7280;
  font-size: 14px;
  line-height: 1.6;
  word-break: keep-all;
  overflow-wrap: break-word;
}

.action-modal-message {
  min-height: 24px;
  margin-top: 0;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.5;
}

.action-modal-message.info {
  color: #1d4ed8;
}

.action-modal-message.error {
  color: #b91c1c;
}

.action-modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
  position: sticky;
  bottom: 0;
  background: #ffffff;
  padding-top: 12px;
}

.action-modal-btn {
  flex: 1;
  min-height: 44px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 800;
}

.action-modal-btn.primary {
  background: #2563eb;
  color: #ffffff;
}

.action-modal-btn.secondary {
  background: #e5e7eb;
  color: #111827;
}

.edit-mini-map {
  width: 100%;
  height: 220px;
  min-height: 220px;
  border-radius: 16px;
  overflow: hidden;
  border: 2px solid #e5e7eb;
  margin-top: 4px;
  flex-shrink: 0;
}

.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
  background: rgba(37, 99, 235, 0.18);
}

.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
  background: #2563eb;
  color: #ffffff;
  font-weight: 800;
  border: 3px solid rgba(255, 255, 255, 0.95);
}

@media (max-width: 1024px) {
  .main-layout {
    grid-template-columns: 1fr;
  }

  #map {
    height: min(560px, 58vh);
  }
}

@media (max-width: 640px) {
  .app {
    padding: 12px;
  }

  .app-header,
  .panel {
    border-radius: 18px;
  }

  .app-header {
    padding: 18px;
  }

  .panel {
    padding: 16px;
  }

  .password-grid {
    grid-template-columns: 1fr;
  }

  .form-label {
    font-size: 17px;
  }

  .big-button {
    min-height: 54px;
    font-size: 17px;
  }

  .map-panel-head {
    flex-direction: column;
    align-items: stretch;
  }

  .map-actions {
    flex-direction: column;
  }

  .small-button {
    width: 100%;
  }

  #map {
    height: min(460px, 52vh);
    min-height: 320px;
  }

  .gallery-drawer {
    width: 100vw;
  }

  .gallery-drawer-header {
    padding-top: calc(16px + env(safe-area-inset-top));
  }

  .gallery-list {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }

  .gallery-item {
    grid-template-columns: 84px minmax(0, 1fr);
    gap: 10px;
    padding: 10px;
  }

  .gallery-thumb {
    width: 84px;
    height: 84px;
    border-radius: 12px;
  }

  .gallery-item-body {
    padding-right: 32px;
  }

  .gallery-delete-icon-btn {
    width: 26px;
    height: 26px;
    font-size: 18px;
  }

  .gallery-item-actions,
  .action-modal-actions {
    flex-direction: column;
  }

  .edit-modal,
  .action-modal {
    padding:
      calc(14px + env(safe-area-inset-top))
      14px
      calc(14px + env(safe-area-inset-bottom));
  }

  .edit-modal-card,
  .action-modal-card {
    padding: 16px;
    border-radius: 16px;
    max-height: calc(100dvh - 28px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    gap: 12px;
  }

  .edit-mini-map {
    height: 200px;
    min-height: 200px;
  }

  .popup-card {
    width: min(220px, 70vw);
  }
}