/* Fidget Box 3000: a pocket synth in Zathu's hardware language.
   Shared by the site's hero and the /synth app. Graphite body, flat recessed screen,
   one hot orange, keys that press down. */

.hardware-chassis-card {
  --fb-body: #1c1e22;
  --fb-key: #2a2d33;
  --fb-key-hi: #353941;
  --fb-well: #0e0f11;
  --fb-shade: #0a0b0d;
  --fb-ink: #ece9e3;
  --fb-dim: #a0a29f;
  --fb-hot: #ff5a1f;
  --fb-hot-dark: #b83a0a;
  --fb-amber: #ffc766;
  --fb-font: 'Bricolage Grotesque', system-ui, -apple-system, sans-serif;

  background: var(--fb-body);
  color: var(--fb-ink);
  font-family: var(--fb-font);
  border-radius: 22px;
  box-shadow: 0 8px 0 var(--fb-shade);
  padding: 8px;
  position: relative;
  overflow: hidden;
}

.hardware-chassis-card button { font-family: var(--fb-font); }
.hardware-chassis-card button:focus-visible,
.hardware-chassis-card input:focus-visible + .arp-slider { outline: 3px solid var(--fb-hot); outline-offset: 2px; }

/* Header: the Z, the name, one button */
.hardware-rack-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  padding: 10px 12px 12px;
}
.rack-header-left { display: flex; align-items: center; gap: 10px; }
/* A generous invisible tap target around the Z (negative margins keep the layout unchanged) */
.rack-z-hit {
  display: flex; padding: 14px 8px 14px 14px; margin: -14px -8px -14px -14px;
  cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.rack-z {
  width: 18px; height: 18px; background: var(--fb-hot);
  cursor: pointer;
  clip-path: polygon(0 0, 100% 0, 100% 26%, 38% 74%, 100% 74%, 100% 100%, 0 100%, 0 74%, 62% 26%, 0 26%);
}
@keyframes rack-z-jam { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.3) rotate(8deg); } }
.rack-z.jamming { animation: rack-z-jam 0.75s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .rack-z.jamming { animation: none; } }
.tune-menu {
  position: absolute; z-index: 20; top: 58px; left: 12px; right: 12px; max-width: 340px;
  display: flex; flex-direction: column; gap: 6px; padding: 10px;
  background: var(--fb-well); border-radius: 14px; box-shadow: 0 6px 0 var(--fb-shade), 0 0 0 2px var(--fb-key);
}
.tune-menu[hidden] { display: none; }
.tune-menu-head { font-size: .72rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--fb-dim); padding: 2px 4px 4px; }
.tune-menu-item {
  background: var(--fb-key); border: 0; border-radius: 8px; color: var(--fb-ink); cursor: pointer;
  font-size: .95rem; font-weight: 600; text-align: left; padding: 10px 12px; box-shadow: 0 3px 0 var(--fb-shade);
  transition: transform .12s cubic-bezier(.22,1,.36,1), box-shadow .12s cubic-bezier(.22,1,.36,1), background-color .15s;
}
.tune-menu-item:hover { background: var(--fb-key-hi); }
.tune-menu-item:active { transform: translateY(3px); box-shadow: 0 0 0 var(--fb-shade); transition-duration: .04s; }
/* Surprise: fills left to right like a progress bar while its song plays */
#surprise-btn { position: relative; overflow: hidden; isolation: isolate; }
#surprise-btn::before {
  content: ''; position: absolute; inset: 0; z-index: -1;
  background: var(--fb-hot-dark); transform: scaleX(0); transform-origin: left center;
}
#surprise-btn.playing::before { animation: surprise-fill var(--dur, 12s) linear forwards; }
@keyframes surprise-fill { to { transform: scaleX(1); } }
.rack-title { font-size: 1.05rem; font-weight: 800; letter-spacing: -0.02em; color: var(--fb-ink); }
.rack-header-right { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

/* Shared key feel */
.rack-btn, .scope-btn, .mode-btn, .hold-btn, .arp-opt-btn {
  background: var(--fb-key);
  border: 0;
  color: var(--fb-ink);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  box-shadow: 0 3px 0 var(--fb-shade);
  transition: transform .12s cubic-bezier(.22,1,.36,1), box-shadow .12s cubic-bezier(.22,1,.36,1), background-color .15s;
}
.rack-btn:hover, .scope-btn:hover, .mode-btn:hover, .hold-btn:hover, .arp-opt-btn:hover:not(:disabled) { background: var(--fb-key-hi); }
.rack-btn:active, .scope-btn:active, .mode-btn:active, .hold-btn:active, .arp-opt-btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 0 0 var(--fb-shade); transition-duration: .04s; }
.scope-btn.active, .mode-btn.active, .hold-btn.active, .arp-opt-btn.active {
  background: var(--fb-hot); color: #160700; box-shadow: 0 3px 0 var(--fb-hot-dark);
}
.scope-btn.active:active, .mode-btn.active:active, .hold-btn.active:active, .arp-opt-btn.active:active { box-shadow: 0 0 0 var(--fb-hot-dark); }

.rack-btn { font-size: .85rem; padding: 7px 12px; }

/* Screen: a flat recessed well */
.oscilloscope-screen-wrapper {
  background: var(--fb-well);
  border-radius: 16px;
  padding: 10px 10px 12px;
  position: relative;
}
.oscilloscope-crt-frame { position: relative; overflow: hidden; border-radius: 10px; }
.oscilloscope-canvas { width: 100%; height: 180px; display: block; touch-action: none; background: var(--fb-well); }

.oscilloscope-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; padding: 0 2px; font-size: .9rem; color: var(--fb-dim); }
.scope-wave-selector { display: flex; gap: 8px; flex-shrink: 0; }
.scope-btn { font-size: .82rem; padding: 6px 11px; }

/* Controls */
.synth-bar-controls { padding: 14px 6px 8px; }
.mode-switcher-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.key-btn-group { display: flex; gap: 6px; flex: 1 1 100%; }
.key-btn-group .key-btn { flex: 1 1 0; min-width: 0; padding: 8px 0; text-align: center; font-size: .85rem; }
.key-btn-group .key-btn-sharp:not(.active) { background: #222429; color: var(--fb-dim); }
.mode-btn-group { display: flex; flex-wrap: wrap; gap: 6px; flex: 1 1 100%; }
.mode-btn-group .mode-btn { flex: 1 1 auto; text-align: center; font-size: .85rem; padding: 8px 10px; }

/* The eight note keys: big, chunky, they press down */
.synth-keys-grid { display: flex; flex-wrap: nowrap; gap: 8px; width: 100%; }
.synth-key {
  flex: 1 1 0; min-width: 0;
  background: var(--fb-key); border: 0; border-radius: 12px;
  padding: 18px 2px 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 2px;
  cursor: pointer; user-select: none; text-align: center; overflow: hidden;
  box-shadow: 0 6px 0 var(--fb-shade);
  transition: transform .1s cubic-bezier(.22,1,.36,1), box-shadow .1s cubic-bezier(.22,1,.36,1), background-color .12s;
}
.synth-key:hover { background: var(--fb-key-hi); }
.synth-key:active, .synth-key.key-pressed, .synth-key.key-held {
  transform: translateY(5px); box-shadow: 0 1px 0 var(--fb-shade);
  background: var(--fb-hot); transition-duration: .04s;
}
.synth-note-name { font-size: 1.1rem; font-weight: 800; letter-spacing: -0.02em; color: var(--fb-ink); white-space: nowrap; }
.synth-key-degree { font-size: .72rem; color: var(--fb-dim); white-space: nowrap; }
.synth-key-shortcut { font-size: .72rem; font-weight: 700; color: var(--fb-dim); margin-top: 8px; }
.synth-key.is-root .synth-key-degree { color: var(--fb-hot); font-weight: 700; }
.synth-key:active .synth-note-name, .synth-key.key-pressed .synth-note-name, .synth-key.key-held .synth-note-name,
.synth-key:active .synth-key-degree, .synth-key.key-pressed .synth-key-degree, .synth-key.key-held .synth-key-degree,
.synth-key:active .synth-key-shortcut, .synth-key.key-pressed .synth-key-shortcut, .synth-key.key-held .synth-key-shortcut { color: #160700; }

/* Notes / arpeggiator switch, hold */
.arp-switcher { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px 12px; margin: 18px 0 10px; font-size: .9rem; }
.arp-label { color: var(--fb-dim); transition: color .2s; }
.arp-label.active { color: var(--fb-ink); font-weight: 700; }
.arp-switch { position: relative; display: inline-block; width: 52px; height: 28px; cursor: pointer; }
.arp-switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.arp-slider { position: absolute; inset: 0; background: var(--fb-well); border-radius: 999px; pointer-events: none; }
.arp-slider::before {
  content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--fb-dim);
  transition: transform .3s cubic-bezier(0.34, 1.36, 0.64, 1), background-color .2s;
}
.arp-switch input:checked + .arp-slider::before { transform: translateX(24px); background: var(--fb-hot); }
.octave-group { display: flex; align-items: center; gap: 8px; margin-left: 10px; font-size: .85rem; }
.hold-btn { margin-left: 10px; font-size: .85rem; padding: 6px 12px; }
.hold-key-hint { opacity: .6; margin-left: 4px; }

.arp-options { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 0 0 8px; font-size: .85rem; transition: opacity .2s; }
.arp-options.is-off { opacity: .4; }
.arp-opt-label { color: var(--fb-dim); }
.arp-opt-gap { margin-left: 12px; }
.arp-notes-val { min-width: 1.4em; text-align: center; color: var(--fb-ink); font-weight: 800; }
.arp-end-group { display: flex; gap: 6px; }
.arp-opt-btn { font-size: .8rem; padding: 5px 10px; }
.arp-step-btn { min-width: 30px; padding: 4px 0; font-size: 1rem; line-height: 1; }
.arp-opt-btn:disabled { cursor: not-allowed; opacity: .4; }

/* Hints that need a keyboard */
@media (hover: none) and (pointer: coarse) {
  .synth-key-shortcut, .hold-key-hint { display: none; }
}

/* Maximized: header and controls stay visible, the screen takes the remaining space */
body.scope-max-open { overflow: hidden; }
.hardware-chassis-card.scope-maximized {
  position: fixed; inset: 0; z-index: 10000; display: flex; flex-direction: column;
  border-radius: 0; box-shadow: none; overflow-y: auto; padding: 8px 12px 12px;
}
.scope-maximized .oscilloscope-screen-wrapper { flex: 1; min-height: 200px; display: flex; flex-direction: column; }
.scope-maximized .oscilloscope-crt-frame { flex: 1; min-height: 0; }
.scope-maximized .oscilloscope-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.scope-maximized .oscilloscope-meta { flex-wrap: wrap; gap: 8px; }

/* Status: always two lines so nothing shifts */
#scope-status-text { flex: 1 1 0; min-width: 0; line-height: 1.35; min-height: 2.7em; margin-right: 12px; }

/* The /synth app (body.synth-app): the rack fills the viewport, no full-screen toggle,
   safe areas keep it clear of notches and the home indicator when installed. */
body.synth-app { background: #131416; }
body.synth-app::before { display: none; }
body.synth-app .rack-max-btn { display: none; }
body.synth-app .hardware-chassis-card.scope-maximized {
  padding: calc(8px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
}

@media (max-width: 560px) {
  .key-btn-group { gap: 4px; }
  .synth-keys-grid { gap: 5px; }
  .synth-key { padding: 14px 0 10px; border-radius: 10px; }
  .oscilloscope-meta { flex-direction: column; align-items: stretch; gap: 10px; }
  .scope-wave-selector { flex-wrap: wrap; }
  .scope-btn { flex: 1 1 auto; }
}
@media (prefers-reduced-motion: reduce) {
  .hardware-chassis-card *, .hardware-chassis-card *::before { transition-duration: .01ms !important; }
}
