/* global styles */

:root {
  /* Chrome-only for now but this will allow smooth size transitions */
  interpolate-size: allow-keywords;

  --accent-color: #ffb020;

  /* TONEBENCH rack palette */
  --bg-deep: #14110d;
  --panel: #1e1a14;
  --panel-raised: #262019;
  --panel-line: #3a3226;
  --amber: #ffb020;
  --amber-dim: #7a5a1e;
  --amber-glow: rgba(255, 176, 32, 0.35);
  --green: #6dff8f;
  --red: #ff5c4d;
  --text: #e8ddc8;
  --text-muted: #8a7f6c;
  --font-display: 'Space Mono', monospace;
  --font-body: 'IBM Plex Mono', monospace;
}

html {
  box-sizing: border-box;
}

*,
*:before,
*:after {
  box-sizing: inherit;
}

body {
  display: flex;
  flex-direction: column;
  padding: 0;
  margin: 0;
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(255, 176, 32, 0.06), transparent 60%),
    var(--bg-deep);
  color: var(--text);

  font-family: var(--font-body);
  font-style: normal;
  font-variant: normal;
}

footer,
header {
  flex: 0;
  min-height: 50px;
  height: 50px;
  display: flex;
  align-items: center;

  img {
    max-height: 40px;
    margin-right: 0.5em;
  }

  h1 {
    flex: 1;
    margin-right: 50px;
    text-align: center;
  }
}

header#main-head {
  justify-content: space-between;
  padding: 0 8px;
  border-bottom: 1px solid var(--panel-line);
  background: var(--panel);
}

.header-identity {
  text-decoration: none;
  color: inherit;

  h1 {
    font-family: var(--font-display);
    font-size: 24px;
  }
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.06em;
  font-variant: normal;
  color: var(--text);
}

#main-head > * {
  display: flex;
  flex-direction: row;
  align-items: center;
}

#logo {
  height: 40px;
  margin: 0 10px 0 5px;
}

#main-foot {
  border-top: 1px solid var(--panel-line);
  justify-content: center;
  background: var(--panel);
  color: var(--text-muted);
  font-size: 11px;
  letter-spacing: 0.06em;
}

main {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  max-width: 100vw;
  overflow: hidden;

  padding: 8px;
  overflow-y: auto;
  background-color: var(--bg-deep);
}

.btn,
button,
input[type='file']::file-selector-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  padding: 0.5em 1em;
  border-radius: 3px;
  background: var(--panel-raised);
  color: var(--text);
  border: 1px solid var(--panel-line);
  cursor: pointer;
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-variant: normal;
  text-decoration: none;

  img {
    height: 2em;
    width: 2em;
    margin: 0 0.25rem;
  }

  &:disabled {
    cursor: not-allowed;

    img {
      opacity: 0.5;
    }
  }

  &:not(:disabled):hover,
  &:not(:disabled):focus-visible {
    outline: none;
    border-color: var(--amber-dim);
    color: var(--amber);
    background-color: var(--panel-raised);
  }
}

input[type='file'] {
  border-radius: 5px;
  border: 1px solid #ccc;
  cursor: pointer;

  &::file-selector-button {
    display: inline-flex;
  }

  &:not(:disabled):hover,
  &:not(:disabled):focus-visible {
    outline: var(--accent-color) auto 1px;

    &::file-selector-button {
      background-color: #ddbfc67a;
    }
  }
}

a.btn {
  &:not(:disabled):hover,
  &:not(:disabled):focus-visible {
    text-decoration: underline;
  }
}

a:focus-visible {
  outline: var(--accent-color) auto 1px;
}

/* util classes */

.u-hidden {
  display: none !important;
}

.u-flex {
  display: flex;
}

.u-flex-column {
  flex-direction: column;
}

.u-flex-1 {
  flex: 1;
}

.u-left {
  text-align: left;
}

.u-center {
  text-align: center;
}

.u-fill-width {
  width: -webkit-fill-available;
  width: 100%;
}

.u-fill-height {
  height: -webkit-fill-available;
  height: 100vh;
}

.u-stretch-height {
  height: -webkit-fill-available;
  height: 100%;
  flex: 1;
}

/* background scroll fix for dialogs */
dialog {
  overscroll-behavior: contain;
}

dialog::backdrop {
  overflow: hidden;
  overscroll-behavior: contain;
}

/* responsive design tweaks (breakpoints adopted from Bootstrap) */

/* Small devices (e.g. phones, 575px and under) */
@media (max-width: 575px) {
  header > img {
    display: none;
  }
}

/* Small devices (landscape phones, 576px and up) */
@media (min-width: 576px) {
  header > img {
    display: none;
  }
}

/* Medium devices (tablets, 768px and up) */
@media (min-width: 768px) {
  header > img {
    display: block;
  }
}

/* Large devices (desktops, 992px and up) */
@media (min-width: 992px) {
  header > img {
    display: block;
  }
}

/* ---------- TONEBENCH rack layout ----------
   These elements are light DOM (rendered by index.ts directly, not inside a
   component's Shadow DOM), so they can't reach the panel/screw/module-label
   rules in components/styles/panelChrome.ts — Shadow DOM styles don't cross
   the shadow boundary. This is an intentional near-duplication of that file
   for the handful of light-DOM elements (the presets panel + rack status);
   every *component* still shares the one PANEL_CHROME_CSS constant. */

.rack {
  max-width: 1180px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 4px;
  padding: 16px 18px;
}
.panel .screw {
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #0000;
  box-shadow:
    inset 0 0 0 1px var(--panel-line),
    inset 0 0 2px #000;
}
.panel .screw-tl {
  top: 6px;
  left: 6px;
}
.panel .screw-tr {
  top: 6px;
  right: 6px;
}
.panel .screw-bl {
  bottom: 6px;
  left: 6px;
}
.panel .screw-br {
  bottom: 6px;
  right: 6px;
}

.module-label {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--amber);
  text-transform: uppercase;
  margin: 0 0 12px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.module-label .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 6px var(--amber-glow);
}

.rack-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 18px;
}
.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.brand-lockup img {
  width: 42px;
  height: 42px;
}
.brand-lockup h1 {
  margin: 0;
  font-size: 31px;
  line-height: 1;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.brand-lockup h1 span {
  color: var(--amber);
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-left: auto;
}
.led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--panel-line);
  box-shadow: inset 0 0 2px #000;
  transition:
    background 0.15s,
    box-shadow 0.15s;
}
.led.on {
  background: var(--green);
  box-shadow: 0 0 8px rgba(109, 255, 143, 0.7);
}

.top-grid {
  display: block;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  align-items: stretch;
}
@media (max-width: 980px) {
  .controls-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
@media (max-width: 560px) {
  .controls-grid {
    grid-template-columns: 1fr;
  }
}

.mutate-row {
  display: flex;
  justify-content: flex-end;
}
.btn.mutate {
  color: var(--red);
  border-color: #5a2a24;
}
.btn.mutate:hover {
  border-color: var(--red);
}

.rack-footer {
  text-align: center;
  font-size: 10.5px;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  padding: 6px 0 2px;
}
.rack-footer a {
  color: var(--text);
  text-decoration: none;
}
.rack-footer a:hover,
.rack-footer a:focus-visible {
  color: var(--amber);
  text-decoration: underline;
}
.rack-footer span {
  display: inline-block;
  margin: 0 8px;
  color: var(--panel-line);
}

/* Custom elements default to `display: inline`; every TONEBENCH component
   is a block-level layout participant (grid item, flex child, or full-width
   field row). */
range-field,
wave-toggle,
source-panel,
envelope-panel,
filter-panel,
space-panel,
oscilloscope-panel,
code-out-panel,
sound-set-drawer {
  display: block;
  min-width: 0;
}
code-out-panel {
  height: 100%;
}

.code-modal {
  width: min(1040px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  padding: 0;
  color: var(--text);
  background: transparent;
  border: 0;
}
.code-modal::backdrop {
  background: rgba(12, 10, 7, 0.76);
  backdrop-filter: blur(3px);
}
.code-modal-shell {
  display: grid;
  gap: 8px;
  min-width: 0;
}
.code-modal-close {
  justify-self: end;
  padding: 5px 9px;
  color: var(--text-muted);
  background: var(--panel);
}
.code-modal-close:hover,
.code-modal-close:focus-visible {
  color: var(--amber);
}
.code-modal code-out-panel {
  height: min(78vh, 720px);
}

/* ---------- sound sets drawer ----------
   Same <dialog> mechanics as .code-modal (showModal()/backdrop/focus-trap),
   but pinned to the right edge and stretched full-height, with a slide-in
   transform instead of a center fade — a drawer, not a centered modal. */
.soundsets-modal {
  position: fixed;
  inset: 0 0 0 auto;
  margin: 0;
  width: min(360px, 100vw);
  height: 100vh;
  max-height: 100vh;
  padding: 0;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: 0;
}
.soundsets-modal::backdrop {
  background: rgba(12, 10, 7, 0.76);
  backdrop-filter: blur(3px);
}
.soundsets-modal-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 8px;
  height: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding: 14px;
  overflow-y: auto;
  background: var(--bg-deep);
  border-left: 1px solid var(--panel-line);
}
.soundsets-modal-close {
  justify-self: end;
  padding: 5px 9px;
  color: var(--text-muted);
  background: var(--panel);
}
.soundsets-modal-close:hover,
.soundsets-modal-close:focus-visible {
  color: var(--amber);
}

.soundsets-modal,
.soundsets-modal::backdrop {
  transition:
    opacity 0.25s,
    transform 0.25s allow-discrete;
  opacity: 0;
}
.soundsets-modal[open],
.soundsets-modal[open]::backdrop {
  opacity: 1;
}
.soundsets-modal[open] {
  transform: translateX(0);
}
@starting-style {
  .soundsets-modal[open] {
    opacity: 0;
    transform: translateX(100%);
  }
  .soundsets-modal[open]::backdrop {
    opacity: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .soundsets-modal,
  .soundsets-modal::backdrop {
    transition: none;
  }
}

@media (max-width: 575px) {
  .rack-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }
  .brand-lockup img {
    display: none;
  }
  .brand-lockup h1 {
    font-size: 27px;
  }
  .status {
    margin-left: 0;
  }
}

/* web component placeholders */
update-notification {
  display: none;
  --update-notification-bg: linear-gradient(135deg, #7a7a7a 0%, #3a3a3a 50%, #5a5a5a 100%);
  --update-notification-color: white;
  --update-notification-border: transparent;
  --update-notification-btn-bg: white;
  --update-notification-btn-color: #5a5a5a;
  --update-notification-btn-hover: #f0f0f0;
}

/* view transitions */

@view-transition {
  navigation: auto;
  types: slide, forwards;
}
