:root {
    --bg-0: #1a1a2e;
    --bg-1: #16213e;
    --panel: rgba(0, 0, 0, 0.32);
    --line: rgba(255, 255, 255, 0.14);
    --text: #fff;
    --muted: #c5c9d6;
    --cyan: #00e8e8;
    --melody: #3498db;
    --melody-deep: #217dbb;
    --warm: #e67e22;
    --warm-deep: #d35400;
    --play: #2ecc71;
    --play-deep: #27ae60;
    --stop: #e74c3c;
    --stop-deep: #c0392b;
    --gap: 12px;
    --pad: 20px;
    --page-max: 1600px;
    --tap: 56px;
    --radius: 14px;
    --c: #ff3333;
    --d: #ff8800;
    --e: #ffcc00;
    --f: #66cc33;
    --g: #009933;
    --a: #9933cc;
    --b: #cc3399;
    --klap: #e91e63;
    --stamp: #4caf50;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
}

body {
    font-family: "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
    background: linear-gradient(135deg, var(--bg-0) 0%, var(--bg-1) 100%);
    color: var(--text);
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto auto auto;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
}

button, .whacker, .tool, label {
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

/* HEADER */
header {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: 8px var(--pad) 4px;
    flex-shrink: 0;
}

header h1 {
    margin: 0;
    font-size: clamp(1.15rem, 2.2vw, 1.7rem);
    font-weight: 800;
    letter-spacing: 0.04em;
    color: #fff;
    text-align: center;
    line-height: 1.2;
}

#fs-btn {
    position: absolute;
    top: 8px;
    right: var(--pad);
    width: var(--tap);
    height: var(--tap);
    border: 2px solid var(--line);
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    line-height: 1;
    padding: 0;
    box-shadow: none;
}

#fs-btn:hover { background: rgba(255, 255, 255, 0.22); color: #fff; }

#aftel {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    font-size: min(58vh, 42vw);
    font-weight: 900;
    color: #fff;
    line-height: 1;
    letter-spacing: 0.02em;
    text-shadow: 0 0 28px rgba(0, 232, 232, 0.85), 0 12px 40px rgba(0, 0, 0, 0.75);
    background: rgba(12, 14, 40, 0.32);
}

/* BOARD: lamps + beat boxes share the same 8 columns (1 or 2 rows) */
.board {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 4px var(--pad) 8px;
    min-height: 0;
    width: 100%;
    max-width: var(--page-max);
    margin: 0 auto;
    position: relative;
}

.seq-row {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 8px;
    min-height: 0;
    flex: 1 1 0;
}

.indicators,
.stage {
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: var(--gap);
    width: 100%;
}

.lamp {
    height: 16px;
    background: #4a4a5c;
    border-radius: 8px;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.5);
    cursor: pointer;
}

.lamp.on {
    background: var(--cyan);
    box-shadow: 0 0 14px var(--cyan);
}

.hidden { display: none !important; }

.stage {
    position: relative;
    min-height: 0;
    height: 100%;
    align-items: stretch;
}

.beat-box {
    min-width: 0;
    min-height: 0;
    height: 100%;
    max-height: none;
    background: #2a2a3a;
    border-radius: var(--radius);
    border: 3px solid #444;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 28px 6px 12px;
    font-weight: 800;
    opacity: 0.45;
    position: relative;
    box-shadow: inset 0 0 18px rgba(0, 0, 0, 0.4);
    transition: box-shadow 0.12s, filter 0.12s;
    cursor: pointer;
}

.number {
    position: absolute;
    top: 6px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: clamp(0.85rem, 1.6vh, 1.15rem);
    color: rgba(255, 255, 255, 0.8);
    font-weight: 700;
    line-height: 1;
}

.beat-icon {
    width: min(46%, 88px);
    aspect-ratio: 1;
    height: auto;
    margin: 0;
    flex: 0 0 auto;
    fill: currentColor;
    opacity: 0.95;
}

.beat-icon svg {
    width: 100%;
    height: 100%;
    display: block;
}

.beat-text {
    z-index: 2;
    text-align: center;
    font-size: clamp(1.05rem, 3.2vh, 2rem);
    line-height: 1.1;
    width: 100%;
}

.rust .beat-icon { color: #888; }
.geel .beat-icon,
.e .beat-icon,
.f .beat-icon { color: #111; }

.active-play {
    opacity: 1 !important;
    z-index: 10;
    filter: brightness(1.08);
    box-shadow: 0 0 28px rgba(255, 255, 255, 0.35);
}

.beat-box.c { background: var(--c); color: #fff; border-color: rgba(255,255,255,0.45); opacity: 1; box-shadow: 0 4px 10px rgba(0,0,0,0.3); }
.beat-box.d { background: var(--d); color: #fff; border-color: rgba(255,255,255,0.45); opacity: 1; box-shadow: 0 4px 10px rgba(0,0,0,0.3); }
.beat-box.e { background: var(--e); color: #111; border-color: rgba(255,255,255,0.45); opacity: 1; box-shadow: 0 4px 10px rgba(0,0,0,0.3); }
.beat-box.f { background: var(--f); color: #111; border-color: rgba(255,255,255,0.45); opacity: 1; box-shadow: 0 4px 10px rgba(0,0,0,0.3); }
.beat-box.g { background: var(--g); color: #fff; border-color: rgba(255,255,255,0.45); opacity: 1; box-shadow: 0 4px 10px rgba(0,0,0,0.3); }
.beat-box.a { background: var(--a); color: #fff; border-color: rgba(255,255,255,0.45); opacity: 1; box-shadow: 0 4px 10px rgba(0,0,0,0.3); }
.beat-box.b { background: var(--b); color: #fff; border-color: rgba(255,255,255,0.45); opacity: 1; box-shadow: 0 4px 10px rgba(0,0,0,0.3); }
.beat-box.c-high { background: var(--c); color: #fff; border: 5px solid #fff; opacity: 1; box-shadow: 0 4px 10px rgba(0,0,0,0.3); }

.klap { background: var(--klap); color: #fff; border-color: rgba(255,255,255,0.5); opacity: 1; }
.stamp { background: var(--stamp); color: #fff; border-color: rgba(255,255,255,0.5); opacity: 1; }
.alles { background: #fff; color: #111; border: 5px solid gold; opacity: 1; }

.rood_dbl {
    background: linear-gradient(90deg, var(--c) 45%, #222 45%, #222 55%, var(--c) 55%);
    color: #fff; border: 2px solid var(--c);
}
.geel_dbl {
    background: linear-gradient(90deg, var(--e) 45%, #222 45%, #222 55%, var(--e) 55%);
    color: #fff; border: 2px solid var(--e);
}
.rood_geel {
    background: linear-gradient(135deg, var(--c) 50%, var(--e) 50%);
    color: #fff; border-color: #fff;
}
.rust { background: transparent; border: 3px dashed #666; color: #9aa; opacity: 0.7; }

#play-cursor {
    position: absolute;
    top: 0;
    width: 8px;
    height: 40px;
    background: var(--cyan);
    box-shadow: 0 0 18px var(--cyan);
    z-index: 50;
    display: none;
    border-radius: 4px;
    pointer-events: none;
}

.board.stappen-16 {
    gap: 8px;
}

.board.stappen-16 .seq-row {
    gap: 4px;
}

.board.stappen-16 .lamp {
    height: 10px;
}

.board.stappen-16 .beat-box {
    min-height: 0;
    padding: 18px 4px 6px;
    gap: 2px;
}

.board.stappen-16 .beat-text {
    font-size: clamp(0.85rem, 2.2vh, 1.4rem);
}

.board.stappen-16 .beat-icon {
    width: min(38%, 56px);
}

.board.stappen-16 .number {
    top: 3px;
    font-size: clamp(0.7rem, 1.3vh, 0.95rem);
}

/* BUILDER */
#builder-panel {
    background: var(--panel);
    padding: 10px var(--pad) 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    border-top: 1px solid var(--line);
}

#builder-panel h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 800;
    color: #fff;
    letter-spacing: 0.03em;
}

.builder-tools {
    display: grid;
    grid-template-columns: repeat(11, minmax(48px, 56px));
    gap: 8px;
    justify-content: center;
    width: 100%;
}

.tool {
    width: 100%;
    height: var(--tap);
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 800;
    font-size: 1rem;
    cursor: grab;
    box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
    color: #fff;
}

.tool:active { cursor: grabbing; }
.tool.c { background: var(--c); }
.tool.d { background: var(--d); }
.tool.e { background: var(--e); color: #111; }
.tool.f { background: var(--f); color: #111; }
.tool.g { background: var(--g); }
.tool.a { background: var(--a); }
.tool.b { background: var(--b); }
.tool.c-high { background: var(--c); border: 3px solid #fff; }
.tool.klap { background: var(--klap); }
.tool.stamp { background: var(--stamp); }
.tool.rust { border: 3px dashed #888; color: #ccc; background: transparent; }

.beat-box.drag-over {
    border-color: #fff;
    box-shadow: 0 0 20px #fff;
}

/* TUBES: only take space when Speel zelf is on */
#interactive-boomwhackers {
    background: #1f1f2e;
    border-top: 1px solid var(--line);
    flex-shrink: 0;
}

#interactive-boomwhackers.closed {
    display: none;
}

.tubes-toggle {
    min-width: 148px;
    min-height: var(--tap);
    padding: 8px 16px;
    font-size: 1.05rem;
    background: #2a4a62;
    color: #fff;
}

.tubes-toggle:hover { background: #35607e; color: #fff; }

.tubes-toggle.active-zelf {
    background: var(--cyan);
    color: #102028;
    box-shadow: 0 4px 0 #00b8b8;
}

.boomwhacker-tubes {
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    justify-items: center;
    align-items: end;
    gap: var(--gap);
    width: 100%;
    max-width: var(--page-max);
    margin: 0 auto;
    padding: 8px var(--pad) 14px;
    border-bottom: 6px solid rgba(255, 255, 255, 0.12);
}

.whacker {
    width: 100%;
    min-width: 0;
    max-width: 120px;
    border-radius: 12px 12px 8px 8px;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 10px;
    font-weight: 800;
    font-size: 1.25rem;
    color: #111;
    cursor: pointer;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
    border: 2px solid rgba(0, 0, 0, 0.25);
    transition: filter 0.1s, transform 0.1s;
}

.whacker:hover { filter: brightness(1.12); }
.whacker:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,0.3); }

.whacker.c { background: var(--c); height: 168px; color: #fff; }
.whacker.d { background: var(--d); height: 156px; color: #fff; }
.whacker.e { background: var(--e); height: 144px; }
.whacker.f { background: var(--f); height: 132px; }
.whacker.g { background: var(--g); height: 120px; color: #fff; }
.whacker.a { background: var(--a); height: 108px; color: #fff; }
.whacker.b { background: var(--b); height: 96px; color: #fff; }
.whacker.c-high { background: var(--c); height: 84px; color: #fff; border: 3px solid #fff; }

/* CONTROLS */
.controls {
    background: var(--panel);
    border-top: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px var(--pad) 12px;
    width: 100%;
    max-width: var(--page-max);
    margin: 0 auto;
    min-height: 0;
    flex-shrink: 0;
}

.level-block {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: rgba(255, 255, 255, 0.05);
    padding: 4px;
    border-radius: 12px;
}

.level-block.collapsed {
    padding: 2px 4px;
}

.level-block.collapsed .level-grid {
    display: none;
}

.level-toggle {
    width: 100%;
    min-height: 44px;
    margin: 0;
    padding: 8px 12px;
    font-size: 1rem;
    font-weight: 800;
    letter-spacing: 0.03em;
    background: transparent;
    box-shadow: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.level-toggle::after {
    content: "▶";
    font-size: 0.75rem;
}

.level-block:not(.collapsed) .level-toggle::after {
    content: "▼";
}

.level-toggle.melody { color: #7ec8f5; }
.level-toggle.warm { color: #ffb066; }
.level-toggle.lang { color: #7eedc7; }
.level-toggle:hover { background: rgba(255, 255, 255, 0.08); color: inherit; }

.level-label {
    display: block;
    text-align: center;
    font-size: 0.95rem;
    font-weight: 800;
    margin: 0;
    letter-spacing: 0.03em;
}

.level-label.melody { color: #7ec8f5; }
.level-label.warm { color: #ffb066; }
.level-label.lang { color: #7eedc7; }

.level-grid {
    display: grid;
    grid-template-columns: repeat(10, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
}

button {
    padding: 8px 10px;
    min-height: var(--tap);
    font-size: 0.95rem;
    font-weight: 800;
    cursor: pointer;
    border: none;
    border-radius: 12px;
    background: #3e3e50;
    color: #eee;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.25);
    line-height: 1.15;
}

button:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,0.2); }
button:hover { background: #4e4e60; color: #fff; }

.level-grid.melody button { background: #2c3e50; }
.level-grid.melody button.active-btn {
    background: var(--melody);
    color: #fff;
    box-shadow: 0 4px 0 var(--melody-deep);
}
.level-grid.warm button { background: #503e2c; }
.level-grid.warm button.active-btn {
    background: var(--warm);
    color: #fff;
    box-shadow: 0 4px 0 var(--warm-deep);
}
.level-grid.lang {
    grid-template-columns: repeat(8, minmax(0, 1fr));
}
.level-grid.lang button { background: #1e4a44; }
.level-grid.lang button.active-btn {
    background: #1abc9c;
    color: #fff;
    box-shadow: 0 4px 0 #148f77;
}
#btn-21,
#btn-30 {
    background: #3e3e50;
    border: 2px solid #ccc;
    min-width: 148px;
    color: #fff;
}
#btn-21.active-btn,
#btn-30.active-btn {
    background: #7f8c8d;
    color: #fff;
    box-shadow: 0 4px 0 #5d6d6e;
}

.big-play {
    background: var(--play);
    color: #fff;
    font-size: 1.45rem;
    min-width: 180px;
    min-height: 60px;
    padding: 12px 36px;
    border-radius: 40px;
    box-shadow: 0 6px 0 var(--play-deep);
    letter-spacing: 0.06em;
}
.big-play:hover { background: #3ad87c; color: #fff; }
.big-play:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--play-deep); }
.big-play.stop { background: var(--stop); box-shadow: 0 6px 0 var(--stop-deep); }
.big-play.stop:hover { background: #ef6456; }
.big-play.stop:active { box-shadow: 0 2px 0 var(--stop-deep); }

.settings {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 12px 18px;
    color: #fff;
}

.toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: var(--tap);
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.08);
    border: 2px solid var(--line);
    border-radius: 14px;
    font-size: 1.05rem;
    font-weight: 800;
    cursor: pointer;
}

.toggle input {
    width: 22px;
    height: 22px;
    margin: 0;
    accent-color: var(--play);
    cursor: pointer;
}

.tempo {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: var(--tap);
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.08);
    border: 2px solid var(--line);
    border-radius: 14px;
    font-size: 1.05rem;
    font-weight: 800;
}

.tempo span { white-space: nowrap; }

.bpm-block {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 10px;
    min-height: var(--tap);
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.08);
    border: 2px solid var(--line);
    border-radius: 14px;
}

.bpm-label {
    font-size: 1.05rem;
    font-weight: 800;
    white-space: nowrap;
}

.bpm-grid {
    display: grid;
    grid-template-columns: repeat(8, minmax(52px, 60px));
    gap: 6px;
}

.bpm-btn {
    min-width: 52px;
    min-height: 52px;
    padding: 8px 4px;
    font-size: 1.2rem;
    background: #2c3e50;
    color: #eee;
}

.bpm-btn.active-bpm {
    background: var(--melody);
    color: #fff;
    box-shadow: 0 4px 0 var(--melody-deep);
}

input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    width: 150px;
    height: 14px;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 6px;
    outline: none;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #fff;
    cursor: pointer;
    box-shadow: 0 0 8px rgba(0, 0, 0, 0.4);
}

.dragging-clone {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    opacity: 0.9;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.5);
    transform: scale(1.15);
}

/* Digibord ~1920×1080 and tall classroom screens */
@media (min-width: 1400px) and (min-height: 900px) {
    .whacker.c { height: 176px; }
    .whacker.d { height: 164px; }
    .whacker.e { height: 152px; }
    .whacker.f { height: 140px; }
    .whacker.g { height: 128px; }
    .whacker.a { height: 116px; }
    .whacker.b { height: 104px; }
    .whacker.c-high { height: 92px; }
}

/* iPad landscape / smaller boards: keep 5+5 so buttons stay even */
@media (max-width: 1199px) {
    .level-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
    .level-grid.lang { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .builder-tools { grid-template-columns: repeat(11, minmax(44px, 52px)); }
    .whacker { max-width: 56px; }
}

/* iPad portrait */
@media (max-width: 834px) {
    :root { --pad: 12px; --gap: 8px; --tap: 52px; }
    .level-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
    .level-grid.lang { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    button { font-size: 0.82rem; min-height: 52px; padding: 6px 4px; }
    .builder-tools { grid-template-columns: repeat(6, minmax(48px, 1fr)); max-width: 420px; }
    .whacker.c { height: 132px; }
    .whacker.d { height: 122px; }
    .whacker.e { height: 112px; }
    .whacker.f { height: 102px; }
    .whacker.g { height: 92px; }
    .whacker.a { height: 84px; }
    .whacker.b { height: 76px; }
    .whacker.c-high { height: 68px; }
    .tempo input { width: 120px; }
    .bpm-grid { grid-template-columns: repeat(4, minmax(52px, 1fr)); }
    .bpm-btn { min-height: 52px; font-size: 1.1rem; }
}

@media (max-width: 600px) {
    .level-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .indicators, .stage { gap: 6px; }
    .beat-box { padding: 22px 2px 8px; min-height: 0; }
    .beat-text { font-size: 1rem; }
    .settings { gap: 8px; }
    .big-play { width: 100%; }
    .bpm-grid { grid-template-columns: repeat(4, minmax(52px, 1fr)); }
    .bpm-btn { min-height: 52px; font-size: 1.1rem; }
}

@media (max-height: 800px) {
    .controls { padding: 8px var(--pad) 10px; gap: 6px; }
    .level-block { padding: 6px; gap: 6px; }
    button { min-height: 48px; }
    .big-play { min-height: 52px; font-size: 1.25rem; }
    .toggle, .tempo { min-height: 48px; }
    .board.stappen-16 .beat-box { min-height: 0; padding: 12px 2px 4px; }
}

@media (max-height: 780px) {
    .whacker.c { height: 110px; }
    .whacker.d { height: 102px; }
    .whacker.e { height: 94px; }
    .whacker.f { height: 86px; }
    .whacker.g { height: 78px; }
    .whacker.a { height: 70px; }
    .whacker.b { height: 62px; }
    .whacker.c-high { height: 54px; }
    .beat-box { min-height: 0; }
}

