:root {
  --paper: #f7f3ea;
  --card: #fffdf9;
  --ink: #1e1b18;
  --muted: #6a645c;
  --line: #e6dfd2;
  --navy: #1d2540;
  --navy-soft: #e8ebf5;
  --red: #d7263d;
  --correct: #1b9e5a;
  --timing: #e48a00;
  --wrong: #d7263d;
  --missed: #9aa3ae;
  --extra: #7a4de0;
  --grade-a: #1b9e5a;
  --grade-b: #1c8c99;
  --grade-c: #d99a00;
  --grade-d: #e0661b;
  --grade-f: #d7263d;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(30, 27, 24, 0.05), 0 6px 24px rgba(30, 27, 24, 0.06);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Malgun Gothic",
    "Noto Sans KR", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom);
}

body.is-recording {
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}

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

button {
  cursor: pointer;
  border: 0;
  background: none;
  -webkit-tap-highlight-color: transparent;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

:focus-visible {
  outline: 3px solid #6b8cff;
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

/* In the iOS app the page runs edge to edge: keep scrolled content from showing under the status bar. */
.native-app body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto;
  height: env(safe-area-inset-top);
  background: var(--paper);
  z-index: 25;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 1000px;
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 18px 6px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  flex: none;
}

.brand h1 {
  margin: 0;
  font-size: 21px;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.tagline {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13.5px;
}

.top-link {
  color: var(--navy);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--navy-soft);
  white-space: nowrap;
}

/* ---------- layout ---------- */

main {
  max-width: 1000px;
  margin: 0 auto;
  padding: 8px 14px 24px;
  display: grid;
  gap: 14px;
}

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

.card h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  font-size: 18px;
  letter-spacing: -0.01em;
}

.step {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--navy);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}

.hint {
  color: var(--muted);
  font-size: 13px;
  margin: 6px 0 0;
}

/* ---------- pieces ---------- */

.pieces {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 10px;
}

.piece {
  position: relative;
  text-align: left;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 12px 12px 11px;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
  min-height: 92px;
}

.piece:hover {
  border-color: #c9c0b1;
}

.piece[aria-pressed="true"] {
  border-color: var(--navy);
  box-shadow: 0 0 0 3px var(--navy-soft);
}

.piece-title {
  display: block;
  font-weight: 700;
  font-size: 15px;
  line-height: 1.3;
  padding-right: 18px;
}

.piece-composer {
  display: block;
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 2px;
}

.piece-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: #f1ece2;
  color: #5b554d;
}

.piece-best {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 12px;
  font-weight: 800;
  color: #fff;
  width: 22px;
  height: 22px;
  border-radius: 7px;
  display: grid;
  place-items: center;
}

.upload-row {
  margin-top: 12px;
}

.upload {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border: 1.5px dashed #c9c0b1;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--navy);
  cursor: pointer;
  background: #fffaf2;
}

.upload input,
.file-drop input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload:focus-within,
.file-drop:focus-within {
  outline: 3px solid #6b8cff;
  outline-offset: 2px;
}

/* ---------- options ---------- */

.options {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 26px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.option {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.option-label {
  font-size: 14px;
  font-weight: 600;
  color: #4a453f;
}

.segmented {
  display: inline-flex;
  background: #efe9df;
  border-radius: 12px;
  padding: 3px;
}

.segmented button {
  padding: 6px 13px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 600;
  color: #5b554d;
}

.segmented button[aria-pressed="true"] {
  background: #fff;
  color: var(--navy);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.stepper {
  display: inline-flex;
  align-items: center;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.stepper button {
  width: 36px;
  height: 34px;
  font-size: 18px;
  font-weight: 700;
  color: var(--navy);
}

.stepper output {
  min-width: 74px;
  text-align: center;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.link {
  color: var(--navy);
  font-size: 13.5px;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 4px 2px;
}

/* ---------- tabs & inputs ---------- */

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs button {
  flex: none;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14.5px;
  font-weight: 600;
  background: #f1ece2;
  color: #5b554d;
}

.tabs button[aria-selected="true"] {
  background: var(--navy);
  color: #fff;
}

.recorder {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.record-button {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 14px 24px 14px 18px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  box-shadow: 0 6px 18px rgba(215, 38, 61, 0.28);
  transition: transform 0.12s;
}

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

.record-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
}

.recording .record-button {
  background: var(--navy);
  box-shadow: 0 6px 18px rgba(29, 37, 64, 0.28);
}

.recording .record-dot {
  border-radius: 3px;
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.45;
  }
}

.rec-status {
  display: grid;
  gap: 5px;
  min-width: 180px;
  flex: 1;
}

.rec-time {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.rec-hint {
  font-size: 13px;
  color: var(--muted);
}

.meter {
  height: 8px;
  border-radius: 999px;
  background: #ece6db;
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #1b9e5a, #e4b400 75%, #d7263d);
  transition: width 0.08s linear;
}

.ghost {
  padding: 8px 12px;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 600;
}

.tips {
  margin: 14px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13.5px;
}

.file-drop {
  position: relative;
  display: grid;
  gap: 4px;
  place-items: center;
  text-align: center;
  padding: 26px 16px;
  border: 2px dashed #c9c0b1;
  border-radius: 16px;
  background: #fffaf2;
  cursor: pointer;
}

.file-drop-title {
  font-weight: 700;
  color: var(--navy);
  font-size: 16px;
}

.file-drop-sub {
  color: var(--muted);
  font-size: 13px;
}

.panel-text {
  margin: 0 0 12px;
  font-size: 14px;
  color: #4a453f;
}

.midi-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.demo {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.demo .hint {
  flex: 1 1 220px;
  margin: 0;
}

.midi-status {
  font-size: 14px;
  color: var(--muted);
}

.primary,
.secondary {
  padding: 10px 18px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 15px;
}

.primary {
  background: var(--navy);
  color: #fff;
}

.secondary {
  background: var(--navy-soft);
  color: var(--navy);
}

.progress {
  margin-top: 16px;
}

.progress-text {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
}

.progress-bar {
  height: 10px;
  border-radius: 999px;
  background: #ece6db;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: var(--navy);
  border-radius: inherit;
  transition: width 0.2s ease;
}

.error {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: #fdecee;
  color: #a3182b;
  font-size: 14px;
  font-weight: 600;
}

/* ---------- recording dock ---------- */

.rec-dock {
  position: fixed;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px 10px 16px;
  border-radius: 999px;
  background: var(--navy);
  color: #fff;
  box-shadow: 0 10px 30px rgba(20, 24, 40, 0.35);
  width: min(94vw, 460px);
}

.rec-dock .rec-time {
  font-size: 18px;
}

.rec-dock .meter {
  flex: 1;
  background: rgba(255, 255, 255, 0.18);
}

.rec-dock button {
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-weight: 700;
  white-space: nowrap;
}

.rec-dot-live {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ff5a6e;
  animation: pulse 1.2s ease-in-out infinite;
  flex: none;
}

/* ---------- result ---------- */

.result-top {
  display: flex;
  gap: 18px;
  align-items: center;
  flex-wrap: wrap;
}

.grade {
  display: grid;
  place-items: center;
  width: 118px;
  height: 118px;
  border-radius: 28px;
  color: #fff;
  flex: none;
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.12);
}

.grade-letter {
  font-size: 64px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.04em;
  margin-top: 6px;
}

.grade-score {
  font-size: 16px;
  font-weight: 700;
  margin-top: -18px;
  opacity: 0.95;
}

.grade-score small {
  font-size: 12px;
  opacity: 0.8;
}

.grade-A {
  background: var(--grade-a);
}
.grade-B {
  background: var(--grade-b);
}
.grade-C {
  background: var(--grade-c);
}
.grade-D {
  background: var(--grade-d);
}
.grade-F {
  background: var(--grade-f);
}

.result-summary {
  flex: 1;
  min-width: 200px;
}

.headline {
  margin: 0;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.35;
}

.result-meta {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13.5px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px 22px;
  margin: 18px 0 4px;
}

.metric-row {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 5px;
}

.metric-row span:last-child {
  font-variant-numeric: tabular-nums;
}

.metric-note {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  margin-top: 3px;
}

.bar {
  height: 9px;
  border-radius: 999px;
  background: #ece6db;
  overflow: hidden;
}

.bar > i {
  display: block;
  height: 100%;
  border-radius: inherit;
}

.counts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
  padding: 0;
  margin: 16px 0 0;
}

.counts li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 999px;
  background: #f4efe6;
  font-size: 13.5px;
  font-weight: 600;
}

.counts b {
  font-variant-numeric: tabular-nums;
}

.feedback {
  list-style: none;
  padding: 0;
  margin: 16px 0 0;
  display: grid;
  gap: 8px;
}

.feedback li {
  padding: 10px 12px 10px 38px;
  border-radius: 12px;
  font-size: 14.5px;
  position: relative;
  background: #f6f2ea;
}

.feedback li::before {
  position: absolute;
  left: 12px;
  top: 10px;
  font-size: 15px;
}

.feedback .warn {
  background: #fff4e6;
}

.feedback .warn::before {
  content: "⚠️";
}

.feedback .good {
  background: #eaf7ef;
}

.feedback .good::before {
  content: "✅";
}

.feedback .info::before {
  content: "💡";
}

.strip-title {
  margin: 18px 0 8px;
  font-size: 14px;
  font-weight: 700;
}

.strip {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.strip button {
  min-width: 38px;
  padding: 5px 6px 4px;
  border-radius: 9px;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.strip button small {
  display: block;
  font-size: 10px;
  font-weight: 600;
  opacity: 0.9;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

/* ---------- score ---------- */

.score-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.score-head h2 {
  margin: 0;
}

.score-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: #f1ece2;
  color: var(--navy);
  font-size: 18px;
  font-weight: 700;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 10px;
  background: #f1ece2;
  cursor: pointer;
}

.toggle input {
  width: 17px;
  height: 17px;
  accent-color: var(--navy);
}

.score-title {
  margin: 8px 0 0;
  font-size: 15px;
  font-weight: 700;
}

.score-title small {
  color: var(--muted);
  font-weight: 500;
}

.omr-notice {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: #eef2ff;
  color: #27325a;
  font-size: 13.5px;
}

.omr-notice p {
  margin: 0 0 6px;
  font-weight: 600;
}

.omr-key {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.omr-key select {
  font: inherit;
  padding: 5px 8px;
  border-radius: 9px;
  border: 1.5px solid #c7cdea;
  background: #fff;
  color: inherit;
}

.footer a {
  color: inherit;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  list-style: none;
  padding: 10px 12px;
  margin: 10px 0 0;
  border-radius: 12px;
  background: #f6f2ea;
  font-size: 13px;
  font-weight: 600;
}

.legend li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.swatch.correct {
  background: var(--correct);
}
.swatch.timing {
  background: var(--timing);
}
.swatch.wrong {
  background: var(--wrong);
}
.swatch.missed {
  background: var(--missed);
}

.cross {
  font-weight: 900;
}

.cross.wrong {
  color: var(--wrong);
}

.cross.extra {
  color: var(--extra);
}

.sheet-wrap {
  position: relative;
  margin-top: 8px;
  overflow-x: auto;
  border-radius: 12px;
  background: #fff;
}

.sheet {
  min-height: 160px;
}

.sheet svg {
  display: block;
}

.sheet-highlight {
  position: absolute;
  border-radius: 8px;
  background: rgba(59, 91, 219, 0.14);
  box-shadow: 0 0 0 2px rgba(59, 91, 219, 0.45);
  pointer-events: none;
  transition: opacity 0.6s;
}

.sheet-status {
  margin: 8px 0 0;
  font-size: 13.5px;
  color: var(--muted);
}

/* ---------- history ---------- */

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.history-head h2 {
  margin: 0;
}

.history-list {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  display: grid;
  gap: 8px;
}

.history-item {
  display: grid;
  grid-template-columns: 38px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 9px 10px;
  border-radius: 12px;
  background: #faf6ef;
}

.history-grade {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  color: #fff;
  font-weight: 900;
  font-size: 20px;
}

.history-title {
  font-weight: 700;
  font-size: 14.5px;
}

.history-meta {
  font-size: 12.5px;
  color: var(--muted);
}

.history-score {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* ---------- footer & toast ---------- */

.footer {
  max-width: 1000px;
  margin: 0 auto;
  padding: 4px 22px 36px;
  color: var(--muted);
  font-size: 12.5px;
}

.footer p {
  margin: 4px 0;
}

.toast {
  position: fixed;
  left: 50%;
  top: calc(12px + env(safe-area-inset-top));
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--navy);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  max-width: 92vw;
}

.toast button {
  color: #ffd66b;
  font-weight: 700;
}

@media (max-width: 560px) {
  .card {
    padding: 15px;
    border-radius: 16px;
  }

  .grade {
    width: 96px;
    height: 96px;
    border-radius: 24px;
  }

  .grade-letter {
    font-size: 52px;
  }

  .grade-score {
    margin-top: -14px;
  }

  .headline {
    font-size: 17px;
  }

  .pieces {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .record-button {
    width: 100%;
    justify-content: center;
  }
}

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

/* ---------- my scores ---------- */

.piece-wrap {
  position: relative;
  display: grid;
}

.piece-wrap .piece {
  width: 100%;
}

.piece-delete {
  position: absolute;
  right: 8px;
  bottom: 8px;
  min-width: 26px;
  height: 26px;
  padding: 0 6px;
  border-radius: 999px;
  background: #f1ece2;
  color: #7a716a;
  font-size: 15px;
  font-weight: 700;
  line-height: 26px;
}

.piece-delete[data-confirm="1"] {
  background: #fdecee;
  color: #a3182b;
  font-size: 12px;
}

.chip-mine {
  background: #e8ebf5;
  color: var(--navy);
}

.share-button {
  height: 34px;
  padding: 0 12px;
  border-radius: 10px;
  background: var(--navy-soft);
  color: var(--navy);
  font-size: 13.5px;
  font-weight: 700;
  white-space: nowrap;
}

/* ---------- privacy & support pages ---------- */

.brand-link {
  color: inherit;
  text-decoration: none;
}

.brand-name {
  margin: 0;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.doc {
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  font-size: 15px;
  line-height: 1.7;
}

.doc h1 {
  margin: 0 0 4px;
  font-size: 22px;
  letter-spacing: -0.02em;
}

.doc h2 {
  display: block;
  margin: 26px 0 6px;
  font-size: 17px;
}

.doc h3 {
  margin: 18px 0 4px;
  font-size: 15px;
}

.doc p,
.doc ul,
.doc ol {
  margin: 6px 0;
}

.doc ul,
.doc ol {
  padding-left: 20px;
}

.doc code {
  padding: 1px 5px;
  border-radius: 6px;
  background: #f1ece2;
  font-size: 13.5px;
}

.doc a {
  color: var(--navy);
}

.doc-meta {
  color: var(--muted);
  font-size: 13.5px;
}

.doc-summary {
  margin: 16px 0 4px;
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--navy-soft);
}

.doc-contact {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 14px;
  margin: 8px 0;
}

.doc-contact dt {
  color: var(--muted);
}

.doc-contact dd {
  margin: 0;
}

.doc-button {
  display: inline-block;
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--navy);
  color: #fff !important;
  font-weight: 700;
  text-decoration: none;
}
