/* =========================
   Fonts (self-hosted)
   ========================= */

/* DM Mono */
@font-face {
  font-family: 'DM Mono';
  font-style: normal;
  font-weight: 300;
  font-display: swap;
  src: url('../fonts/dm-mono-300-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'DM Mono';
  font-style: normal;
  font-weight: 300;
  font-display: swap;
  src: url('../fonts/dm-mono-300-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'DM Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/dm-mono-400-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'DM Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/dm-mono-400-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'DM Mono';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../fonts/dm-mono-500-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'DM Mono';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../fonts/dm-mono-500-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* DM Sans */
@font-face {
  font-family: 'DM Sans';
  font-style: normal;
  font-weight: 300 500;
  font-display: swap;
  src: url('../fonts/dm-sans-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'DM Sans';
  font-style: normal;
  font-weight: 300 500;
  font-display: swap;
  src: url('../fonts/dm-sans-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Playfair Display */
@font-face {
  font-family: 'Playfair Display';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('../fonts/playfair-display-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Playfair Display';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('../fonts/playfair-display-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* =========================
   Custom properties
   ========================= */

:root {
  --bg:     #0e1117;
  --text:   #dce4f0;
  --muted:  #6b7a96;

  --panel:  #161b26;
  --panel2: #1e2535;
  --border: #2a3348;
  --ring:   rgba(232, 168, 56, 0.55);

  --kb-white:  #eef2f8;
  --kb-border: #c0c8d8;
  --kb-black1: #0a0d14;
  --kb-black2: #2a3048;

  --piano-max: 620px;
  --white-h:   140px;
  --black-h:   90px;
  --black-r:   4px;

  /* Blue: active scale notes */
  --blue:      #3a7bd5;
  --blue-rgb:  58, 123, 213;

  /* Gold: root note */
  --gold:      #e8a838;
  --gold-rgb:  232, 168, 56;

  --ctrl-bg:     #161b26;
  --ctrl-border: #2a3348;
  --ctrl-color:  #dce4f0;
}

/* =========================
   Reset & base
   ========================= */

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
}

#app {
  max-width: calc(var(--piano-max) + 64px);
  margin: 0 auto;
  padding:
    max(32px, env(safe-area-inset-top))
    max(32px, env(safe-area-inset-right))
    48px
    max(32px, env(safe-area-inset-left));
}

/* =========================
   Heading
   ========================= */

.heading-block {
  margin: 0 0 28px;
}

.heading-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.heading-copy {
  min-width: 0;
}

h1 {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 2.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--text);
  margin: 0;
}

.lang-toggle {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  flex-shrink: 0;
}

.lang-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition:
    transform 120ms ease,
    background 120ms ease,
    box-shadow 120ms ease;
}

.lang-btn:hover {
  background: rgba(var(--gold-rgb), 0.08);
}

.lang-btn.active {
  background: #1c1a0f;
  box-shadow: inset 0 0 0 1px var(--gold);
}

.lang-btn:focus-visible {
  outline: none;
  box-shadow:
    inset 0 0 0 1px var(--gold),
    0 0 0 3px var(--ring);
}

.lang-flag {
  width: 22px;
  height: 22px;
  display: block;
}

/* =========================
   Menu wrapper
   ========================= */

.menu {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-bottom: 20px;
}

/* =========================
   Controls grid
   ========================= */

.controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 220px));
  gap: 16px 24px;
  align-items: end;
  max-width: 524px;
}

.control {
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
}

.control label {
  font-size: 0.72rem;
  font-family: 'DM Mono', 'Courier New', monospace;
  color: var(--muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  white-space: nowrap;
}

.control--wide {
  grid-column: 1 / -1;
}

/* dropdown arrow */
.control--select::after {
  content: "▾";
  position: absolute;
  right: 14px;
  bottom: 10px;
  color: var(--muted);
  pointer-events: none;
}

/* =========================
   Form controls
   ========================= */

select,
button {
  height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--ctrl-border);
  background: var(--ctrl-bg);
  color: var(--ctrl-color);
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}

select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  padding-right: 38px;
}

select option,
select optgroup {
  background: var(--panel2);
  color: var(--ctrl-color);
}

select:hover,
button:hover {
  border-color: rgba(255, 255, 255, 0.22);
}

select:focus,
button:focus-visible {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(var(--blue-rgb), 0.22);
}

button {
  cursor: pointer;
  font-weight: 600;
}

/* =========================
   Root note picker
   ========================= */

.root-note {
  font-size: 0.72rem;
  font-family: 'DM Mono', 'Courier New', monospace;
  color: var(--muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.root-picker {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 68px));
  gap: 8px;
  width: min(524px, 100%);
}

.root-picker--accidentals {
  grid-template-columns: repeat(5, minmax(0, 68px));
  width: min(412px, 100%);
}

.root-btn {
  height: 38px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.2px;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  transition:
    transform 120ms ease,
    border-color 120ms ease,
    filter 120ms ease,
    box-shadow 120ms ease;
}

.root-btn:hover {
  filter: brightness(1.08);
  border-color: rgba(255, 255, 255, 0.18);
}

.root-btn:active {
  transform: translateY(1px);
}

.root-btn:focus-visible {
  outline: none;
  border-color: rgba(var(--gold-rgb), 0.65);
  box-shadow:
    0 0 0 3px var(--ring),
    0 6px 20px rgba(0, 0, 0, 0.28);
}

.root-btn.is-active {
  border-color: rgba(var(--gold-rgb), 0.55);
  background:
    linear-gradient(180deg, rgba(var(--gold-rgb), 0.22), rgba(var(--gold-rgb), 0.10)),
    var(--panel);
  color: var(--gold);
  box-shadow:
    inset 0 -2px 0 rgba(var(--gold-rgb), 0.6),
    0 6px 16px rgba(0, 0, 0, 0.24);
}

.root-btn--accidental {
  font-size: 1.4rem;
}

.root-btn--accidental[data-empty="true"] {
  letter-spacing: 0;
  text-transform: none;
}

/* =========================
   Piano
   ========================= */

.piano {
  position: relative;
  width: 100%;
  max-width: var(--piano-max);
  margin-top: 8px;
  border-radius: 0;
  overflow: hidden;
}

.white-row {
  display: flex;
}

.white-key {
  position: relative;
  flex: 1;
  height: var(--white-h);
  border: 1px solid var(--kb-border);
  border-right: 2px solid var(--kb-black1);
  background: var(--kb-white);
  border-radius: 0 0 2px 2px;
  transition: box-shadow 0.25s ease;
}

.black-row {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: var(--black-h);
  pointer-events: none;
}

.black-key {
  position: absolute;
  transform: translateX(-50%);
  width: calc(100% / 15 * 0.62);
  height: var(--black-h);
  border-radius: 2px 2px var(--black-r) var(--black-r);
  background: linear-gradient(180deg, var(--kb-black1) 0%, var(--kb-black2) 100%);
  border: 1px solid #0a0d14;
  border-top: 2px solid #1e2535;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transition: box-shadow 0.25s ease;
}

/* --- Active (in-scale) --- */

.white-key.active {
  background: linear-gradient(180deg, #ffffff 0%, #c8e0ff 60%, #4a90e2 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    inset 0 -6px 12px rgba(var(--blue-rgb), 0.12);
}

.black-key.active {
  background: linear-gradient(180deg, #0a0d14 0%, #5b9ef5 100%);
  box-shadow:
    0 0 8px rgba(var(--blue-rgb), 0.6),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

/* --- Root note --- */

.white-key.root {
  background: linear-gradient(180deg, #ffffff 0%, #ffe8b0 60%, #e8a838 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    inset 0 -6px 14px rgba(var(--gold-rgb), 0.35),
    0 2px 8px rgba(var(--gold-rgb), 0.30);
}

.white-key.root::after {
  content: "";
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 4px;
  height: 3px;
  border-radius: 2px;
  background: var(--gold);
  opacity: 0.85;
}

.black-key.root {
  background: linear-gradient(180deg, #0a0d14 0%, #c8891a 100%);
  box-shadow:
    0 8px 18px rgba(0, 0, 0, 0.55),
    inset 0 -10px 18px rgba(var(--gold-rgb), 0.30);
}

/* --- Combined: root note that is also in the scale --- */

.white-key.active.root {
  background: linear-gradient(180deg, #ffffff 0%, #ffe8b0 60%, #e8a838 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    inset 0 -8px 16px rgba(var(--gold-rgb), 0.40),
    0 3px 10px rgba(var(--gold-rgb), 0.35);
}

.black-key.active.root {
  background: linear-gradient(180deg, #0a0d14 0%, #c8891a 100%);
  box-shadow:
    0 8px 18px rgba(0, 0, 0, 0.55),
    inset 0 -10px 18px rgba(var(--gold-rgb), 0.30);
}

/* =========================
   Scale output box
   ========================= */

.scale-output {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  margin-top: 16px;
}

.scale-name {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--gold);
  margin-bottom: 12px;
}

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

.note-pill {
  font-family: 'DM Mono', 'Courier New', monospace;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(74, 144, 226, 0.14);
  border: 1px solid rgba(91, 158, 245, 0.32);
  color: #d7e9ff;
}

.note-pill.root {
  background: #1c1a0f;
  border-color: var(--gold);
  color: var(--gold);
}

.intervals {
  margin-top: 14px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  row-gap: 8px;
}

.interval-note {
  font-family: 'DM Mono', 'Courier New', monospace;
  font-size: 0.82rem;
  font-weight: 500;
  color: #bddbff;
  min-width: 28px;
  text-align: center;
}

.interval-note.root {
  color: var(--gold);
}

.interval-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 4px;
}

.interval-step-line {
  width: 24px;
  height: 1px;
  background: var(--border);
}

.interval-step-label {
  font-family: 'DM Mono', 'Courier New', monospace;
  font-size: 0.58rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  margin-top: 3px;
  white-space: nowrap;
}

/* =========================
   Responsive
   ========================= */

@media (max-width: 768px) {
  .heading-row {
    align-items: center;
  }

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

  .root-picker {
    width: 100%;
  }
}

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

  select,
  button {
    width: 100%;
  }

  .root-picker {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .root-btn {
    white-space: normal;
  }
}

footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--muted);
  font-size: .88rem;
  border-top: 1px solid var(--border);
}

footer p {
  margin: 0;
}

footer a {
  color: var(--muted);
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: .2em;
}

footer a:hover {
  text-decoration-style: solid;
}

@media (max-width: 450px) {
  /* Show only second octave on very small screens */
  .white-row,
  .black-row {
    width: 187.5%;
    margin-left: -87.5%;
  }

  .black-row {
    right: auto;
  }
}
