@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Space+Mono:wght@700&display=swap');

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

:root {
  --bg-header: #007a78;
  --bg-page: #e2e2e2;
  --bg-white: #ffffff;
  --bg-black: #000000;
  
  --text-dark: #111111;
  --text-muted: #666666;
  --note-blue: #2563eb;
  
  --press-white: #bae6fd;
  --press-white-border: #0284c7;
  --press-black: #0284c7;
  
  --border-dark: #111111;
  --border-light: #cccccc;
  
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  
  --font-sans: 'Inter', -apple-system, sans-serif;
  --font-mono: 'Space Mono', monospace;
}

:focus-visible {
  outline: 2px solid var(--bg-header);
  outline-offset: 2px;
}

html, body {
  width: 100%;
  height: 100%;
  background-color: var(--bg-page);
}

body {
  font-family: var(--font-sans);
  color: var(--text-dark);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 48px;
  flex-shrink: 0;
  background-color: var(--bg-header);
  color: #ffffff;
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 0.95rem;
}

.nav-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.nav-group {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 500;
}

#volumeLevel {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  min-width: 32px;
}

.nav-range, .modal-range {
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.4);
  outline: none;
  cursor: pointer;
}

.nav-range { width: 70px; }
.modal-range { width: 100%; background: #ccc; }

.nav-range::-webkit-slider-thumb, .modal-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ffffff;
  cursor: pointer;
}

.modal-range::-webkit-slider-thumb {
  background: var(--bg-header);
}

.sw {
  position: relative;
  display: inline-block;
  width: 32px;
  height: 18px;
}

.sw input { opacity: 0; width: 0; height: 0; }

.sw-track {
  position: absolute;
  inset: 0;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 10px;
  transition: background 0.15s ease;
}

.sw-track::before {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  left: 2px;
  bottom: 2px;
  background: #ffffff;
  border-radius: 50%;
  transition: transform 0.15s ease;
}

input:checked + .sw-track {
  background: rgba(255, 255, 255, 0.85);
}

input:checked + .sw-track::before {
  transform: translateX(14px);
  background: var(--bg-header);
}

.nav-btn {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: #ffffff;
  padding: 4px 10px;
  border-radius: var(--radius-xs);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 600;
  transition: background 0.15s ease;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

@media (max-width: 500px) {
  .nav-group { display: none; }
}

.page {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  width: 100%;
}

#mainScreen {
  display: block;
  width: 100%;
  max-width: 920px;
}

.cabinet {
  background: var(--bg-white);
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.stage {
  position: relative;
  width: 100%;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-xs);
  background: var(--bg-white);
  overflow: hidden;
}

.keys-outer {
  width: 100%;
  overflow: hidden;
}

.keys-row {
  display: flex;
  position: relative;
  width: 100%;
  height: 220px;
  user-select: none;
  touch-action: none;
  background: var(--bg-white);
}

.wk {
  flex: 1 0 0%;
  height: 100%;
  background: #ffffff;
  border-right: 1px solid var(--border-dark);
  border-bottom: 1px solid var(--border-dark);
  border-radius: 0 0 3px 3px;
  cursor: pointer;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 12px;
  gap: 4px;
  transition: background 0.35s ease, transform 0.12s ease, border-color 0.35s ease;
}

.wk:last-child {
  border-right: none;
}

.wk:hover {
  background: #f7f7f7;
}

.wk:active, .wk.pressed {
  background: var(--press-white);
  border-color: var(--press-white-border);
  transform: translateY(3px);
  transition: background 0.03s ease, transform 0.03s ease, border-color 0.03s ease;
}

.wk .kb {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 700;
  color: #000000;
  line-height: 1;
}

.wk .nt {
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--note-blue);
  line-height: 1;
}

.bk {
  position: absolute;
  top: 0;
  z-index: 3;
  width: 4.2%;
  height: 118px;
  background: var(--bg-black);
  border-radius: 0 0 3px 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.35s ease, transform 0.12s ease;
}

.bk:hover {
  background: #1f1f1f;
}

.bk:active, .bk.pressed {
  background: var(--press-black);
  transform: translateY(2px);
  transition: background 0.03s ease, transform 0.03s ease;
}

.bk .kb {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
  color: #ffffff;
}

#bk1    { left: calc((100% / 14) * 1 - 2.1%) !important; }
#bk2    { left: calc((100% / 14) * 2 - 2.1%) !important; }
#bk4    { left: calc((100% / 14) * 4 - 2.1%) !important; }
#bk5    { left: calc((100% / 14) * 5 - 2.1%) !important; }
#bk7    { left: calc((100% / 14) * 7 - 2.1%) !important; }
#bk8    { left: calc((100% / 14) * 8 - 2.1%) !important; }
#bk9    { left: calc((100% / 14) * 9 - 2.1%) !important; }
#bkDash { left: calc((100% / 14) * 11 - 2.1%) !important; }
#bkEq   { left: calc((100% / 14) * 12 - 2.1%) !important; }

#mobileOskPanel {
  display: none;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
}

.mob-cabinet {
  background: var(--bg-white);
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-sm);
  padding: 8px;
}

.mob-stage {
  position: relative;
  width: 100%;
}

.mob-keys-wrap {
  position: relative;
  display: flex;
  width: 100%;
  border: 1px solid var(--border-dark);
}

.mob-wk {
  flex: 1;
  background: #ffffff;
  border-right: 1px solid var(--bg-black);
  height: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 10px;
  gap: 4px;
  touch-action: none;
  transition: background 0.35s ease, transform 0.12s ease;
}

.mob-wk.oskpressed {
  background: var(--press-white);
  transform: translateY(3px);
  transition: background 0.03s ease, transform 0.03s ease;
}

.mob-wk .mob-kb {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
  color: #000000;
}

.mob-wk .mob-nt {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--note-blue);
}

.mob-bk {
  position: absolute;
  top: 0;
  z-index: 3;
  background: var(--bg-black);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  transition: background 0.35s ease, transform 0.12s ease;
}

.mob-bk.oskpressed {
  background: var(--press-black);
  transform: translateY(2px);
  transition: background 0.03s ease, transform 0.03s ease;
}

.mob-bk .mob-kb {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  color: #ffffff;
}

#landscapeHint {
  display: none;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 10px;
}

@media (max-width: 600px) and (orientation: portrait) {
  .cabinet { display: none; }
  .page { justify-content: flex-start; padding: 10px; }
}

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.overlay.open { display: flex; }

.modal {
  background: #ffffff;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-sm);
  width: 100%;
  max-width: 380px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #f5f5f5;
  border-bottom: 1px solid var(--border-light);
}

.modal-title {
  font-size: 0.9rem;
  font-weight: 700;
}

.modal-x-btn {
  background: none;
  border: none;
  font-size: 0.95rem;
  cursor: pointer;
  color: var(--text-muted);
}

.modal-x-btn:hover { color: var(--text-dark); }

.modal-body {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-section-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 8px;
}

.mctrl-row, .modal-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.mctrl-label { font-size: 0.8rem; color: #222222; }

#volumeLevelModal {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-align: right;
  margin-top: 4px;
}

.mctrl-right { display: flex; align-items: center; gap: 8px; }

.mctrl-box { text-align: center; min-width: 36px; }

.mctrl-val {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 700;
}

.mctrl-sub { font-size: 0.6rem; color: #777777; }

.mcbtn {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-xs);
  background: #f0f0f0;
  border: 1px solid var(--border-light);
  cursor: pointer;
  font-weight: 700;
}

.mcbtn:hover { background: #e0e0e0; }

.modal-divider { border: none; border-top: 1px solid #eeeeee; }

.midi-status { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 6px; }

.midi-sel {
  width: 100%;
  background: #ffffff;
  border: 1px solid var(--border-light);
  padding: 6px;
  border-radius: var(--radius-xs);
  font-size: 0.75rem;
}

.midi-ref {
  background: #f5f5f5;
  border: 1px solid var(--border-light);
  padding: 6px;
  border-radius: var(--radius-xs);
  font-size: 0.72rem;
  margin-top: 6px;
  width: 100%;
  cursor: pointer;
}

.midi-ref:hover { background: #e8e8e8; }

.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid #eeeeee;
  background: #f9f9f9;
}

.modal-close {
  width: 100%;
  padding: 8px;
  border: none;
  border-radius: var(--radius-xs);
  background: var(--bg-header);
  color: #ffffff;
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
}

.modal-close:hover { opacity: 0.9; }

#portraitOverlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg-page);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}

#portraitOverlay.show { display: flex; }

.portrait-icon { font-size: 2.5rem; margin-bottom: 12px; }
.portrait-title { font-size: 1rem; font-weight: 700; margin-bottom: 6px; }
.portrait-sub { font-size: 0.8rem; color: var(--text-muted); }

.wk, .bk, .mob-wk, .mob-bk {
  -webkit-tap-highlight-color: transparent !important;
  -webkit-touch-callout: none !important;
  user-select: none !important;
  touch-action: none !important;
}