/* =====================================================================
 * style.css — 시각 설정 블록: 색, 글꼴, 글자 크기, 선 굵기, 간격을 여기서 바꿉니다.
 * ===================================================================== */
:root {
  /* 색 */
  --ink: #000000;          /* 글자·선 (로고 잉크와 같은 순수 검정) */
  --paper: #ffffff;        /* 바탕 */
  --surface: #eff1f3;      /* 입력칸·목록 행 바탕 */
  --rule: #cdd2d7;         /* 구분선 */
  --muted: #59626b;        /* 보조 글자 */
  --signal: #ffd60a;       /* 강조: 야간 러닝 반사조끼 노랑 (1위 기록, 포커스) */
  --danger: #c4161c;       /* 삭제·오류 */
  --ok: #157f3b;           /* 검산 일치 */
  --gold: #e0b000; --silver: #b3b9bf; --bronze: #c07a43;   /* 상위 3위 메달 */

  /* 글꼴 */
  --font-num: 'Barlow Condensed', 'IBM Plex Sans KR', system-ui, sans-serif;
  --font-text: 'IBM Plex Sans KR', 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif;

  /* 글자 크기 */
  --fs-body: 16px;
  --fs-small: 13px;
  --fs-h1: 26px;
  --fs-h2: 18px;
  --fs-time: 26px;         /* 랭킹 표의 기록 시간 */
  --fs-leader-time: clamp(34px, 9.5vw, 52px);  /* 1위 기록 시간 (화면 폭에 비례, 최소~최대) */
  --fs-rank-no: 22px;      /* 순위 숫자 */
  --fs-sub-num: 18px;      /* 랭킹 표의 1km당 시간·거리 */
  --fs-field-num: 28px;    /* 입력 화면의 숫자 칸 */

  /* 선 굵기 */
  --line-rule: 1px;        /* 일반 구분선 */
  --line-strong: 3px;      /* 표 머리줄, 강조선 */
  --line-focus: 3px;       /* 키보드 포커스 테두리 */
  --line-leader: 0.16em;   /* 1위 시간 아래 노란 결승 테이프 굵기 (글자 크기 대비) */

  /* 크기·간격 */
  --page-max: 680px;
  --pad: 20px;
  --radius-btn: 999px;
  --radius-field: 10px;
  --logo-size: min(70vw, 300px);
  --medal-size: 32px;
  --thumb-size: 56px;      /* 홈 목록 썸네일 */
  --thumb-radius: 8px;
  --route-img-max: 520px;  /* 랭킹 상단 경로 이미지 최대 폭 */
  --route-img-radius: 12px;
  --img-preview-size: 132px; /* 회차 만들기 화면의 이미지 미리보기 */
  --seg-width: 66px;       /* 시·분·초 입력칸 폭 */
  --dist-width: 128px;     /* 거리 입력칸 폭 */
  --cell-pad-x: 6px;       /* 랭킹 표 칸 좌우 여백 */
}
@media (max-width: 420px) {
  :root { --pad: 16px; --fs-time: 22px; --fs-rank-no: 20px; --medal-size: 28px; --cell-pad-x: 4px; }
}
@media (max-width: 380px) {   /* 360px급 소형 화면 */
  :root { --pad: 12px; --fs-time: 20px; --fs-leader-time: 30px; --fs-sub-num: 16px; --fs-rank-no: 18px; --medal-size: 26px; --cell-pad-x: 3px; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #ffffff; --paper: #0d0f12; --surface: #1b1f24; --rule: #353b42;
    --muted: #a3acb5; --danger: #ff5a5f; --ok: #4cc777;
  }
  .logo { filter: invert(1); }
}

/* ---------------- 기본 ---------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(72px + env(safe-area-inset-top, 0px)); }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 var(--fs-body)/1.55 var(--font-text);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
button, input { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: var(--line-focus) solid var(--signal); outline-offset: 2px; box-shadow: 0 0 0 calc(var(--line-focus) + 2px) var(--ink); }
[hidden] { display: none !important; }   /* display 지정보다 숨김을 우선 */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: var(--page-max); margin: 0 auto; padding: 12px var(--pad);
  background: var(--paper);
}
.topbar .left, .topbar .right { display: flex; align-items: center; gap: 8px; min-height: 40px; }
main { max-width: var(--page-max); margin: 0 auto; padding: 0 var(--pad) 64px; }

/* ---------------- 버튼 ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 18px; border-radius: var(--radius-btn);
  border: 2px solid var(--ink); background: var(--ink); color: var(--paper);
  font-weight: 700; font-size: 15px; text-decoration: none; cursor: pointer;
}
.btn.ghost { background: transparent; color: var(--ink); }
.btn.link { border-color: transparent; background: transparent; color: var(--ink); padding: 8px 4px; font-weight: 500; }
.btn.danger { border-color: var(--danger); background: transparent; color: var(--danger); min-height: 30px; padding: 3px 8px; font-size: 12px; border-width: 1.5px; }
.btn.big { width: 100%; min-height: 64px; font-size: 18px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.admin-tag { font-size: var(--fs-small); font-weight: 700; padding: 2px 8px; background: var(--signal); color: #000; border-radius: 4px; }

/* ---------------- 첫 화면 ---------------- */
.hero { text-align: center; padding: 8px 0 28px; }
.logo { width: var(--logo-size); height: auto; display: block; margin: 0 auto; }
.hero h1 { margin: 12px 0 0; font-size: var(--fs-h1); font-weight: 700; letter-spacing: -0.01em; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0 10px; }
.section-head h2 { margin: 0; font-size: var(--fs-h2); }

.round-list { list-style: none; margin: 0; padding: 0; border-top: var(--line-strong) solid var(--ink); }
.round-list li { border-bottom: var(--line-rule) solid var(--rule); }
.round-list a {
  display: grid; grid-template-columns: var(--thumb-size) 1fr auto; align-items: center; column-gap: 14px; row-gap: 2px;
  padding: 14px 2px; text-decoration: none;
}
.round-list .thumb-sq { grid-row: 1 / span 2; grid-column: 1; }
.round-list .title { grid-column: 2; align-self: end; font-weight: 700; font-size: 17px; line-height: 1.3; }
.round-list .meta { grid-column: 2; align-self: start; color: var(--muted); font-size: var(--fs-small); }
.round-list .count { grid-row: 1 / span 2; grid-column: 3; font: italic 700 24px/1 var(--font-num); white-space: nowrap; }
.thumb-sq {
  display: grid; place-items: center; width: var(--thumb-size); height: var(--thumb-size);
  border-radius: var(--thumb-radius); object-fit: cover; background: var(--surface); color: var(--muted);
}
.thumb-none svg { width: 62%; height: 62%; }   /* 이미지 없는 회차의 자리표시 아이콘 */
.round-list .count small { font: 400 var(--fs-small) var(--font-text); color: var(--muted); margin-left: 2px; }

.admin-panel { margin: 0 0 28px; padding: 16px; background: var(--surface); border-radius: var(--radius-field); }
.admin-panel h2 { margin: 0 0 10px; font-size: 16px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > * { flex: 1 1 160px; }

/* ---------------- 입력칸 ---------------- */
.field { display: block; margin: 0 0 14px; }
.field .lab { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; margin-bottom: 6px; }
input[type=text], input[type=password], input[type=date], input[type=number], input[inputmode] {
  width: 100%; min-height: 46px; padding: 10px 12px;
  background: var(--paper); border: 2px solid var(--rule); border-radius: var(--radius-field);
}
.admin-panel input { background: var(--paper); }
input:focus { border-color: var(--ink); outline: none; }

.seg { display: flex; align-items: flex-end; gap: 6px; flex-wrap: wrap; }
.seg input { flex: none; width: var(--seg-width); text-align: center; font: italic 700 var(--fs-field-num)/1 var(--font-num); padding: 6px 4px; }
.seg .unit { font-size: var(--fs-small); color: var(--muted); padding-bottom: 12px; margin-right: 6px; white-space: nowrap; }
.seg input[name=dist] { width: var(--dist-width); }
.badge { font-size: 12px; font-weight: 500; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--rule); color: var(--muted); }
.badge.ocr { border-color: var(--ink); color: var(--ink); }
.badge.calc { border-color: var(--muted); }
.badge.missing { border-color: var(--danger); color: var(--danger); }
.badge.edited { background: var(--surface); }

/* ---------------- 랭킹 ---------------- */
.round-head h1 { margin: 4px 0 2px; font-size: var(--fs-h1); line-height: 1.25; }
.round-head p { margin: 0 0 18px; color: var(--muted); font-size: var(--fs-small); }
.route-img {
  display: block; width: 100%; max-width: var(--route-img-max); height: auto; aspect-ratio: 1 / 1; object-fit: cover;
  margin: 0 0 16px; border-radius: var(--route-img-radius); border: var(--line-rule) solid var(--rule); background: var(--surface);
}
.places { display: flex; flex-wrap: wrap; gap: 4px 18px; margin: -10px 0 16px; font-size: 14px; }
.places div { display: flex; gap: 6px; }
.places dt { color: var(--muted); }
.places dd { margin: 0; font-weight: 500; }
.btn.small { min-height: 34px; padding: 4px 14px; font-size: 14px; }
.round-head .btn.small { margin: 0 0 18px; }

/* ---------------- 회차 만들기·수정 ---------------- */
.lab small { font-weight: 400; font-size: 12px; color: var(--muted); }
.img-field { display: grid; grid-template-columns: var(--img-preview-size) 1fr; gap: 16px; align-items: start; margin: 4px 0 22px; }
.img-preview {
  width: var(--img-preview-size); aspect-ratio: 1 / 1; overflow: hidden; display: grid; place-items: center;
  border-radius: var(--thumb-radius); border: var(--line-rule) solid var(--rule); background: var(--surface); color: var(--muted);
}
.img-preview img { display: block; width: 100%; height: 100%; object-fit: cover; }
.img-preview.busy { opacity: .45; }
.img-empty { display: grid; justify-items: center; gap: 2px; font-size: 12px; }
.img-empty svg { width: 46px; height: 46px; }
.img-tools .lab { display: block; font-weight: 700; font-size: 15px; }
.img-tools .hint { margin: 4px 0 10px; }
.img-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.img-actions .btn.danger { min-height: 40px; padding: 8px 14px; font-size: 14px; }
.fit { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.fit label { position: relative; cursor: pointer; }
.fit input { position: absolute; opacity: 0; inset: 0; }
.fit span { display: inline-block; padding: 6px 12px; border: 1.5px solid var(--rule); border-radius: 999px; font-size: 13px; }
.fit input:checked + span { border-color: var(--ink); background: var(--ink); color: var(--paper); }
.fit input:focus-visible + span { outline: var(--line-focus) solid var(--signal); outline-offset: 2px; }
.date-row { display: flex; align-items: center; gap: 8px; }
.date-row input { flex: 1; }
.danger-zone { margin-top: 40px; padding-top: 18px; border-top: var(--line-rule) solid var(--rule); }
.danger-zone h2 { margin: 0 0 6px; font-size: 16px; }
.danger-zone p { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.btn.danger-solid { border-color: var(--danger); background: var(--danger); color: #fff; }
@media (max-width: 420px) {
  :root { --img-preview-size: 200px; }
  .img-field { grid-template-columns: 1fr; }
}

.rank-wrap { overflow-x: auto; }
table.rank { width: 100%; border-collapse: collapse; }
.rank th {
  text-align: left; font-size: var(--fs-small); font-weight: 500; color: var(--muted);
  padding: 6px var(--cell-pad-x); border-bottom: var(--line-strong) solid var(--ink);
  word-break: keep-all; line-height: 1.25; vertical-align: bottom;
}
.rank td { padding: 12px var(--cell-pad-x); border-bottom: var(--line-rule) solid var(--rule); vertical-align: middle; }
.rank .c-rank { width: calc(var(--medal-size) + 2 * var(--cell-pad-x)); }
.rank .c-num { white-space: nowrap; }
.rank td.c-time { font: italic 800 var(--fs-time)/1 var(--font-num); letter-spacing: .01em; }
.rank td.c-pace, .rank td.c-dist { font: italic 600 var(--fs-sub-num)/1 var(--font-num); }
.rank td.c-dist small, .rank td.c-pace small { font: 400 12px var(--font-text); color: var(--muted); margin-left: 1px; }
.rank td.c-name { font-weight: 500; font-size: 15px; line-height: 1.3; min-width: 4.2em; word-break: keep-all; overflow-wrap: anywhere; }
.rank td.c-name .btn.danger { display: flex; margin-top: 6px; }
.rank td.c-del { width: 1%; text-align: right; }

.medal {
  display: inline-grid; place-items: center; width: var(--medal-size); height: var(--medal-size);
  font: italic 800 var(--fs-rank-no)/1 var(--font-num);
}
.medal.m1, .medal.m2, .medal.m3 { border-radius: 50%; color: #000; font-size: calc(var(--fs-rank-no) - 4px); }
.medal.m1 { background: var(--gold); } .medal.m2 { background: var(--silver); } .medal.m3 { background: var(--bronze); }

/* 1위 행: 결승선 시계처럼 크게 */
.rank tr.leader td { padding-top: 18px; padding-bottom: 18px; }
.rank tr.leader td.c-time { font-size: var(--fs-leader-time); }
.rank tr.leader td.c-time span {
  text-decoration: underline var(--signal); text-decoration-thickness: var(--line-leader);
  text-underline-offset: 0.1em; text-decoration-skip-ink: none;
}
.rank tr.fresh { animation: fresh 2.4s ease-out 1; }
@keyframes fresh { from { background: var(--signal); } to { background: transparent; } }

.empty { padding: 28px 4px; color: var(--muted); border-top: var(--line-strong) solid var(--ink); }

/* ---------------- 입력 화면 ---------------- */
.picker { margin: 8px 0 20px; }
.picker input[type=file] { position: absolute; opacity: 0; width: 1px; height: 1px; }
.progress { margin: 14px 0; }
.progress .bar { height: 6px; background: var(--surface); border-radius: 3px; overflow: hidden; }
.progress .bar i { display: block; height: 100%; width: 0; background: var(--ink); transition: width .2s; }
.progress p { margin: 6px 0 0; font-size: var(--fs-small); color: var(--muted); }

.review { display: grid; grid-template-columns: 116px 1fr; gap: 18px; align-items: start; }
.review .thumb { width: 116px; border: var(--line-rule) solid var(--rule); border-radius: 8px; display: block; }
@media (max-width: 420px) {
  .review { grid-template-columns: 1fr; }
  .review .thumb { width: 96px; }
}
.check { margin: 6px 0 18px; padding: 10px 12px; border-left: var(--line-strong) solid var(--rule); font-size: 14px; }
.check.ok { border-left-color: var(--ok); }
.check.warn { border-left-color: var(--danger); }
.check .btn { margin-top: 6px; }
.hint { color: var(--muted); font-size: var(--fs-small); margin: 0 0 14px; }

/* ---------------- 알림·대화상자 ---------------- */
.notice { margin: 12px 0; padding: 12px 14px; border-radius: var(--radius-field); background: var(--surface); font-size: 14px; }
.notice.error { border: 2px solid var(--danger); background: transparent; }
#toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 12px;
  background: var(--ink); color: var(--paper); font-size: 14px; z-index: 20;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
#toast.show { opacity: 1; }
dialog {
  width: min(92vw, 380px); border: 2px solid var(--ink); border-radius: 16px; padding: 22px;
  background: var(--paper); color: var(--ink);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h2 { margin: 0 0 14px; font-size: 20px; }
dialog .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }

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