:root {
  color-scheme: dark;
  --ink: #f8f4e8;
  --muted: #b7b09e;
  --back: #151411;
  --panel: #201f1a;
  --panel-strong: #2b2922;
  --line: #484338;
  --lime: #c7ff4a;
  --coral: #ff7a59;
  --amber: #ffc857;
  --cyan: #73e0d4;
  --danger: #ff8a8a;
  --shadow: 0 18px 55px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background:
    linear-gradient(120deg, rgba(255, 200, 87, 0.07), transparent 30%),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.03) 0 1px, transparent 1px 68px),
    var(--back);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: "Yu Gothic UI", "Yu Gothic", Meiryo, Verdana, sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid var(--lime);
  outline-offset: 3px;
}

.app-shell {
  width: min(1160px, calc(100% - 28px));
  margin: 0 auto;
  padding: 22px 0 34px;
  display: grid;
  gap: 14px;
}

.stage,
.session-panel,
.control-panel,
.tools-panel,
.auto-panel,
.piano-panel,
.peers-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(32, 31, 26, 0.92);
  box-shadow: var(--shadow);
}

.stage {
  min-height: 210px;
  padding: clamp(20px, 4vw, 42px);
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 18px;
}

.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(95deg, rgba(199, 255, 74, 0.15), transparent 42%),
    linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.24));
  pointer-events: none;
}

.identity,
.signal-strip,
.meter {
  position: relative;
  z-index: 1;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--lime);
  font-size: 0.78rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-family: Georgia, "Yu Mincho", serif;
  font-size: clamp(2.7rem, 8vw, 6.5rem);
  line-height: 0.9;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 7px;
  font-size: 1.05rem;
  letter-spacing: 0;
}

.signal-strip {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 220px;
  padding: 10px 12px;
  border: 1px solid rgba(248, 244, 232, 0.2);
  border-radius: 8px;
  background: rgba(21, 20, 17, 0.72);
  color: var(--ink);
}

.pulse {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 6px rgba(255, 200, 87, 0.14);
}

.pulse.online {
  background: var(--lime);
  box-shadow: 0 0 0 6px rgba(199, 255, 74, 0.14);
}

.pulse.error {
  background: var(--danger);
  box-shadow: 0 0 0 6px rgba(255, 138, 138, 0.14);
}

.meter {
  grid-column: 1 / -1;
  width: 100%;
  height: 90px;
  align-self: end;
}

.session-panel,
.peers-panel {
  padding: 18px;
}

.panel-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
}

.panel-head p,
.field-note {
  color: var(--muted);
  font-size: 0.9rem;
}

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

.join-form {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto;
  gap: 8px;
  align-items: end;
  padding: 14px;
  border: 1px solid rgba(248, 244, 232, 0.15);
  border-radius: 8px;
  background: var(--panel-strong);
}

.join-form label {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.86rem;
}

.join-form input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #11100e;
  color: var(--ink);
  padding: 0 12px;
}

.field-note,
.field-error {
  grid-column: 1 / -1;
  min-height: 1.15em;
  margin: -2px 0 0;
}

.field-error {
  color: var(--danger);
  font-size: 0.88rem;
}

.primary-button,
.secondary-button,
.danger-button,
.ghost-button {
  min-height: 44px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 0 14px;
  white-space: nowrap;
}

.primary-button {
  background: var(--lime);
  color: #151411;
  font-weight: 800;
}

.secondary-button {
  background: var(--coral);
  color: #151411;
  font-weight: 800;
}

.danger-button {
  background: #2a1212;
  border-color: rgba(255, 138, 138, 0.55);
  color: #ffdede;
  font-weight: 800;
}

.ghost-button {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}

.room-line {
  margin-top: 12px;
  display: grid;
  grid-template-columns: auto minmax(130px, max-content) auto auto;
  justify-content: start;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

#codeOutput {
  min-width: 9ch;
  padding: 8px 12px;
  border-radius: 6px;
  background: #11100e;
  color: var(--lime);
  font-family: Georgia, "Yu Mincho", serif;
  font-size: 1.65rem;
  letter-spacing: 0.12em;
  text-align: center;
}

.control-panel {
  display: grid;
  grid-template-columns: minmax(170px, 1fr) minmax(170px, 1fr) repeat(3, minmax(100px, auto));
  gap: 10px;
  align-items: center;
  padding: 12px;
}

.tools-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(108px, 1fr));
  gap: 10px;
  align-items: stretch;
  padding: 12px;
}

.tools-panel > button {
  min-height: 58px;
}

.tools-panel .ghost-button[aria-pressed="true"] {
  border-color: var(--lime);
  color: var(--lime);
  background: rgba(199, 255, 74, 0.08);
}

.auto-panel {
  padding: 14px;
}

.auto-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
}

.auto-head p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.file-picker {
  display: grid;
  gap: 7px;
  min-width: min(260px, 100%);
  color: var(--muted);
  font-size: 0.86rem;
}

.file-picker input {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #11100e;
  color: var(--ink);
  padding: 9px;
}

.auto-grid {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) repeat(3, minmax(96px, auto));
  gap: 10px;
  align-items: stretch;
  margin-top: 12px;
}

.auto-grid > button {
  min-height: 58px;
}

progress {
  width: 100%;
  height: 12px;
  margin-top: 12px;
  accent-color: var(--lime);
}

.range-control,
.select-control,
.metric {
  min-height: 58px;
  border: 1px solid rgba(248, 244, 232, 0.13);
  border-radius: 8px;
  background: rgba(17, 16, 14, 0.68);
  padding: 9px 11px;
}

.range-control,
.select-control {
  display: grid;
  gap: 7px;
}

.range-control span,
.select-control span,
.metric span {
  color: var(--muted);
  font-size: 0.78rem;
}

.select-control select {
  width: 100%;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #11100e;
  color: var(--ink);
  padding: 0 9px;
}

.metric {
  display: grid;
  gap: 4px;
}

.metric strong {
  color: var(--ink);
  font-size: 1rem;
  overflow-wrap: anywhere;
}

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

.piano-panel {
  padding: 14px;
  overflow-x: auto;
}

.piano {
  position: relative;
  min-width: calc(var(--white-count) * 50px);
  height: clamp(250px, 38vw, 350px);
  display: grid;
  grid-template-columns: repeat(var(--white-count), minmax(46px, 1fr));
  gap: 4px;
  padding: 4px;
  border-radius: 8px;
  background: linear-gradient(180deg, #0d0c0a, #252219);
  touch-action: none;
}

.key {
  border: 0;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 70ms ease, filter 70ms ease, box-shadow 70ms ease;
}

.key.white {
  position: relative;
  height: 100%;
  border-radius: 5px;
  background: linear-gradient(180deg, #fffdf5, #d9d1bd 78%, #b9b09c);
  color: #2b2922;
  box-shadow: inset 0 -11px 0 rgba(0, 0, 0, 0.1);
}

.key.black {
  position: absolute;
  top: 4px;
  z-index: 3;
  width: min(42px, calc(100% / var(--white-count) * 0.66));
  height: 62%;
  border-radius: 0 0 5px 5px;
  transform: translateX(-50%);
  background: linear-gradient(180deg, #1d1b17, #050504);
  color: var(--ink);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.42), inset 0 -6px 0 rgba(255, 255, 255, 0.05);
}

.key.active-local {
  filter: saturate(1.2) brightness(1.08);
  box-shadow: 0 0 0 3px rgba(199, 255, 74, 0.35), inset 0 -7px 0 rgba(0, 0, 0, 0.14);
  transform: translateY(3px);
}

.key.black.active-local {
  transform: translateX(-50%) translateY(3px);
}

.key.active-remote {
  box-shadow: 0 0 0 3px rgba(115, 224, 212, 0.42), inset 0 -7px 0 rgba(0, 0, 0, 0.14);
}

.note-label,
.key-label {
  position: absolute;
  left: 8px;
  right: 8px;
  pointer-events: none;
}

.note-label {
  bottom: 12px;
  font-weight: 800;
}

.key-label {
  bottom: 36px;
  color: rgba(43, 41, 34, 0.62);
  font-size: 0.76rem;
}

.black .note-label {
  bottom: 8px;
  color: rgba(248, 244, 232, 0.86);
  font-size: 0.78rem;
}

.black .key-label {
  display: none;
}

.peers-panel {
  min-height: 100px;
}

.peer-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
  padding: 0;
  margin: 0;
}

.peer-list li {
  padding: 8px 10px;
  border: 1px solid rgba(248, 244, 232, 0.15);
  border-radius: 999px;
  background: rgba(17, 16, 14, 0.7);
  color: var(--ink);
  font-size: 0.9rem;
}

@media (max-width: 820px) {
  .stage,
  .session-grid,
  .control-panel,
  .tools-panel,
  .auto-grid {
    grid-template-columns: 1fr;
  }

  .auto-head {
    flex-direction: column;
  }

  .signal-strip {
    width: 100%;
  }

  .join-form {
    grid-template-columns: 1fr;
  }

  .room-line {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .key {
    transition: none;
  }
}
