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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #f5f5f5;
  display: flex;
  flex-direction: column;
  color: #333;
  touch-action: pan-y;
}

/* ========== 全屏按钮 ========== */
.fullscreen-btn {
  position: fixed;
  top: 16px;
  right: 70px;
  z-index: 200;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(0, 0, 0, 0.1);
  color: #333;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.fullscreen-btn:hover {
  background: #fff;
  transform: scale(1.05);
}

.fullscreen-btn:active {
  transform: scale(0.95);
}

.fullscreen-btn.active {
  background: rgba(25, 118, 210, 0.9);
  border-color: rgba(25, 118, 210, 0.9);
  color: #fff;
}

/* ========== 设置按钮 ========== */
.settings-btn {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 200;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(0, 0, 0, 0.1);
  color: #333;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.settings-btn:hover {
  background: #fff;
  transform: scale(1.05);
}

.settings-btn:active {
  transform: scale(0.95);
}

/* ========== 遮罩层 ========== */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  z-index: 300;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.settings-overlay.open {
  opacity: 1;
  visibility: visible;
}

/* ========== 右侧设置面板 ========== */
.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 320px;
  max-width: 85vw;
  height: 100vh;
  background: #ffffff;
  backdrop-filter: blur(20px);
  z-index: 400;
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.2);
}

.settings-panel.open {
  transform: translateX(0);
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 16px;
  border-bottom: 1px solid #eee;
}

.settings-header h2 {
  font-size: 1.3rem;
  font-weight: 600;
  color: #333;
  letter-spacing: 0.02em;
}

.close-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: #f0f0f0;
  border: none;
  color: #666;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.close-btn:hover {
  background: #e0e0e0;
  color: #333;
}

.settings-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px 32px;
}

.settings-content::-webkit-scrollbar {
  width: 4px;
}

.settings-content::-webkit-scrollbar-track {
  background: transparent;
}

.settings-content::-webkit-scrollbar-thumb {
  background: #ddd;
  border-radius: 2px;
}

.midi-status {
  text-align: center;
  font-size: 0.8rem;
  padding: 10px;
  margin-bottom: 16px;
  background: #f5f5f5;
  border-radius: 10px;
  color: #888;
}

.settings-section {
  margin-bottom: 24px;
}

.settings-section h3 {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #999;
  margin-bottom: 10px;
}

.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn-group button {
  padding: 10px 14px;
  border: 1px solid #ddd;
  background: #fff;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.85rem;
  color: #666;
  transition: all 0.2s ease;
  font-weight: 500;
}

.btn-group button:hover {
  background: #f5f5f5;
  border-color: #ccc;
}

.btn-group button.on {
  background: #333;
  color: #fff;
  border-color: #333;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.custom-range {
  background: #f8f8f8;
  padding: 14px;
  border-radius: 12px;
  margin-top: -8px;
}

.range-selectors {
  display: flex;
  align-items: center;
  gap: 10px;
}

.range-selectors span {
  color: #999;
  font-size: 0.85rem;
}

.range-selectors select {
  flex: 1;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #ddd;
  background: #fff;
  color: #333;
  font-size: 0.9rem;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s ease;
}

.range-selectors select:focus {
  border-color: #333;
}

.stats-section {
  background: #f8f8f8;
  padding: 16px;
  border-radius: 12px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.stat-item {
  text-align: center;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: #333;
  line-height: 1.2;
}

.stat-label {
  font-size: 0.7rem;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 4px;
}

/* ========== 主显示区域 ========== */
.main-area {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 0 12px;
}

/* ========== 顶部状态栏 ========== */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 4px;
  margin-top: 50px;
}

.midi-status {
  font-size: 0.75rem;
  color: #888;
  background: #f0f0f0;
  padding: 6px 12px;
  border-radius: 20px;
}

.stats {
  display: flex;
  gap: 16px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 40px;
}

.stat-num {
  font-size: 1.2rem;
  font-weight: 700;
  color: #333;
  line-height: 1.2;
}

.stat-text {
  font-size: 0.65rem;
  color: #999;
  text-transform: uppercase;
}

/* ========== 谱子区域 ========== */
.sb {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border-radius: 10px;
  padding: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  overflow: hidden;
  min-height: 0;
}

canvas#S {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.fb {
  text-align: center;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 8px;
  border-radius: 8px;
  margin: 6px 0;
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  color: #333;
}

.fb.ok {
  background: #e8f5e9;
  color: #2e7d32;
  animation: pop 0.3s;
}

.fb.no {
  background: #ffebee;
  color: #c62828;
  animation: shk 0.4s;
}

.piano-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 0;
  flex-shrink: 0;
}

/* ========== 钢琴键盘 ========== */
.piano {
  display: flex;
  justify-content: center;
  user-select: none;
}

.wk {
  flex: 0 0 42px;
  height: 140px;
  background: linear-gradient(180deg, #ffffff, #f0f0f0);
  border: 1px solid #999;
  border-right: none;
  border-radius: 0 0 4px 4px;
  cursor: pointer;
  position: relative;
  transition: background 0.1s ease;
}

.wk:first-child {
  border-top-left-radius: 5px;
  border-bottom-left-radius: 5px;
}

.wk:last-child {
  border-right: 1px solid #999;
  border-top-right-radius: 5px;
  border-bottom-right-radius: 5px;
}

.wk:hover {
  background: linear-gradient(180deg, #fff, #e8e8e8);
}

.wk:active {
  background: linear-gradient(180deg, #e8e8e8, #ddd);
}

.wk .lb {
  position: absolute;
  bottom: 8px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.6rem;
  color: #666;
  font-weight: 600;
  pointer-events: none;
}

.bk {
  position: absolute;
  left: 70%;
  width: 60%;
  height: 84px;
  background: linear-gradient(180deg, #2a2a2a, #111);
  border-radius: 0 0 4px 4px;
  cursor: pointer;
  z-index: 2;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.4);
  transition: background 0.1s ease;
}

.bk:hover {
  background: linear-gradient(180deg, #3a3a3a, #222);
}

.bk:active {
  height: 82px;
}

.bk .lb {
  position: absolute;
  bottom: 5px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.5rem;
  color: #aaa;
  font-weight: 500;
  pointer-events: none;
}

.wk.ch {
  background: linear-gradient(180deg, #c8e6c9, #a5d6a7) !important;
  border-color: #66bb6a !important;
}

.wk.wh {
  background: linear-gradient(180deg, #ffcdd2, #ef9a9a) !important;
  border-color: #ef5350 !important;
}

.bk.ch {
  background: linear-gradient(180deg, #388e3c, #2e7d32) !important;
}

.bk.wh {
  background: linear-gradient(180deg, #b71c1c, #8e0000) !important;
}

.kd {
  pointer-events: none;
}

/* ========== 动画 ========== */
@keyframes pop {
  0% { transform: scale(0.95); }
  50% { transform: scale(1.03); }
  100% { transform: scale(1); }
}

@keyframes shk {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* ========== 横屏模式 ========== */
@media (max-height: 500px) and (orientation: landscape) {
  body {
    padding: 0;
    background: #f5f5f5;
  }

  .settings-btn {
    top: 8px;
    right: 8px;
    width: 38px;
    height: 38px;
  }

  .settings-panel {
    width: 280px;
  }

  .settings-header {
    padding: 14px 16px 12px;
  }

  .settings-content {
    padding: 12px 16px 20px;
  }

  .settings-section {
    margin-bottom: 16px;
  }

  .btn-group button {
    padding: 8px 12px;
    font-size: 0.8rem;
  }

  .main-area {
    flex-direction: row;
    padding: 50px 8px 8px;
    max-width: none;
    gap: 8px;
  }

  .top-bar {
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    margin-top: 0;
    padding: 0;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    border-radius: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }

  .midi-status {
    font-size: 0.7rem;
    padding: 4px 10px;
  }

  .stats {
    gap: 10px;
  }

  .stat {
    min-width: 32px;
  }

  .stat-num {
    font-size: 1rem;
  }

  .stat-text {
    font-size: 0.55rem;
  }

  .sb {
    flex: 1.2;
    margin-bottom: 0;
    padding: 8px;
  }

  .feedback {
    position: absolute;
    top: 50px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.8rem;
    padding: 6px 16px;
    min-height: auto;
    z-index: 10;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    border-radius: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }

  .piano-wrapper {
    flex: 1;
    align-items: center;
  }

  .wk {
    height: 100px;
    flex: 0 0 32px;
  }

  .bk {
    left: 65%;
    width: 58%;
    height: 60px;
  }

  .bk:active {
    height: 58px;
  }

  .settings-panel.landscape-fullscreen {
    width: 100%;
    max-width: none;
  }
}

/* ========== 桌面端键盘优化 ========== */
@media (min-width: 800px) {
  .piano-wrapper {
    background: #e8e8e8;
    border-radius: 12px;
    padding: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  }

  .wk {
    height: 150px;
  }

  .bk {
    height: 90px;
  }

  .bk:active {
    height: 88px;
  }
}
