:root {
  --bg: #f6f4ef;
  --panel: #ffffff;
  --text: #1f1d1a;
  --muted: #6d6860;
  --border: #e3dfd6;
  --accent: #3b5bdb;
  --accent-soft: #e5ebff;
  --root: #e8590c;
  --white-key: #ffffff;
  --black-key: #22201d;
  --error: #c92a2a;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161514;
    --panel: #201f1d;
    --text: #ece9e3;
    --muted: #9b968d;
    --border: #34322e;
    --accent: #748ffc;
    --accent-soft: #252c48;
    --root: #ff8a3d;
    --white-key: #e9e6e0;
    --black-key: #0c0b0a;
    --error: #ff6b6b;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  --bg: #161514;
  --panel: #201f1d;
  --text: #ece9e3;
  --muted: #9b968d;
  --border: #34322e;
  --accent: #748ffc;
  --accent-soft: #252c48;
  --root: #ff8a3d;
  --white-key: #e9e6e0;
  --black-key: #0c0b0a;
  --error: #ff6b6b;
  --shadow: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  line-height: 1.5;
}

a { color: var(--accent); }

.site-header {
  max-width: 960px;
  margin: 0 auto;
  padding: 14px 16px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.site-nav { display: flex; gap: 16px; }
.site-nav a { color: var(--muted); text-decoration: none; font-size: 0.95rem; }
.site-nav a:hover { color: var(--accent); }

.page-intro { padding: 8px 2px 0; }
.page-intro h1 { margin: 0; font-size: 1.9rem; line-height: 1.25; }
.page-intro p { margin: 4px 0 0; color: var(--muted); }
.breadcrumb { font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; }
.breadcrumb a { color: var(--muted); }

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  gap: 16px;
}

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

.label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  margin: 4px 0 8px;
  letter-spacing: 0.02em;
}
.label:not(:first-child) { margin-top: 18px; }

/* 본문 글 */
.article h2 { font-size: 1.25rem; margin: 24px 0 8px; }
.article h2:first-child { margin-top: 4px; }
.article h3 { font-size: 1rem; margin: 18px 0 8px; }
.article p { margin: 0 0 8px; }
.table-wrap { overflow-x: auto; }
.article table { border-collapse: collapse; width: 100%; min-width: 360px; }
.article th, .article td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.article thead th { color: var(--muted); font-size: 0.85rem; font-weight: 600; }
.chart-row h3 { margin: 16px 0 6px; }
.chord-links { display: flex; flex-wrap: wrap; gap: 6px; }
.chord-links a {
  text-decoration: none;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.9rem;
}
.chord-links a:hover { border-color: var(--accent); color: var(--accent); }

.site-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 8px 16px 32px;
}

button {
  font: inherit;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
button:hover { border-color: var(--accent); }
button.active, button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 검색 */
#search-form { display: flex; gap: 8px; }
#search {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 1.05rem;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.error { color: var(--error); margin: 8px 0 0; font-size: 0.9rem; }

/* 버튼 그리드 */
.button-grid { display: grid; gap: 6px; }
.roots { grid-template-columns: repeat(12, 1fr); }
.types { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
.button-grid button {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 4px;
  font-weight: 600;
}
.button-grid .alt { font-size: 0.72rem; font-weight: 400; opacity: 0.75; }

/* 코드 표시 */
.chord-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.chord-name { font-size: 2.6rem; font-weight: 700; line-height: 1.1; }
.chord-ko { color: var(--muted); }
.play-buttons { display: flex; gap: 8px; }
.play-buttons button { padding: 10px 16px; }

.tabs {
  display: flex;
  gap: 6px;
  margin: 16px 0 12px;
  flex-wrap: wrap;
}
.tabs button { border-radius: 999px; padding: 6px 14px; font-size: 0.9rem; }

/* 건반 */
.keyboard-wrap {
  overflow-x: auto;
  padding-bottom: 4px;
}
.keyboard {
  position: relative;
  height: 200px;
  min-width: 640px;
  user-select: none;
  touch-action: manipulation;
}
.key {
  position: absolute;
  top: 0;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
}
.key.white {
  height: 100%;
  background: var(--white-key);
  border: 1px solid #bdb8ae;
  border-radius: 0 0 6px 6px;
  z-index: 1;
}
.key.black {
  height: 62%;
  background: var(--black-key);
  border-radius: 0 0 4px 4px;
  z-index: 2;
}
.key.on.white { background: var(--accent-soft); }
.key.on .label {
  display: flex;
}
.key .label {
  display: none;
  flex-direction: column;
  align-items: center;
  margin-bottom: 18px;
}
.key.black .label { margin-bottom: 8px; }
.key .note {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 0.8rem;
  min-width: 24px;
  height: 24px;
  padding: 0 4px;
  border-radius: 12px;
  display: grid;
  place-items: center;
}
.key.root .note { background: var(--root); }
.key .deg { font-size: 0.7rem; color: #555; margin-top: 2px; font-weight: 600; }
.key.black .deg { color: #ddd; }
.key.on.black { background: color-mix(in srgb, var(--accent) 45%, var(--black-key)); }
.key.root.black { background: color-mix(in srgb, var(--root) 45%, var(--black-key)); }
.key .octave {
  position: absolute;
  bottom: 3px;
  font-size: 0.62rem;
  color: #999;
}
.key.playing.white { filter: brightness(0.88); }
.key.playing.black { filter: brightness(1.6); }

/* 정보 */
.info {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 16px 0 0;
}
.info div {
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 12px;
}
.info dt { font-size: 0.78rem; color: var(--muted); }
.info dd { margin: 2px 0 0; font-weight: 600; font-size: 1.05rem; }
.hint { color: var(--muted); font-size: 0.82rem; margin: 12px 0 0; }

@media (max-width: 640px) {
  .roots { grid-template-columns: repeat(6, 1fr); }
  .types { grid-template-columns: repeat(3, 1fr); }
  .chord-name { font-size: 2rem; }
  .info { grid-template-columns: 1fr; }
  .keyboard { height: 170px; }
}
