/* ============================================================
   Karaoke Key Master — iOS App Design System
   Apple HIG 기반: Large Title, Inset Grouped List, Segmented
   Control, Tab Bar, 시스템 다크모드 대응
   ============================================================ */

:root {
  /* iOS Light palette */
  --bg: #f2f2f7;                 /* systemGroupedBackground */
  --bg-elevated: #ffffff;        /* secondarySystemGroupedBackground */
  --bg-tertiary: #e5e5ea;
  --label: #000000;
  --label-secondary: rgba(60, 60, 67, 0.6);
  --label-tertiary: rgba(60, 60, 67, 0.3);
  --separator: rgba(60, 60, 67, 0.12);
  --tint: #007aff;               /* systemBlue */
  --tint-soft: rgba(0, 122, 255, 0.12);
  --green: #34c759;
  --orange: #ff9500;
  --red: #ff3b30;
  --purple: #af52de;
  --pink: #ff2d55;
  --fill: rgba(120, 120, 128, 0.16);
  --fill-secondary: rgba(120, 120, 128, 0.08);
  --nav-blur-bg: rgba(242, 242, 247, 0.78);
  --tabbar-blur-bg: rgba(249, 249, 249, 0.82);
  --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  --key-white: #ffffff;
  --key-black: #2c2c2e;
  --key-border: #d1d1d6;
}

html[data-theme="dark"] {
  --bg: #000000;
  --bg-elevated: #1c1c1e;
  --bg-tertiary: #2c2c2e;
  --label: #ffffff;
  --label-secondary: rgba(235, 235, 245, 0.6);
  --label-tertiary: rgba(235, 235, 245, 0.3);
  --separator: rgba(84, 84, 88, 0.6);
  --tint: #0a84ff;
  --tint-soft: rgba(10, 132, 255, 0.18);
  --green: #30d158;
  --orange: #ff9f0a;
  --red: #ff453a;
  --purple: #bf5af2;
  --pink: #ff375f;
  --fill: rgba(120, 120, 128, 0.36);
  --fill-secondary: rgba(120, 120, 128, 0.18);
  --nav-blur-bg: rgba(0, 0, 0, 0.72);
  --tabbar-blur-bg: rgba(22, 22, 24, 0.82);
  --card-shadow: none;
  --key-white: #e8e8ed;
  --key-black: #1c1c1e;
  --key-border: #3a3a3c;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--label);
  overflow-x: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
  transition: background-color 0.25s ease, color 0.25s ease;
}

/* ── App frame: 모바일 앱 폭으로 중앙 정렬 ── */
.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ── Navigation bar (blur) ── */
.nav-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  background: var(--nav-blur-bg);
  border-bottom: 0.5px solid var(--separator);
  padding-top: env(safe-area-inset-top);
}
.nav-bar-inner {
  max-width: 640px;
  margin: 0 auto;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}
.nav-title {
  font-size: 17px;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.2s ease;
}
body.scrolled .nav-title { opacity: 1; }
.nav-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--fill-secondary);
  color: var(--tint);
  font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.icon-btn:active { opacity: 0.6; }

/* ── Large title ── */
.large-title {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: 0.2px;
  margin: 10px 0 2px;
}
.large-subtitle {
  color: var(--label-secondary);
  font-size: 15px;
  margin: 0 0 18px;
}

/* ── Section header (iOS grouped list style) ── */
.section-header {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--label-secondary);
  margin: 26px 4px 8px;
}
.section-footer {
  font-size: 13px;
  color: var(--label-secondary);
  margin: 8px 4px 0;
}

/* ── Cards (inset grouped) ── */
.card {
  background: var(--bg-elevated);
  border-radius: 14px;
  box-shadow: var(--card-shadow);
  overflow: hidden;
}
.card + .card { margin-top: 16px; }
.card-pad { padding: 16px; }

/* rows inside a card, like Settings cells */
.cell {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  min-height: 44px;
  position: relative;
}
.cell + .cell::before {
  content: "";
  position: absolute;
  left: 16px; right: 0; top: 0;
  border-top: 0.5px solid var(--separator);
}
.cell-icon {
  width: 30px; height: 30px;
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  color: #fff;
  flex-shrink: 0;
}
.cell-body { flex: 1; min-width: 0; }
.cell-title { font-size: 17px; }
.cell-sub { font-size: 13px; color: var(--label-secondary); }
.cell-value { font-size: 17px; color: var(--label-secondary); flex-shrink: 0; }

/* ── Inputs ── */
.field {
  width: 100%;
  border: none;
  background: var(--fill-secondary);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 17px;
  color: var(--label);
  font-family: inherit;
}
.field:focus { outline: 2px solid var(--tint); outline-offset: 0; }
.field::placeholder { color: var(--label-tertiary); }

select.field { appearance: none; -webkit-appearance: none; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 18px;
  border: none;
  border-radius: 12px;
  font-size: 17px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
}
.btn:active { transform: scale(0.98); opacity: 0.85; }
.btn-primary { background: var(--tint); color: #fff; }
.btn-secondary { background: var(--tint-soft); color: var(--tint); }
.btn-danger { background: var(--red); color: #fff; }
.btn-sm { width: auto; padding: 8px 14px; font-size: 15px; border-radius: 10px; }
.btn[disabled] { opacity: 0.4; pointer-events: none; }

/* ── Segmented control ── */
.segmented {
  display: flex;
  background: var(--fill);
  border-radius: 9px;
  padding: 2px;
  margin: 4px 0 14px;
}
.segmented button {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--label);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  padding: 6px 0;
  border-radius: 7px;
  cursor: pointer;
}
.segmented button.active {
  background: var(--bg-elevated);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
  font-weight: 600;
}

/* ── Result verdict banner ── */
.verdict {
  border-radius: 14px;
  padding: 18px 16px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.verdict.ok      { background: color-mix(in srgb, var(--green) 14%, var(--bg-elevated)); }
.verdict.warn    { background: color-mix(in srgb, var(--orange) 14%, var(--bg-elevated)); }
.verdict.danger  { background: color-mix(in srgb, var(--red) 14%, var(--bg-elevated)); }
.verdict .v-icon { font-size: 30px; line-height: 1; }
.verdict .v-title { font-size: 17px; font-weight: 700; margin: 0 0 2px; }
.verdict .v-sub { font-size: 14px; color: var(--label-secondary); margin: 0; }

.keychip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--tint);
  color: #fff;
  font-weight: 700;
  font-size: 22px;
  border-radius: 12px;
  padding: 8px 16px;
}

/* ── Stat grid ── */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.stat {
  background: var(--fill-secondary);
  border-radius: 12px;
  padding: 12px 14px;
}
.stat .s-label { font-size: 12px; font-weight: 600; color: var(--label-secondary); text-transform: uppercase; letter-spacing: 0.4px; }
.stat .s-value { font-size: 20px; font-weight: 700; margin-top: 2px; }
.stat .s-sub { font-size: 12px; color: var(--label-secondary); }

/* ── Piano ── */
.piano-wrap { overflow-x: auto; padding: 6px 0 2px; }
.piano {
  position: relative;
  height: 96px;
  display: flex;
  min-width: 480px;
}
.pk-white {
  flex: 1;
  background: var(--key-white);
  border: 0.5px solid var(--key-border);
  border-radius: 0 0 4px 4px;
  position: relative;
}
.pk-black {
  position: absolute;
  top: 0;
  width: 60%;
  height: 58%;
  background: var(--key-black);
  border-radius: 0 0 3px 3px;
  z-index: 2;
}
.pk-white.in-user { background: color-mix(in srgb, var(--tint) 26%, var(--key-white)); }
.pk-black.in-user { background: color-mix(in srgb, var(--tint) 55%, var(--key-black)); }
.pk-white.song-max { background: var(--pink); }
.pk-black.song-max { background: var(--pink); }
.pk-white.user-max { background: var(--tint); }
.pk-black.user-max { background: var(--tint); }
.pk-label {
  position: absolute;
  bottom: 3px; left: 0; right: 0;
  font-size: 9px;
  text-align: center;
  color: rgba(0,0,0,0.45);
  pointer-events: none;
}
.piano-legend { display: flex; gap: 16px; margin-top: 10px; font-size: 12px; color: var(--label-secondary); flex-wrap: wrap; }
.piano-legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ── Range test (mic) ── */
.pitch-display {
  text-align: center;
  padding: 22px 0 10px;
}
.pitch-note { font-size: 52px; font-weight: 800; letter-spacing: 1px; line-height: 1; }
.pitch-korean { font-size: 15px; color: var(--label-secondary); margin-top: 6px; }
.pitch-meter {
  height: 6px;
  background: var(--fill);
  border-radius: 3px;
  margin: 18px 16px 4px;
  overflow: hidden;
}
.pitch-meter > div {
  height: 100%;
  width: 0%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--green), var(--orange), var(--red));
  transition: width 0.1s linear;
}
.rec-dot {
  display: inline-block;
  width: 8px; height: 8px;
  background: var(--red);
  border-radius: 50%;
  margin-right: 6px;
  animation: blink 1s infinite;
}
@keyframes blink { 50% { opacity: 0.2; } }

/* ── Song list rows ── */
.song-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  position: relative;
  cursor: pointer;
}
.song-row:active { background: var(--fill-secondary); }
.song-row + .song-row::before {
  content: "";
  position: absolute;
  left: 62px; right: 0; top: 0;
  border-top: 0.5px solid var(--separator);
}
.song-art {
  width: 38px; height: 38px;
  border-radius: 9px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px;
  color: #fff;
  font-weight: 700;
}
.song-meta { flex: 1; min-width: 0; }
.song-name { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song-artist { font-size: 13px; color: var(--label-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song-badge {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 700;
  border-radius: 7px;
  padding: 4px 8px;
}
.song-badge.ok { background: color-mix(in srgb, var(--green) 18%, transparent); color: var(--green); }
.song-badge.warn { background: color-mix(in srgb, var(--orange) 18%, transparent); color: var(--orange); }
.song-badge.danger { background: color-mix(in srgb, var(--red) 16%, transparent); color: var(--red); }

/* ── Tag chip ── */
.chip {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: var(--label-secondary);
  background: var(--fill-secondary);
  border-radius: 6px;
  padding: 2px 7px;
  margin-left: 6px;
  vertical-align: 1px;
}

/* ── Tab bar ── */
.tab-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 60;
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  background: var(--tabbar-blur-bg);
  border-top: 0.5px solid var(--separator);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab-bar-inner {
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  height: 56px;
}
.tab-item {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--label-secondary);
  font-family: inherit;
  font-size: 10px;
  font-weight: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
}
.tab-item .t-icon { font-size: 22px; line-height: 1; }
.tab-item.active { color: var(--tint); }

/* ── Pages ── */
.page { display: none; animation: pageIn 0.25s ease; }
.page.active { display: block; }
@keyframes pageIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Spinner ── */
.spinner {
  width: 22px; height: 22px;
  border: 2.5px solid var(--fill);
  border-top-color: var(--tint);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Autocomplete dropdown ── */
.ac-wrap { position: relative; }
.ac-list {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  background: var(--bg-elevated);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
  z-index: 40;
  overflow: hidden;
  max-height: 260px;
  overflow-y: auto;
}
.ac-item { padding: 11px 14px; cursor: pointer; font-size: 15px; }
.ac-item:active, .ac-item:hover { background: var(--fill-secondary); }
.ac-item .a-artist { color: var(--label-secondary); font-size: 13px; }

/* ── Footer ── */
.app-footer {
  text-align: center;
  font-size: 12px;
  color: var(--label-tertiary);
  padding: 30px 0 12px;
}
.app-footer a { color: var(--label-secondary); text-decoration: none; margin: 0 6px; }

/* ── AdSense 광고 안전장치 ──
   광고 iframe이 고정 폭을 지정해도 화면을 넘지 않게 하고,
   채워지지 않은(unfilled) 광고는 빈 공간을 차지하지 않게 숨김 */
.ad-unit { overflow-x: hidden; max-width: 100%; }
.ad-unit ins.adsbygoogle { max-width: 100%; }
ins.adsbygoogle[data-ad-status="unfilled"] { display: none !important; }

/* ── Utility ── */
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.hidden { display: none !important; }
.text-secondary { color: var(--label-secondary); }
.text-sm { font-size: 13px; }

@media (min-width: 700px) {
  body { font-size: 16px; }
}
