/* ==========================================================================
   달린이 기록일지 — 디자인 시스템
   라이트/다크 모두 대응. 색·간격·라운드는 전부 아래 토큰으로만 조절한다.
   ========================================================================== */

:root {
  --brand-1: #106e85;
  --brand-2: #3c91a3;
  --brand-soft: rgba(16, 110, 133, 0.1);
  --brand-ring: rgba(16, 110, 133, 0.35);

  --bg: #f5f6fa;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-hover: #f1f5f9;

  --text: #0f172a;
  --text-muted: #64748b;
  --text-faint: #94a3b8;

  --border: #e6e8ee;
  --border-strong: #d5d9e2;

  --success: #059669;
  --success-soft: #ecfdf5;
  --success-border: #a7f3d0;
  --warning-bg: #fffbeb;
  --warning-text: #92400e;
  --warning-border: #fde68a;

  --gold: #f59e0b;
  --silver: #94a3b8;
  --bronze: #b45309;

  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 20px;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 4px 16px -4px rgba(15, 23, 42, 0.1), 0 2px 6px -2px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 18px 40px -18px rgba(15, 23, 42, 0.28);

  --header-h: 128px;
  --bg-translucent: rgba(245, 246, 250, 0.82);
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand-1: #2dd4bf;
    --brand-2: #22d3ee;
    --brand-soft: rgba(45, 212, 191, 0.16);
    --brand-ring: rgba(45, 212, 191, 0.45);

    --bg: #0b0e17;
    --bg-elevated: #121724;
    --surface: #141a29;
    --surface-2: #171e2f;
    --surface-hover: #1c2437;

    --text: #eef2f9;
    --text-muted: #99a3b8;
    --text-faint: #6b7688;

    --border: #232b3d;
    --border-strong: #2f3950;

    --success: #34d399;
    --success-soft: rgba(52, 211, 153, 0.12);
    --success-border: rgba(52, 211, 153, 0.35);
    --warning-bg: rgba(251, 191, 36, 0.12);
    --warning-text: #fcd34d;
    --warning-border: rgba(251, 191, 36, 0.32);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 6px 20px -6px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 22px 48px -20px rgba(0, 0, 0, 0.8);

    --bg-translucent: rgba(11, 14, 23, 0.8);
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Malgun Gothic", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* 상단 배경 글로우 --------------------------------------------------------- */
.app-glow {
  position: fixed;
  inset: -20% -10% auto -10%;
  height: 420px;
  background:
    radial-gradient(60% 60% at 20% 0%, var(--brand-soft), transparent 70%),
    radial-gradient(50% 50% at 85% 10%, rgba(124, 58, 237, 0.12), transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* 헤더 -------------------------------------------------------------------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: max(14px, env(safe-area-inset-top)) 0 0;
  background: var(--bg-translucent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}

.app-header-inner,
.tabs,
.container {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding-inline: 18px;
}

.app-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  flex: none;
  border-radius: 13px;
  overflow: hidden;
  box-shadow: 0 6px 16px -6px var(--brand-ring);
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-text strong {
  font-size: 1.02rem;
  font-weight: 750;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.brand-text span {
  font-size: 0.74rem;
  color: var(--text-faint);
  white-space: nowrap;
}

/* 이름 칩 ----------------------------------------------------------------- */
.identity-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: none;
  padding: 5px 10px 5px 5px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  font-size: 0.8rem;
}

.identity-avatar {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
}

.identity-label strong {
  font-weight: 650;
}

.link-button {
  border: none;
  background: none;
  padding: 0 2px;
  color: var(--brand-1);
  font: inherit;
  font-size: 0.76rem;
  font-weight: 650;
  cursor: pointer;
  border-radius: 6px;
}

.link-button:hover {
  opacity: 0.75;
}

.manual-entry-link {
  display: block;
  width: 100%;
  margin-top: 4px;
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* 탭 ---------------------------------------------------------------------- */
.tabs {
  display: flex;
  gap: 4px;
  padding-block: 12px 10px;
}

.tab-button {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 6px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease, transform 0.12s ease;
}

.tab-button svg {
  width: 16px;
  height: 16px;
  opacity: 0.85;
}

.tab-button:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.tab-button:active {
  transform: scale(0.97);
}

.tab-button.active {
  background: var(--surface);
  border-color: var(--border);
  color: var(--brand-1);
  box-shadow: var(--shadow-sm);
}

/* 본문 -------------------------------------------------------------------- */
.container {
  position: relative;
  z-index: 1;
  padding-top: 20px;
  padding-bottom: calc(56px + env(safe-area-inset-bottom));
}

section {
  animation: rise 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

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

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

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: -0.025em;
}

h2 {
  font-size: 1.3rem;
  font-weight: 750;
}

.block-title {
  margin: 26px 0 10px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.pill {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-1);
  font-size: 0.72rem;
  font-weight: 650;
}

.hint-text {
  margin: 16px 4px 0;
  font-size: 0.78rem;
  line-height: 1.6;
  color: var(--text-faint);
}

.hint-text b {
  color: var(--text-muted);
  font-weight: 650;
}

.hint-inline {
  margin: -4px 2px 10px;
}

.row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.icon-button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.icon-button:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.icon-button.danger {
  color: #dc2626;
  border-color: rgba(220, 38, 38, 0.3);
}

.icon-button.danger:hover {
  background: rgba(220, 38, 38, 0.08);
}

/* 카드 -------------------------------------------------------------------- */
.card {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.card + .card {
  margin-top: 14px;
}

/* 폼 ---------------------------------------------------------------------- */
form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field-label {
  font-size: 0.78rem;
  font-weight: 650;
  color: var(--text-muted);
}

.confirm-owner {
  padding: 12px 14px;
  margin-bottom: 16px;
  border: 1px solid var(--brand-ring);
  border-radius: var(--radius);
  background: var(--brand-soft);
}

.confirm-owner .field-label {
  color: var(--brand-1);
}

.confirm-owner select {
  background-color: var(--surface);
  border-color: var(--brand-ring);
  font-weight: 650;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

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

.select-row {
  display: flex;
  gap: 10px;
}

.select-row .field {
  flex: 1;
}

input,
select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text);
  font: inherit;
  font-size: 0.94rem;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
  appearance: none;
}

select {
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
  cursor: pointer;
}

input:focus-visible,
select:focus-visible,
.tab-button:focus-visible,
.btn:focus-visible,
.link-button:focus-visible,
.dropzone:focus-within {
  outline: none;
  border-color: var(--brand-1);
  box-shadow: 0 0 0 3.5px var(--brand-ring);
}

input:disabled {
  background: var(--surface-2);
  color: var(--text-faint);
  cursor: not-allowed;
}

input[type="date"] {
  min-height: 44px;
}

/* 파일 업로드 드롭존 ------------------------------------------------------- */
.dropzone {
  position: relative;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 26px 18px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease;
}

.dropzone:hover {
  border-color: var(--brand-1);
  background: var(--brand-soft);
}

.dropzone-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: 4px;
  border-radius: 13px;
  background: var(--brand-soft);
  color: var(--brand-1);
}

.dropzone-icon svg {
  width: 22px;
  height: 22px;
}

.dropzone-title {
  font-size: 0.92rem;
  font-weight: 650;
}

.dropzone-hint {
  font-size: 0.76rem;
  color: var(--text-faint);
}

.dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: none;
  background: none;
  opacity: 0;
  cursor: pointer;
}

.shared-preview {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.shared-preview img {
  width: 100%;
  max-height: 340px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

/* 버튼 -------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.94rem;
  font-weight: 680;
  letter-spacing: -0.01em;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.18s ease, opacity 0.18s ease, background 0.18s ease;
}

.btn:active {
  transform: translateY(1px) scale(0.995);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  box-shadow: 0 10px 22px -12px var(--brand-ring);
}

.btn-primary:hover:not(:disabled) {
  box-shadow: 0 14px 28px -12px var(--brand-ring);
}

.btn-lg {
  padding: 14px 18px;
  font-size: 1rem;
}

.btn-ghost {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text);
}

.button-row {
  display: flex;
  gap: 10px;
}

.button-row .btn {
  flex: 1;
}

/* 상태 메시지 / 배너 -------------------------------------------------------- */
.status {
  min-height: 1.2em;
  margin: 12px 2px 0;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.status:empty {
  display: none;
}

.banner {
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 0.84rem;
  line-height: 1.5;
}

.banner-warning {
  background: var(--warning-bg);
  color: var(--warning-text);
  border: 1px solid var(--warning-border);
}

/* 통계 카드 --------------------------------------------------------------- */
.stat-card.is-success {
  border-color: var(--success-border);
  background: var(--success-soft);
}

.stat-card-title {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0 0 14px;
  font-size: 0.82rem;
  font-weight: 650;
  color: var(--success);
}

.check-dot {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--success);
  color: #fff;
  font-size: 0.66rem;
  font-weight: 800;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.stat {
  text-align: center;
  min-width: 0;
}

.stat span {
  display: block;
  font-size: 1.12rem;
  font-weight: 760;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  overflow-wrap: anywhere;
}

.stat label {
  display: block;
  margin-top: 3px;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-faint);
}

/* 표 ---------------------------------------------------------------------- */
.table-card {
  padding: 4px 4px 2px;
  overflow: hidden;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
}

th,
td {
  padding: 11px 10px;
  text-align: right;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: var(--surface);
  color: var(--text-faint);
  font-size: 0.73rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  border-bottom: 1px solid var(--border);
}

tbody tr {
  border-bottom: 1px solid var(--border);
}

tbody tr:last-child {
  border-bottom: none;
}

tbody tr:hover {
  background: var(--surface-hover);
}

th:first-child,
td:first-child {
  text-align: left;
  padding-left: 14px;
}

th:last-child,
td:last-child {
  padding-right: 14px;
}

td:first-child {
  font-weight: 650;
  color: var(--text-muted);
}

/* 순위표: 이름 강조 + 상위 3인 메달 색 */
.rank-table td:nth-child(2) {
  text-align: left;
  font-weight: 650;
  color: var(--text);
}

.rank-table tbody tr:nth-child(-n + 3) td:first-child {
  color: transparent;
  position: relative;
}

.rank-table tbody tr:nth-child(-n + 3) td:first-child::after {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 0.95rem;
  color: initial;
}

.rank-table tbody tr:nth-child(1) td:first-child::after {
  content: "🥇";
}

.rank-table tbody tr:nth-child(2) td:first-child::after {
  content: "🥈";
}

.rank-table tbody tr:nth-child(3) td:first-child::after {
  content: "🥉";
}

.rank-table tbody tr:nth-child(1) td:nth-child(4) {
  color: var(--gold);
  font-weight: 750;
}

/* 거리 열은 순위 지표라 살짝 강조 */
.rank-table td:nth-child(4) {
  font-weight: 650;
  color: var(--text);
}
