:root {
  --bg-page: #f4f6fb;
  --bg-card: #ffffff;
  --bg-subtle: #f8fafc;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --success: #16a34a;
  --success-hover: #15803d;
  --success-light: #dcfce7;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #d93025;
  --danger-light: #fce8e6;
  --border: #e2e8f0;
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 20px rgba(15, 23, 42, 0.07);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
}

.container {
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: 0 clamp(0.75rem, 2vw, 2.25rem);
}

/* 상단 헤더 */
.site-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: clamp(0.7rem, 1.2vw, 1rem) 0;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--shadow-sm);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-icon {
  font-size: clamp(1.7rem, 2.5vw, 2.1rem);
  line-height: 1;
}

.brand-title {
  font-size: clamp(1.05rem, 1.6vw, 1.25rem);
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand-subtitle {
  font-size: clamp(0.78rem, 1vw, 0.85rem);
  color: var(--text-muted);
}

/* 메인 레이아웃 (전체 영역 활용 + 상대적 비율 계산) */
.main-layout {
  display: grid;
  grid-template-columns: minmax(340px, 25vw) 1fr;
  gap: clamp(1rem, 1.8vw, 1.75rem);
  padding-top: clamp(1rem, 1.8vw, 1.5rem);
  padding-bottom: 3rem;
  align-items: start;
}

.create-section {
  position: sticky;
  top: 5rem;
}

@media (max-width: 960px) {
  .main-layout {
    grid-template-columns: 1fr;
  }

  .create-section {
    position: static;
  }
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: clamp(1rem, 1.8vw, 1.5rem);
  box-shadow: var(--shadow-md);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.card-title {
  font-size: 1.2rem;
  font-weight: 700;
}

/* 폼 필드 및 유효성 검사 (:user-invalid & fallback) */
.puzzle-form {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.field {
  display: flex;
  flex-direction: column;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

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

.field-label {
  font-weight: 600;
  font-size: 0.92rem;
  margin-bottom: 0.2rem;
}

.required-mark {
  color: var(--danger);
}

.optional-mark {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.hint {
  display: block;
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-bottom: 0.45rem;
}

.text-input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  color: var(--text-main);
  background: #fff;
  transition: border-color 0.15s, background-color 0.15s, box-shadow 0.15s;
}

.text-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.error-msg {
  display: none;
  color: var(--danger);
  font-size: 0.82rem;
  margin-top: 0.3rem;
  font-weight: 500;
}

/* Validate Input After Interaction (:user-invalid / :user-valid + fallback) */
input:user-invalid,
input.user-invalid-fallback {
  border-color: var(--danger);
  background-color: var(--danger-light);
}

input:user-invalid + .error-msg,
input.user-invalid-fallback + .error-msg {
  display: block;
}

input:user-valid,
input.user-valid-fallback {
  border-color: #188038;
}

/* 이미지 등록 모드 탭 */
.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  background: var(--bg-subtle);
  padding: 0.3rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-bottom: 0.65rem;
}

.mode-tab {
  border: none;
  background: transparent;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.mode-tab.active {
  background: #fff;
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* 드래그 앤 드롭 영역 */
.drop-zone {
  border: 2px dashed #cbd5e1;
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  padding: 1.35rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background-color 0.2s;
}

.drop-zone:hover,
.drop-zone:focus-visible,
.drop-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
  outline: none;
}

.drop-icon {
  font-size: 2.2rem;
  margin-bottom: 0.35rem;
}

.drop-main-text {
  font-weight: 600;
  font-size: 0.92rem;
  margin-bottom: 0.25rem;
}

.drop-sub-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.drop-sub-text kbd {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.05rem 0.35rem;
  font-size: 0.75rem;
  font-family: inherit;
}

.drop-formats {
  display: inline-block;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: #fff;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.drop-zone-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
}

.editor-canvas-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  background: #0f172a;
  line-height: 0;
  user-select: none;
  touch-action: none;
}

.editor-canvas {
  max-width: 100%;
  max-height: 240px;
  width: auto;
  height: auto;
  display: block;
}

.editor-canvas.crop-mode {
  cursor: crosshair;
}

.crop-selection-box {
  position: absolute;
  border: 2px dashed #ffffff;
  box-shadow: 0 0 0 9999px rgba(15, 23, 42, 0.58), inset 0 0 0 1px rgba(79, 70, 229, 0.9);
  pointer-events: none;
}

.crop-guide-text {
  font-size: 0.78rem;
  color: var(--primary);
  background: var(--primary-light);
  padding: 0.4rem 0.65rem;
  border-radius: 6px;
  width: 100%;
}

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: center;
  width: 100%;
}

.preview-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 0.5rem;
  background: #fff;
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.preview-filename {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 조각 수 프리셋 칩 */
.preset-chips {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.45rem;
  margin-bottom: 0.55rem;
}

.chip {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.15s;
}

.chip:hover {
  border-color: var(--primary);
}

.chip.active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

/* 실시간 진행 상태 박스 */
.progress-box {
  background: #f8fafc;
  border: 1.5px solid #c7d2fe;
  border-radius: var(--radius-md);
  padding: 1rem;
}

.progress-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.95rem;
  color: var(--primary);
  margin-bottom: 0.3rem;
}

.progress-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.progress-steps {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.83rem;
}

.step-item {
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.step-item.active {
  color: var(--primary);
  font-weight: 700;
}

.step-item.done {
  color: var(--success);
  font-weight: 600;
}

/* 버튼 공통 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-lg {
  padding: 0.8rem 1.25rem;
  font-size: 1rem;
}

.btn-sm {
  padding: 0.38rem 0.7rem;
  font-size: 0.8rem;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-success:hover:not(:disabled) {
  background: var(--success-hover);
}

.btn-secondary {
  background: var(--bg-subtle);
  border-color: var(--border);
  color: var(--text-main);
}

.btn-secondary:hover:not(:disabled) {
  background: #e2e8f0;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-main);
}

.btn-ghost:hover {
  background: var(--bg-subtle);
}

.btn-danger-outline {
  background: #fff;
  border-color: #fca5a5;
  color: var(--danger);
}

.btn-danger-outline:hover {
  background: var(--danger-light);
}

/* 배지 */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.22rem 0.6rem;
  border-radius: 999px;
}

.badge-primary {
  background: var(--primary-light);
  color: var(--primary);
}

.badge-pending {
  background: var(--warning-light);
  color: var(--warning);
}

.badge-created {
  background: var(--success-light);
  color: var(--success);
}

.badge-solved {
  background: #e0e7ff;
  color: #3730a3;
}

.puzzle-card.is-solved {
  background: #f8fafc;
}

.puzzle-card.is-solved .puzzle-thumb {
  opacity: 0.78;
}

/* 우측 퍼즐 목록 섹션 */
.list-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.list-subtitle {
  font-size: 0.84rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.filter-tabs {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.filter-tab {
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--text-muted);
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.15s;
}

.filter-tab.active {
  background: var(--text-main);
  border-color: var(--text-main);
  color: #fff;
}

.count-pill {
  background: rgba(100, 116, 139, 0.18);
  padding: 0.05rem 0.42rem;
  border-radius: 999px;
  font-size: 0.73rem;
}

.filter-tab.active .count-pill {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
}

.search-wrapper {
  flex: 1;
  min-width: 190px;
  max-width: 340px;
}

@media (max-width: 640px) {
  .search-wrapper {
    max-width: 100%;
    width: 100%;
  }
}

.search-input {
  width: 100%;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
}

.search-input:focus {
  outline: none;
  border-color: var(--primary);
}

/* 퍼즐 카드 그리드 */
.puzzle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
  gap: clamp(0.85rem, 1.4vw, 1.25rem);
}

.puzzle-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #fff;
  display: flex;
  flex-direction: column;
  transition: transform 0.15s, box-shadow 0.15s;
}

.puzzle-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.puzzle-card.is-pending {
  border-color: #fcd34d;
  background: #fffbeb;
}

.puzzle-thumb-wrap {
  position: relative;
  height: 165px;
  background: #0f172a;
  overflow: hidden;
  cursor: zoom-in;
}

.puzzle-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.25s;
}

.puzzle-thumb-wrap:hover .puzzle-thumb {
  transform: scale(1.03);
}

.puzzle-status-float {
  position: absolute;
  top: 0.6rem;
  left: 0.6rem;
  box-shadow: var(--shadow-sm);
}

.puzzle-issue-num {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  background: rgba(15, 23, 42, 0.72);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.18rem 0.5rem;
  border-radius: 999px;
  text-decoration: none;
}

.puzzle-body {
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 0.6rem;
}

.puzzle-title {
  font-size: 0.96rem;
  font-weight: 700;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.puzzle-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.puzzle-tag {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  font-weight: 600;
  color: var(--text-main);
}

.puzzle-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: auto;
}

.puzzle-actions {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--border);
}

.puzzle-actions-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.4rem;
}

/* 빈 상태 & 로딩 스피너 */
.list-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.spinner {
  display: inline-block;
  width: 1.15rem;
  height: 1.15rem;
  border: 2.5px solid #cbd5e1;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* 모달 Dialog (light-dismiss-a-dialog 준수) */
dialog::backdrop {
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
}

.modal-dialog {
  border: none;
  border-radius: var(--radius-lg);
  padding: 0;
  max-width: 480px;
  width: calc(100% - 2rem);
  margin: auto;
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.25);
  background: #fff;
  color: var(--text-main);
}

.preview-modal {
  max-width: 820px;
}

.modal-content {
  padding: 1.4rem;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 800;
}

.modal-close {
  border: none;
  background: var(--bg-subtle);
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.modal-close:hover {
  background: #e2e8f0;
  color: var(--text-main);
}

.result-summary {
  display: flex;
  gap: 0.85rem;
  align-items: center;
  background: var(--bg-subtle);
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-bottom: 1rem;
}

.result-thumb {
  width: 76px;
  height: 76px;
  border-radius: 8px;
  object-fit: cover;
  background: #0f172a;
}

.result-name {
  font-size: 0.98rem;
  font-weight: 700;
  margin-bottom: 0.2rem;
}

.result-details {
  font-size: 0.83rem;
  color: var(--text-muted);
}

.result-link-box {
  margin-bottom: 1rem;
}

.copy-input-group {
  display: flex;
  gap: 0.45rem;
  margin-top: 0.35rem;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.preview-modal-body {
  text-align: center;
}

.preview-modal-body img {
  max-width: 100%;
  max-height: 75vh;
  border-radius: var(--radius-sm);
  object-fit: contain;
}

/* 토스트 알림 */
.toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 100;
}

.toast {
  background: #1e293b;
  color: #fff;
  padding: 0.7rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  animation: fadeInUp 0.2s ease-out;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

