:root {
  --bg: #fff7ed;
  --surface: #fffaf2;
  --surface-strong: #fff2df;
  --ink: #34271e;
  --muted: #786657;
  --line: #dfc2a3;
  --accent: #b96f35;
  --accent-dark: #7c4425;
  --gold: #ffcf73;
  --wood-a: #c77c43;
  --wood-b: #8a4a2b;
  --metal-a: #f8fbff;
  --metal-b: #aebbcc;
  --metal-c: #6f8094;
  --focus: #2d6cdf;
  font-family: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 8%, rgba(255, 223, 169, 0.55), transparent 28%),
    linear-gradient(145deg, #fff9ef 0%, #f2dec4 100%);
}

button,
select,
input {
  font: inherit;
}

button,
select {
  min-height: 42px;
  border: 2px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  background: #fffaf1;
}

button {
  cursor: pointer;
  padding: 0 16px;
  font-weight: 800;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease, box-shadow 150ms ease;
}

button:hover {
  transform: translateY(-1px);
  border-color: #c89059;
  box-shadow: 0 8px 18px rgba(92, 53, 28, 0.12);
}

button:active,
.tine:active {
  transform: translateY(1px);
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
.tine:focus-visible {
  outline: 3px solid rgba(45, 108, 223, 0.35);
  outline-offset: 3px;
}

.app-shell {
  width: min(1400px, calc(100% - 32px));
  min-height: calc(100vh - 32px);
  margin: 16px auto;
  padding: 28px;
  border: 2px solid #ead2b8;
  border-radius: 28px;
  background: rgba(255, 250, 243, 0.94);
  box-shadow: 0 22px 50px rgba(80, 46, 25, 0.18);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 22px;
  border-bottom: 2px solid #e4c7a8;
}

.brand {
  min-width: 260px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.8rem, 3vw, 2.55rem);
  line-height: 1.1;
}

h2 {
  margin-bottom: 0;
  font-size: 1.08rem;
}

h3 {
  margin-bottom: 12px;
  font-size: 1rem;
}

.top-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 12px;
}

.control-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 4px 4px 4px 14px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: #fff5e7;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 800;
}

.control-chip select {
  min-height: 34px;
  padding: 0 28px 0 10px;
  border: 0;
  background-color: #fffaf1;
  font-weight: 900;
}

.ghost-button {
  background: #fff5e7;
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(220px, 0.82fr) minmax(480px, 2.1fr) minmax(220px, 0.82fr);
  gap: 24px;
  padding: 28px 0 24px;
}

.panel,
.instrument-panel,
.quick-controls {
  border: 2px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.58);
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 16px;
  border-bottom: 2px solid #e5cbb0;
}

.panel-heading span {
  padding: 6px 10px;
  border-radius: 999px;
  color: #744827;
  background: #ffe6bf;
  font-size: 0.82rem;
  font-weight: 900;
  white-space: nowrap;
}

.current-note-card,
.bpm-card {
  display: grid;
  gap: 10px;
  padding: 18px;
  border: 1px solid #dfc2a3;
  border-radius: 16px;
  background: #f9ecdc;
}

.current-note-card span,
.bpm-card span {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 800;
}

.current-note-card strong,
.bpm-card strong {
  font-family: Inter, Arial, sans-serif;
  color: #80502d;
  font-size: 2.2rem;
  line-height: 1;
}

.slider-control {
  display: grid;
  gap: 12px;
  color: var(--muted);
  font-weight: 800;
}

.slider-control span {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}

.segmented-control legend {
  grid-column: 1 / -1;
  margin-bottom: 4px;
  color: var(--muted);
  font-weight: 800;
}

.segmented-control label {
  min-width: 0;
}

.segmented-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-control span {
  display: grid;
  min-height: 40px;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #fffaf1;
  font-weight: 900;
}

.segmented-control input:checked + span {
  border-color: #bd7a2f;
  background: #ffe2a8;
}

.settings-panel {
  padding: 16px;
  border-radius: 16px;
  background: #fff3e4;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  color: var(--muted);
  font-weight: 800;
}

.instrument-panel {
  min-height: 560px;
  padding: 22px;
  background: linear-gradient(180deg, #f8e3c7 0%, #f3d3ac 100%);
  overflow: hidden;
}

.kalimba {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 514px;
  border-radius: 34% 34% 24% 24% / 26% 26% 18% 18%;
  background:
    radial-gradient(circle at 50% 54%, rgba(48, 22, 12, 0.88) 0 8%, transparent 8.5%),
    radial-gradient(circle at 50% 54%, rgba(255, 200, 119, 0.88) 0 12%, transparent 12.6%),
    linear-gradient(180deg, var(--wood-a), var(--wood-b));
  box-shadow:
    inset 0 8px 18px rgba(255, 226, 178, 0.35),
    inset 0 -20px 36px rgba(58, 24, 13, 0.28),
    0 18px 34px rgba(77, 42, 22, 0.22);
}

.kalimba::before {
  position: absolute;
  top: 58px;
  width: 58%;
  height: 38px;
  border-top: 7px solid rgba(246, 183, 112, 0.74);
  border-radius: 50%;
  content: "";
}

.kalimba-bridge {
  position: absolute;
  top: 118px;
  left: 50%;
  z-index: 4;
  width: min(480px, 72%);
  height: 48px;
  border-radius: 16px;
  background:
    linear-gradient(180deg, #332018 0 52%, #dcb58f 52% 100%);
  transform: translateX(-50%);
  box-shadow: 0 8px 16px rgba(40, 20, 12, 0.2);
}

.tine-board {
  position: absolute;
  top: 126px;
  left: 50%;
  z-index: 5;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: clamp(3px, 0.8vw, 9px);
  width: min(560px, 82%);
  height: 324px;
  transform: translateX(-50%);
}

.tine {
  position: relative;
  display: flex;
  flex: 0 1 25px;
  align-items: flex-end;
  justify-content: center;
  min-width: 18px;
  max-width: 32px;
  padding: 0 0 18px;
  border: 1px solid #718194;
  border-radius: 999px;
  color: #26394d;
  background:
    linear-gradient(135deg, var(--metal-a) 0%, var(--metal-b) 48%, var(--metal-c) 100%);
  box-shadow:
    inset 5px 0 7px rgba(255, 255, 255, 0.6),
    inset -5px 0 8px rgba(65, 79, 96, 0.2),
    0 8px 14px rgba(37, 23, 16, 0.16);
  font-family: Inter, Arial, sans-serif;
  font-size: 0.92rem;
  font-weight: 900;
  user-select: none;
  touch-action: manipulation;
}

.tine small {
  position: absolute;
  top: 12px;
  color: rgba(38, 57, 77, 0.7);
  font-size: 0.64rem;
}

.tine.is-playing {
  border-color: #8c5a24;
  background:
    linear-gradient(135deg, #fffdf6 0%, #ffd77a 46%, #aebbcc 100%);
  box-shadow:
    inset 5px 0 8px rgba(255, 255, 255, 0.72),
    0 0 0 5px rgba(255, 210, 110, 0.28),
    0 12px 20px rgba(37, 23, 16, 0.2);
}

.sound-hole {
  position: absolute;
  top: 304px;
  left: 50%;
  z-index: 2;
  width: 120px;
  height: 120px;
  border: 8px solid rgba(245, 177, 101, 0.82);
  border-radius: 50%;
  background: #2c1710;
  transform: translateX(-50%);
  box-shadow: inset 0 8px 18px rgba(0, 0, 0, 0.36);
}

.instrument-hint {
  position: absolute;
  right: 24px;
  bottom: 18px;
  left: 24px;
  z-index: 6;
  margin: 0;
  color: rgba(255, 246, 232, 0.92);
  font-size: 0.9rem;
  font-weight: 800;
  text-align: center;
  text-shadow: 0 1px 3px rgba(54, 26, 15, 0.55);
}

.bpm-card input {
  margin-top: 8px;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.primary-button,
.button-grid button.is-active,
.wide-button.is-active,
.quick-buttons .is-active {
  border-color: #bd7a2f;
  background: #ffe2a8;
}

.wide-button {
  width: 100%;
}

.mini-stats {
  display: grid;
  gap: 10px;
  margin: auto 0 0;
}

.mini-stats div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  font-weight: 800;
}

.mini-stats dd {
  margin: 0;
  color: var(--ink);
}

.quick-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 22px;
  background: #fff4e6;
}

.quick-title {
  display: grid;
  gap: 4px;
}

.quick-title span {
  color: var(--muted);
  font-family: Inter, Arial, sans-serif;
  font-size: 0.86rem;
  font-weight: 800;
}

.quick-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

@media (max-width: 1080px) {
  .app-shell {
    padding: 20px;
  }

  .topbar,
  .quick-controls {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-controls,
  .quick-buttons {
    justify-content: flex-start;
  }

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

  .instrument-panel {
    grid-column: 1 / -1;
    grid-row: 1;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 16px, 520px);
    margin: 8px auto;
    padding: 14px;
    border-radius: 18px;
  }

  .topbar {
    gap: 16px;
  }

  .top-controls,
  .control-chip,
  .quick-buttons {
    width: 100%;
  }

  .control-chip,
  .top-controls button,
  .quick-buttons button {
    flex: 1 1 140px;
  }

  .main-grid {
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 18px 0;
  }

  .panel,
  .instrument-panel,
  .quick-controls {
    border-radius: 16px;
  }

  .panel,
  .instrument-panel {
    padding: 16px;
  }

  .instrument-panel {
    min-height: 444px;
  }

  .kalimba {
    min-height: 410px;
  }

  .kalimba-bridge {
    top: 88px;
    width: 78%;
  }

  .tine-board {
    top: 96px;
    width: 88%;
    height: 250px;
    gap: 3px;
  }

  .tine {
    min-width: 13px;
    padding-bottom: 12px;
    font-size: 0.68rem;
  }

  .tine small {
    display: none;
  }

  .sound-hole {
    top: 238px;
    width: 88px;
    height: 88px;
  }

  .instrument-hint {
    font-size: 0.78rem;
  }
}
