/* 베이스 연습 — 공통 스타일 (모든 페이지에서 사용) */

:root {
  color-scheme: light dark;

  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #f1ece4;
  --raised: #ffffff;
  --border: #e3dbce;
  --text: #2a211b;
  --text-muted: #74675c;
  --accent: #f97316;
  --on-accent: #1f1206;
  --accent-text: #c2410c;
  --success-text: #15803d;
  --danger-text: #b91c1c;
  --focus: #2f7de1;
  --shadow: 0 1px 2px rgba(42, 33, 27, 0.05), 0 8px 24px rgba(42, 33, 27, 0.06);
  --radius: 16px;
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%2374675c' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  --font: -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', Pretendard, 'Noto Sans KR', 'Malgun Gothic',
    'Segoe UI', Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14110f;
    --surface: #1e1916;
    --surface-2: #2a231e;
    --raised: #3b322b;
    --border: #3a3029;
    --text: #f2ebe3;
    --text-muted: #a99b8e;
    --accent-text: #fb923c;
    --success-text: #4ade80;
    --danger-text: #f87171;
    --focus: #6aa8ff;
    --shadow: none;
    --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23a99b8e' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  }
}

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

/* 두 번 빠르게 눌러도 화면이 확대되지 않게 한다 (아이폰). 손가락 두 개로 벌리는 확대와 스크롤은 그대로 된다.
   지판·휴대폰 메뉴처럼 따로 스크롤되는 영역 안에는 바깥 설정이 이어지지 않아서 모든 요소에 준다. */
* {
  touch-action: manipulation;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  /* 한글은 단어 중간이 아니라 띄어쓰기에서 줄을 바꾼다 */
  word-break: keep-all;
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

h1,
h2,
h3,
p {
  margin: 0;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

a,
button,
label,
select {
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

/* ---------- 상단 바 ---------- */

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.app-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.brand__mark {
  flex: none;
  width: 28px;
  height: 28px;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.nav a {
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.nav a[aria-current='page'] {
  background: var(--surface-2);
  color: var(--text);
}

@media (hover: hover) {
  .nav a:hover {
    background: var(--surface-2);
    color: var(--text);
  }
}

/* ---------- 본문 ---------- */

.page {
  display: grid;
  gap: 16px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 16px 56px;
}

.page-head h1 {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.page-head p {
  margin-top: 6px;
  color: var(--text-muted);
}

.panel {
  min-width: 0;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- 설정 패널 ---------- */

/* 설정은 묶음(.settings__group) 단위로 줄바꿈된다. */
.settings,
.settings__fields {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 32px;
}

/* 한꺼번에 비활성화할 수 있게 묶는 fieldset */
.settings__fields {
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.settings__fields:disabled {
  opacity: 0.5;
}

.settings__group {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 16px 24px;
}

.toggles {
  display: flex;
  align-items: center;
  gap: 18px;
  height: 38px;
}

/* ---------- 입력 요소 ---------- */

.field {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.field__label {
  display: block;
  margin-bottom: 6px;
  padding: 0;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
}

/* 라디오 버튼을 이어 붙인 선택 버튼 */
.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border-radius: 11px;
}

.segmented label {
  position: relative;
  display: block;
}

.segmented input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.segmented span {
  display: block;
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 700;
  line-height: 20px;
  white-space: nowrap;
  transition: background-color 0.15s, color 0.15s;
}

.segmented input:checked + span {
  background: var(--raised);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14);
}

.segmented input:focus-visible + span {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.select {
  height: 38px;
  padding: 0 34px 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface) var(--chevron) no-repeat right 12px center / 12px 8px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.input {
  width: 72px;
  height: 38px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.input:disabled {
  opacity: 0.45;
}

/* 아이폰은 글자가 16px 보다 작은 입력 칸을 누르면 화면을 확대한다 */
@media (pointer: coarse) {
  .select,
  .input {
    font-size: 16px;
  }
}

/* 숫자 입력 + 단위 (예: [30] 초) */
.unit-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 700;
}

/* 체크박스를 스위치 모양으로 */
.toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.toggle input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.toggle__track {
  position: relative;
  flex: none;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: var(--border);
  transition: background-color 0.15s;
}

.toggle__track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s;
}

.toggle input:checked + .toggle__track {
  background: var(--accent);
}

.toggle input:checked + .toggle__track::after {
  transform: translateX(16px);
}

.toggle input:focus-visible + .toggle__track {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.toggle input:disabled + .toggle__track {
  opacity: 0.45;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

@media (hover: hover) {
  .btn:hover:not(:disabled) {
    background: var(--surface-2);
  }
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

@media (hover: hover) {
  .btn--primary:hover:not(:disabled) {
    background: var(--accent);
    filter: brightness(1.06);
  }
}

.btn--lg {
  height: 44px;
  padding: 0 22px;
  font-size: 15px;
}

/* 새 버전 안내 (js/pwa.js) */
.update-bar {
  position: fixed;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 50%;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100% - 32px);
  padding: 8px 6px 8px 18px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  transform: translateX(-50%);
}

.update-bar__close {
  width: 36px;
  height: 36px;
  margin-left: -6px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--text-muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

@media (hover: hover) {
  .update-bar__close:hover {
    background: var(--surface-2);
  }
}

@media (max-width: 640px) {
  /* 휴대폰: 제목 아래 한 줄에 메뉴, 넘치면 가로로 넘겨 본다 */
  .app-header__inner {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 16px 8px;
  }

  .brand {
    white-space: nowrap;
  }

  .nav {
    flex-wrap: nowrap;
    width: calc(100% + 32px);
    margin: 0 -16px;
    padding: 0 12px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .nav::-webkit-scrollbar {
    display: none;
  }

  .nav {
    gap: 0;
  }

  /* 메뉴 다섯 개가 360px 화면에도 한 줄에 다 보이게 */
  .nav a {
    flex: none;
    padding: 6px 6px;
    font-size: 13px;
    white-space: nowrap;
  }

  .page {
    padding-top: 20px;
  }

  .page-head h1 {
    font-size: 24px;
  }

  /* 휴대폰에서는 지판이 먼저 보이도록 설정을 맨 아래로 */
  .settings {
    order: 1;
  }

  .settings,
  .settings__fields,
  .settings__group {
    gap: 14px 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}
