/* General Reset */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  background-color: #222;
  color: #ddd;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

/* --- Loading Overlay --- */
#loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #111;
  color: white;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  transition: opacity 0.5s ease;
}

#loading-overlay.loaded {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 5px solid #333;
  border-top-color: #4db8ff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 20px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

#loading-status {
  font-size: 1.2rem;
  margin-bottom: 20px;
}

.progress-container {
  width: 300px;
  height: 6px;
  background: #333;
  border-radius: 3px;
  overflow: hidden;
}

#progress-bar {
  height: 100%;
  width: 0%;
  background: #4db8ff;
  transition: width 0.2s;
}

/* --- Main Container --- */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* Floating Info Panel */
.info-panel {
  position: fixed;
  top: 10px;
  left: 10px;
  background: rgba(40, 40, 40, 0.95);
  border: 1px solid #444;
  border-radius: 8px;
  z-index: 100;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(5px);
  transition: width 0.3s, height 0.3s;
  overflow: hidden;
  max-width: 320px;
}

.info-panel.collapsed {
  max-width: 40px;
  max-height: 40px;
}

.toggle-btn {
  position: absolute;
  top: 5px;
  right: 5px;
  background: transparent;
  border: none;
  color: #aaa;
  font-size: 20px;
  cursor: pointer;
  z-index: 101;
}

.info-panel.collapsed .toggle-btn {
  position: relative;
  top: 0;
  left: 0;
  right: 0;
  width: 40px;
  height: 40px;
  font-size: 24px;
}

.info-content {
  padding: 15px;
  padding-top: 30px;
}

.info-panel.collapsed .info-content {
  display: none;
}

.info-panel h1 {
  font-size: 1.1rem;
  margin: 0 0 5px 0;
  color: #fff;
}

.info-panel p {
  font-size: 0.8rem;
  color: #bbb;
  margin: 0 0 10px 0;
}

.info-panel a {
  color: #4db8ff;
  font-size: 0.8rem;
}

.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 15px;
  margin-bottom: 10px;
}

.control-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.8rem;
  cursor: pointer;
  color: #ccc;
}

/* Canvas Area */
.app-main {
  flex-grow: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.canvas-wrapper {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #000;
}

#canvas {
  width: 100%;
  height: 100%;
  background-color: #333;
  display: block;
}

/* Keyboard Area */
.app-footer {
  flex-shrink: 0;
  width: 100%;
  height: 160px;
  position: relative;
  transition: height 0.2s ease;
}

.app-footer.short-keys {
  height: 100px;
}

.app-footer.hidden-keys {
  height: 0px;
  overflow: hidden;
}

.key-slip {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 20px;
  background: #111;
  z-index: 20;
  pointer-events: none;
  border-bottom: 2px solid #333;
}

#keyboard {
  position: relative;
  width: 100%;
  height: 100%;
  background: #111;
  overflow: hidden;
  cursor: pointer;
  user-select: none;
}

/* White Keys */
.white {
  background: linear-gradient(to bottom, #fff 0%, #eee 100%);
  border: 1px solid #000;
  height: 100%;
  width: calc(100% / 22);
  display: inline-block;
  border-radius: 0 0 4px 4px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
  margin-right: -1px;
  position: relative;
  transition: transform 0.06s ease-out;
}

.white.pressed {
  background: #ccc;
  transform: translateY(3px);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.3);
}

.white .key-label {
  position: absolute;
  bottom: 5px;
  left: 0;
  width: 100%;
  text-align: center;
  font-size: 10px;
  color: #888;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}

/* Black Keys Overlay */
#blackkeys {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 60%;
  z-index: 10;
  pointer-events: none;
}

.black {
  position: absolute;
  background: linear-gradient(to bottom, #333 0%, #000 100%);
  height: 100%;
  width: calc(100% / 22 * 0.6);
  border-radius: 0 0 3px 3px;
  pointer-events: auto;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.5);
  transition: transform 0.06s ease-out;
  z-index: 15;
}

.black.pressed {
  background: #222;
  transform: translateY(3px);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.5);
}

.black .key-label {
  position: absolute;
  bottom: 5px;
  left: 0;
  width: 100%;
  text-align: center;
  font-size: 9px;
  color: #666;
  pointer-events: none;
  opacity: 0;
}

/* Visibility Classes */
#keyboard.show-notes .key-label {
  opacity: 1;
}

#keyboard.show-mapping .key-label {
  opacity: 1;
  color: #c00;
}

#keyboard.show-mapping .black .key-label {
  color: #f44;
}

/* Mobile */
@media (max-width: 768px) {
  .info-panel {
    max-width: 220px;
  }

  .info-panel h1 {
    font-size: 1rem;
  }

  .info-panel p {
    display: none;
  }

  .app-footer {
    height: 120px;
  }

  .app-footer.short-keys {
    height: 80px;
  }

  .controls-grid {
    grid-template-columns: 1fr;
  }
}