:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-hover: #0ea5e9;
  --danger: #f87171;
  --success: #4ade80;
  --warning: #facc15;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

.topnav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  padding-left: calc(20px + env(safe-area-inset-left, 0px));
  padding-right: calc(20px + env(safe-area-inset-right, 0px));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.nav-links { display: flex; gap: 4px; list-style: none; padding: 0; margin: 0; }
.nav-links a {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  padding: 8px 14px;
  border-radius: 8px;
  transition: background .15s, color .15s;
}
.nav-links a:hover { color: var(--text); background: var(--surface-2); }
.nav-links a.active { color: var(--text); background: var(--surface-2); font-weight: 500; }
.nav-right { display: flex; gap: 8px; align-items: center; }
.nav-user { color: var(--text); font-size: 13px; padding: 6px 10px; }
.nav-btn { padding: 6px 12px; font-size: 13px; }
.nav-btn-link {
  padding: 8px 14px;
  background: var(--accent);
  color: #0f172a !important;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 20px 80px;
  padding-left: calc(20px + env(safe-area-inset-left, 0px));
  padding-right: calc(20px + env(safe-area-inset-right, 0px));
}

@media (max-width: 720px) {
  main {
    padding: 14px 12px 96px;
    padding-left: calc(12px + env(safe-area-inset-left, 0px));
    padding-right: calc(12px + env(safe-area-inset-right, 0px));
  }
  .topnav {
    padding: 10px 12px;
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
    padding-left: calc(12px + env(safe-area-inset-left, 0px));
    padding-right: calc(12px + env(safe-area-inset-right, 0px));
    flex-wrap: wrap;
    gap: 8px;
  }
  .nav-links { flex-wrap: wrap; gap: 2px; }
  .nav-links a { padding: 5px 8px; font-size: 12px; white-space: nowrap; }
  .nav-right { gap: 6px; }
  .nav-user { padding: 4px 6px; font-size: 12px; }
  .nav-btn { padding: 5px 10px; font-size: 12px; }
  h1 { font-size: 21px; }
  h2 { font-size: 16px; }
  section, .surface { padding: 14px; border-radius: 10px; }
  .checkbox-grid { grid-template-columns: 1fr 1fr; gap: 4px; }
  .checkbox-grid label { font-size: 13px; padding: 4px 0; }
  button { min-height: 40px; font-size: 14px; }
  .toast { top: 12px; right: 12px; left: 12px; max-width: none; transform: translateY(-150%); }
  .toast.show { transform: translateY(0); }
}

@supports (padding: max(0px)) {
  body {
    padding-bottom: env(safe-area-inset-bottom);
    min-height: 100dvh;
  }
}

h1 { margin: 0 0 6px; font-size: 26px; }
.subtitle { color: var(--muted); margin: 0; font-size: 14px; }

section, .surface {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}

button {
  font-family: inherit;
  font-size: 14px;
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #0f172a; font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
button.ghost { background: transparent; }
button.danger { color: var(--danger); border-color: rgba(248, 113, 113, 0.3); }
button.danger:hover:not(:disabled) { border-color: var(--danger); }

/* 텍스트 계열 입력만 — checkbox/radio/file은 네이티브 모양 유지 */
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="color"]),
select,
textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 10px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.4;
  min-height: 38px;
  -webkit-appearance: none;
  appearance: none;
}
textarea { min-height: 60px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
@media (min-width: 721px) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="range"]):not([type="color"]),
  select,
  textarea { font-size: 14px; min-height: 34px; }
}

/* 체크박스/라디오: 작은 변 기준 정사각형, 가로 배치 */
input[type="checkbox"], input[type="radio"] {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  min-width: 16px;
  min-height: 0;
  flex: 0 0 16px;
  padding: 0;
  margin: 0;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 3px;
  display: inline-block;
  vertical-align: middle;
  cursor: pointer;
  transition: background .12s, border-color .12s;
  position: relative;
  box-sizing: border-box;
}
input[type="radio"] { border-radius: 50%; }
input[type="checkbox"]:hover, input[type="radio"]:hover { border-color: var(--accent); }
input[type="checkbox"]:checked,
input[type="radio"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 1px;
  width: 4px;
  height: 8px;
  border: solid #0f172a;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
input[type="radio"]:checked::after {
  content: "";
  position: absolute;
  inset: 3px;
  background: #0f172a;
  border-radius: 50%;
}
input[type="checkbox"]:focus-visible,
input[type="radio"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.form-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.form-row label { font-size: 12px; color: var(--muted); }
.checkbox-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 8px; }
.checkbox-grid label {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  padding: 6px 4px;
  border-radius: 6px;
  user-select: none;
  white-space: nowrap;
  line-height: 1.2;
  -webkit-tap-highlight-color: transparent;
  min-width: 0;
}
.checkbox-grid label:hover { background: rgba(56, 189, 248, 0.06); }
.checkbox-grid label:has(input:checked) { color: var(--accent); }
.checkbox-grid input[type="checkbox"],
.checkbox-grid input[type="radio"] {
  width: 16px;
  height: 16px;
  min-width: 16px;
  flex: 0 0 16px;
}

.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  font-size: 14px;
  border: 1px dashed var(--border);
  border-radius: 10px;
}

.toast {
  position: fixed;
  top: 20px; right: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 14px;
  max-width: 360px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  transform: translateX(120%);
  transition: transform .2s ease-out;
  z-index: 1000;
  line-height: 1.5;
}
.toast.show { transform: translateX(0); }
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.success { border-color: var(--success); color: var(--success); }

/* 비로그인 안내 배너: 진입 시 페이지 상단에 비차단 노출 */
.auth-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
}
.auth-banner-icon { font-size: 16px; }
.auth-banner-text { flex: 1; }
.auth-banner-cta {
  background: var(--accent);
  color: #0f172a !important;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  white-space: nowrap;
}
.auth-banner-cta:hover { background: var(--accent-hover); color: #0f172a !important; }
@media (max-width: 720px) {
  .auth-banner { flex-wrap: wrap; padding: 10px 12px; gap: 8px; }
  .auth-banner-text { flex-basis: 100%; }
  .auth-banner-cta { margin-left: auto; }
}

/* 인라인 폼 에러 / 안내 (필드 바로 아래) */
.field-error,
.field-hint {
  font-size: 12px;
  line-height: 1.5;
  margin-top: 4px;
  min-height: 16px;
}
.field-error { color: var(--danger); }
.field-hint { color: var(--muted); }
.field-error[hidden],
.field-hint[hidden] { display: none; }

/* 로그인 필요 모달 (공용) */
.modal-backdrop .login-required-modal {
  max-width: 420px;
}
.login-required-modal h2 { margin: 0 0 8px; font-size: 18px; }
.login-required-modal .summary { margin: 0 0 16px; }
.button-link {
  display: inline-block;
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid var(--border);
}
.button-link.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #0f172a !important;
}
.button-link.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #0f172a !important; }

/* signup conflict CTA — 인라인 alert + 액션 */
.signup-conflict {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
  background: rgba(250, 204, 21, 0.08);
  border: 1px solid rgba(250, 204, 21, 0.35);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
}
.signup-conflict button {
  background: var(--warning);
  color: #0f172a;
  border: none;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  margin-left: auto;
  min-height: 0;
}
.signup-conflict button:hover { filter: brightness(1.05); }

/* 한도 안내 — 액션 버튼 근처에 작은 글씨 */
.rate-hint {
  font-size: 11px;
  color: var(--muted);
  margin-top: 6px;
  text-align: center;
  line-height: 1.4;
}

/* 모바일에서 키보드 올라올 때 입력 영역이 가려지지 않도록
   focus된 input/textarea가 화면 중앙에 들어오도록 스크롤 기준점 확보 */
input:focus, select:focus, textarea:focus {
  scroll-margin-top: 80px;
  scroll-margin-bottom: 80px;
}

/* 데스크톱·태블릿에서 좁은 페이지가 휑하지 않도록 폼 max-width 가이드 */
.narrow-form { max-width: 720px; }

.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: -2px;
  margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.chip { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: rgba(74, 222, 128, 0.15); color: var(--success); }
.chip.missing { background: rgba(248, 113, 113, 0.15); color: var(--danger); }
.chip.tag { background: rgba(56, 189, 248, 0.12); color: var(--accent); }
.chip-row { display: flex; gap: 4px; flex-wrap: wrap; }

.difficulty { font-weight: 600; }
.difficulty.easy { color: var(--success); }
.difficulty.medium { color: var(--warning); }
.difficulty.hard { color: var(--danger); }

.prep-steps, .tips-list { margin: 4px 0 14px; padding-left: 22px; }
.prep-steps li { margin-bottom: 4px; line-height: 1.55; }
.tips-list { list-style: none; padding-left: 0; }
.tips-list li {
  margin-bottom: 6px;
  line-height: 1.55;
  padding: 8px 12px;
  background: rgba(56, 189, 248, 0.06);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
}
.plating {
  margin: 4px 0 14px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: 6px;
  line-height: 1.55;
  color: var(--text);
}

@media (max-width: 720px) {
  .modal-backdrop { padding: 8px !important; align-items: flex-end !important; }
  .modal {
    max-width: 100% !important;
    max-height: 92vh !important;
    border-radius: 14px 14px 8px 8px !important;
    padding: 18px !important;
  }
  .modal h2 { font-size: 19px !important; }
  .recipe-grid { grid-template-columns: 1fr !important; gap: 10px !important; }
  .recipe-card { padding: 14px !important; }
  .card-actions button { min-height: 42px; font-size: 14px; }
  .dropzone { padding: 28px 14px !important; }
  table th, table td { padding: 8px 6px !important; font-size: 13px !important; }
  /* 가로 스크롤 강제 방지 */
  body, html { overflow-x: hidden; }
}

