/* ============================================================================
   PATTERN64 — Amiga-Workbench-inspiriertes Retro-Design
   Schlichtes Vanilla-CSS, keine Frameworks. Responsive: ab ~1000px Klappanordnung,
   ab ~600px Touch-Ziele; auf sehr breitenScreens skalieren Raster und Seite hoch.
   Die Rasterspalten füllen verfügbare Breite aus (und scrollen, wenn sie nicht passen).
   ========================================================================= */

:root {
  --bg: #062c4d;
  --bg2: #04223c;
  --panel: #000407;
  --panel2: #000000;
  --bevel-hi: #4f8fc4;
  --bevel-lo: #021626;
  --ink: #d9ecff;
  --ink-dim: #86aed0;
  --accent: #ffd23f;
  --accent2: #41e0c0;
  --sel: #ffb347;
  --row-h: 22px;
  --cell-w: 9.5ch;
  --mono: "Noto Sans Mono", "DejaVu Sans Mono", ui-monospace, "Courier New", monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 70% -10%, #0d5a94 0%, transparent 60%),
    repeating-linear-gradient(0deg, transparent 0 3px, rgba(0,0,0,.07) 3px 4px),
    linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------------------------------------------------------------- Kopf */
#top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: linear-gradient(180deg, #000910, #062f52);
  border-bottom: 3px solid var(--bevel-lo);
  box-shadow: 0 2px 0 var(--bevel-hi) inset, 0 12px 24px rgba(0,0,0,.35);
}
.brand h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: 2px;
  color: #fff;
  text-shadow: 2px 2px 0 #001222, 0 0 14px rgba(65,224,192,.35);
}
.brand h1 span { color: var(--accent); }
.brand .sub { font-size: 10px; color: var(--ink-dim); letter-spacing: 1px; }
.hgroup { display: flex; flex-direction: column; gap: 6px; flex: 1 1 340px; min-width: 0; }

.panel-block {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--panel);
  border: 2px solid;
  border-color: var(--bevel-hi) var(--bevel-lo) var(--bevel-lo) var(--bevel-hi);
}
.lbl { color: var(--accent2); font-size: 11px; letter-spacing: 1px; text-transform: uppercase; }
.ctl { display: inline-flex; align-items: center; gap: 5px; color: var(--ink-dim); font-size: 11px; }
.ctl.wide { display: flex; width: 100%; justify-content: space-between; margin: 3px 0; }

input, select, button {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink);
  background: #052a49;
  border: 2px solid;
  border-color: var(--bevel-lo) var(--bevel-hi) var(--bevel-hi) var(--bevel-lo);
  padding: 3px 6px;
}
input[type="range"] { padding: 0; width: 90px; accent-color: var(--accent2); }
input[type="checkbox"] { accent-color: var(--accent); transform: scale(1.15); }
select { max-width: 190px; }
button {
  background: linear-gradient(180deg, #7fb6e6, #3f78ad);
  border-color: #b9dcff #073a63 #073a63 #b9dcff;
  color: #04182b;
  font-weight: 700;
  cursor: pointer;
  padding: 3px 9px;
  text-shadow: 0 1px 0 rgba(255,255,255,.25);
}
button:hover { filter: brightness(1.12); }
button:active { border-color: #073a63 #b9dcff #b9dcff #073a63; transform: translateY(1px); }
button.big { font-size: 15px; min-width: 38px; }
button.pressed { background: linear-gradient(180deg, #ffd23f, #d8a214); color: #2b1c00; }
button.pressed-red { background: linear-gradient(180deg, #ff8a6a, #c43a22); color: #fff; }
button.off { filter: grayscale(1) brightness(.65); }
button:disabled { opacity: .4; cursor: not-allowed; }

#bpm { width: 64px; text-align: center; font-size: 14px; font-weight: 700; color: var(--accent); }
.pos { color: var(--accent2); font-size: 11px; margin-left: auto; white-space: nowrap; }
.digitbox {
  display: inline-block; min-width: 2.4ch; text-align: center;
  background: #03182c; color: var(--accent); font-size: 15px; font-weight: 700;
  border: 2px solid var(--bevel-lo); padding: 1px 5px;
}
.genbox { display: flex; align-items: center; gap: 8px; }
#btn-random {
  font-size: 15px; padding: 10px 14px; letter-spacing: 1px;
  background: linear-gradient(180deg, #ffd23f, #ff9d2e);
  border-color: #fff2b0 #7a4c00 #7a4c00 #fff2b0;
  color: #241400;
  animation: pulse 2.2s ease-in-out infinite;
}
#btn-random:active { animation: none; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,210,63,.55); }
  50% { box-shadow: 0 0 18px 4px rgba(255,210,63,.28); }
}
.helpbtn { border-radius: 50%; width: 34px; height: 34px; font-size: 16px; }
.chkrow { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 6px 0; }
.chkrow label { display: inline-flex; gap: 5px; align-items: center; cursor: pointer; }
/* Order-Chips: als Gruppe umbrechen und mit Abstand statt aneinandergedrückt */
#order-chips { display: inline-flex; flex-wrap: wrap; gap: 4px; }

/* ---------------------------------------------------------------- Layout */
main {
  flex: 1;
  display: flex;
  gap: 12px;
  padding: 12px;
  align-items: stretch;
  min-height: 0;
}
#grid-area { flex: 1; min-width: 0; min-height: 0; display: flex; }
#side { width: 300px; display: flex; flex-direction: column; gap: 10px; }

.panel {
  background: var(--panel);
  border: 2px solid;
  border-color: var(--bevel-hi) var(--bevel-lo) var(--bevel-lo) var(--bevel-hi);
  padding: 8px 10px;
}
.panel h2 {
  margin: 0 0 6px;
  font-size: 12px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--accent2);
  display: flex;
  align-items: center;
  gap: 8px;
}
.panel .small { font-size: 11px; color: var(--ink-dim); margin: 4px 0; }
.panel .tiny { font-size: 10px; color: var(--ink-dim); line-height: 1.5; margin: 4px 0 0; }
#oct-ctl { margin-left: auto; display: inline-flex; gap: 4px; align-items: center; }

.led {
  width: 11px; height: 11px; border-radius: 50%;
  background: #30546e; border: 1px solid var(--bevel-lo);
  display: inline-block;
}
.led.ok { background: #37e26d; box-shadow: 0 0 8px #37e26d; }
.led.warn { background: #ffb347; box-shadow: 0 0 8px #ffb34777; }

/* ---------------------------------------------------------------- Raster */
#grid-scroll {
  flex: 1;
  overflow: auto;
  background: #031c31;
  border: 2px solid;
  border-color: var(--bevel-lo) var(--bevel-hi) var(--bevel-hi) var(--bevel-lo);
  scrollbar-color: #2c648f #04182b;
  overscroll-behavior: contain;
}
#grid { display: flex; width: 100%; min-width: 100%; }

.gutter { position: sticky; left: 0; z-index: 3; background: #04223c; flex: 0 0 auto; }
.gutter .corner {
  position: sticky; top: 0; z-index: 4;
  height: 84px; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, #0a4a7d, #062f52);
  border-right: 2px solid var(--bevel-lo); border-bottom: 2px solid var(--bevel-lo);
  color: var(--accent2); font-size: 10px; width: 4.2em; min-width: 4.2em;
}
.rownum {
  height: var(--row-h); line-height: var(--row-h);
  text-align: right; padding: 0 6px 0 4px;
  color: var(--ink-dim); font-size: 10px;
  border-right: 2px solid var(--bevel-lo);
  border-bottom: 1px solid #06293f;
  background: #04223c;
  min-width: 4.2em;
}
.rownum.beat2 { color: var(--ink); }
.rownum.beat4 { color: var(--accent2); }
.rownum.curbg { background: #0d3f66; }
.rownum.playhead { background: var(--accent); color: #241400; font-weight: 700; }

.tcol { display: flex; flex-direction: column; border-right: 1px solid #06293f; flex: 1 1 var(--cell-w); min-width: var(--cell-w); }
.thead {
  position: sticky; top: 0; z-index: 2;
  width: 100%; min-width: 0;
  height: 84px;
  background: linear-gradient(180deg, #0a4a7d, #063a63);
  border-bottom: 2px solid var(--bevel-lo);
  border-top: 3px solid var(--trk, #fff);
  display: flex; flex-direction: column; gap: 1px;
  padding: 2px 3px;
  overflow: hidden;
}
.thead .tname {
  font-size: 11px; font-weight: 700; letter-spacing: .5px;
  color: var(--trk, #fff); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thead .tname.active { text-decoration: underline; text-decoration-color: var(--accent); }
.thead select { width: 100%; padding: 0 1px; font-size: 10px; }
.thead .tbtns { display: flex; gap: 2px; }
.thead .tbtns button { padding: 0 3px; font-size: 9.5px; min-width: 0; }
.thead input[type="range"] { width: 100%; height: 10px; }

.cell {
  height: var(--row-h); line-height: var(--row-h);
  width: 100%; min-width: 0;
  padding: 0 4px;
  font-size: 12px;
  white-space: nowrap;
  border-bottom: 1px solid #06293f;
  cursor: crosshair;
  user-select: none;
  display: flex; gap: 4px;
}
.cell:nth-child(odd) { background: rgba(255,255,255,.02); }
.cell.b2 { border-bottom-color: #0c3d5c; }
.cell.b4 { border-bottom-color: #155b85; }
.cell.bar { box-shadow: inset 0 2px 0 #1d7cb0; }
.cell .cn { color: var(--trk, var(--ink)); font-weight: 700; }
.cell .ci { color: var(--ink-dim); font-size: 10px; }
.cell .cn.off { color: #ff8a6a; font-weight: 400; }
.cell.rest .cn { color: #2f5b7a; }
.cell.playhead { background: rgba(255,210,63,.16); }
.cell.playhead.cursor { background: rgba(255,210,63,.3); }
.cell.cursor {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: rgba(255,179,71,.14);
}

/* ---------------------------------------------------------------- Klaviatur */
#piano-wrap { overflow-x: auto; padding: 4px 0; scrollbar-color: #2c648f #04182b; }
#piano { display: flex; position: relative; height: 96px; width: max-content; }
.wkey {
  width: 26px; height: 96px; margin-right: 1px;
  background: linear-gradient(180deg, #e9f4ff 0%, #c4d9ea 85%, #a7c2d6 100%);
  border: 1px solid #05304f; border-radius: 0 0 3px 3px;
  position: relative; cursor: pointer;
  display: flex; align-items: flex-end; justify-content: center;
  font-size: 9px; color: #50789b; padding-bottom: 2px;
}
.wkey:active, .wkey.hit { background: var(--accent); }
.bkey {
  position: absolute; top: 0; height: 60px; width: 17px;
  background: linear-gradient(180deg, #143c5c, #051827 85%);
  border: 1px solid #020f1a; border-radius: 0 0 3px 3px;
  cursor: pointer; z-index: 2;
}
.bkey:active, .bkey.hit { background: #b8860b; }

#drum-pads { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; margin-top: 4px; }
.dpad {
  padding: 9px 2px; font-size: 10px; text-align: center;
  background: linear-gradient(180deg, #2e6da3, #17456e);
  border-color: #6fb0e0 #052a49 #052a49 #6fb0e0;
  color: #eaf6ff;
}
.dpad .k { color: var(--accent); font-weight: 700; display: block; font-size: 12px; }
.dpad:active { transform: translateY(1px); }

/* ---------------------------------------------------------------- Status */
#statusbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; row-gap: 2px;
  padding: 4px 12px;
  background: #032038;
  border-top: 2px solid var(--bevel-hi);
  font-size: 11px; color: var(--ink-dim);
  min-height: 26px;
}
#statusbar .spacer { flex: 1 1 12px; }
#status { flex: 1 1 220px; min-width: 0; }
#statusbar > span:not(.spacer):not(#status) { white-space: nowrap; }
#status b, #cur-note { color: var(--accent); }
#cur-note { min-width: 6ch; }
#st-seed { color: var(--accent2); }

/* ---------------------------------------------------------------- Dialog */
dialog#help {
  color: var(--ink); background: var(--panel);
  border: 3px solid var(--bevel-hi); max-width: min(860px, 92vw);
  padding: 18px 22px;
}
dialog#help::backdrop { background: rgba(0, 8, 16, .72); }
dialog#help h2 { color: var(--accent); margin-top: 0; }
dialog#help .cols { display: flex; gap: 26px; flex-wrap: wrap; }
dialog#help h3 { color: var(--accent2); margin: 8px 0 4px; font-size: 12px; text-transform: uppercase; }
dialog#help table { border-collapse: collapse; font-size: 12px; }
dialog#help td { padding: 2px 10px 2px 0; vertical-align: top; }
dialog#help td:first-child { color: var(--accent); white-space: nowrap; }

/* ---------------------------------------------------------------- Responsive */
@media (max-width: 1000px) {
  /* Klappstapel: Seite wächst mit und scrollt natürlich. Sonst quetscht das
     starre height:100% des Desktop-Layouts Raster und Panels in den Viewport,
     das Raster läuft aus seiner Box und #side übermalt es (Überlappung). */
  html, body { height: auto; }
  main { flex-direction: column; }
  #side { width: 100%; flex-direction: row; flex-wrap: wrap; }
  #side .panel { flex: 1 1 260px; }
  #grid-scroll { height: 46vh; min-height: 220px; }
  #top { padding: 8px; }
  .pos { display: none; }
  /* Statusleiste bleibt beim Scrollen unten sichtbar */
  #statusbar { position: sticky; bottom: 0; z-index: 6; }
}
@media (max-width: 760px) {
  /* Panels untereinander statt zwei schmaler Spalten */
  #side .panel { flex: 1 1 100%; }
}
@media (max-width: 600px) {
  :root { --row-h: 26px; --cell-w: 10.5ch; }   /* größere Touch-Ziele */
  .brand h1 { font-size: 20px; }
  .brand .sub { display: none; }
  #btn-random { font-size: 13px; padding: 9px 10px; }
  .panel-block { gap: 5px; padding: 5px 7px; }
  #piano .wkey { width: 34px; }
  #piano .bkey { width: 22px; }
  #status { flex-basis: 100%; }                /* Status erst die ganze Breite … */
  #statusbar { font-size: 10px; gap: 3px 12px; }
}

/* ---------------------------------------------------------------- Große Screens
   Viel Platz sinnvoll nutzen: größere Zellen, breiteres Seitenpanel. Die
   Rasterspalten füllen dank .tcol{flex-grow} die Restbreite ohnehin aus. */
@media (min-width: 1500px) {
  :root { --row-h: 24px; --cell-w: 11ch; }
  body { font-size: 14px; }
  #side { width: 340px; }
}
@media (min-width: 1900px) {
  :root { --row-h: 26px; --cell-w: 12.5ch; }
  #side { width: 380px; }
  .brand h1 { font-size: 30px; }
}
