/* GlowGrain: a sunlit instrument. Warm dusk base, amber light, cream keys. */
:root {
  --bg: #140a08; --panel: rgba(255, 214, 170, .06); --panel2: rgba(255, 214, 170, .10); --line: rgba(255, 196, 140, .16);
  --fg: #fbeedd; --dim: #bfa38a; --dimmer: #8a6f5c;
  --sun: #ffb454; --sun2: #ff8a5c; --rose: #e8685a; --cream: #fff3e0; --glow: rgba(255, 170, 80, .55);
  --serif: ui-serif, "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
* { box-sizing: border-box; }
html { background: var(--bg); }
html, body { margin: 0; color: var(--fg); font-family: var(--sans); -webkit-text-size-adjust: 100%; }
body { min-height: 100vh; min-height: 100dvh; overflow-x: hidden; -webkit-tap-highlight-color: transparent; }
#sky { position: fixed; inset: 0; width: 100%; height: 100%; z-index: -1; display: block; }
[hidden] { display: none !important; }

#app {
  max-width: 1000px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; gap: 14px;
  padding: 14px max(14px, env(safe-area-inset-right)) calc(18px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}

/* header */
.top { text-align: center; position: relative; padding-top: 8px; }
.labs-link { position: absolute; left: 0; top: 4px; color: var(--dim); font-size: 12px; text-decoration: none; padding: 6px 4px; }
.labs-link:hover, .labs-link:focus-visible { color: var(--sun); }
.logo { margin: 0; font-family: var(--serif); font-weight: 500; font-style: italic; font-size: clamp(30px, 6.5vw, 46px); letter-spacing: .5px;
  text-shadow: 0 0 30px var(--glow); display: inline-flex; align-items: center; gap: 10px; }
.sun { width: .8em; height: .8em; fill: var(--sun); stroke: var(--sun); stroke-width: 1.6; filter: drop-shadow(0 0 8px var(--glow)); }
.tag { margin: 2px 0 8px; color: var(--dim); font-size: 13px; letter-spacing: .6px; }
.chips { position: absolute; right: 0; top: 4px; display: flex; gap: 6px; }
.chip { font: inherit; font-size: 12px; color: var(--dim); background: var(--panel); border: 1px solid var(--line); border-radius: 99px; padding: 6px 12px; cursor: pointer; }
.chip:hover, .chip:focus-visible { color: var(--sun); border-color: var(--sun); outline: none; }
.chip.on { color: #1c0e08; background: var(--sun); border-color: var(--sun); }
.chip.ghost { cursor: default; color: var(--sun2); border-color: var(--sun2); animation: pulse 1.4s ease-in-out infinite; }

/* bloom */
.bloom { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px 12px; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.bloom-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.bloom-head label { font-family: var(--serif); font-style: italic; font-size: 20px; color: var(--cream); }
.hint { color: var(--dim); font-size: 12.5px; line-height: 1.5; }
.chord { margin: 4px 0 0; min-height: 1.4em; font-family: var(--serif); font-style: italic; color: var(--sun); text-align: center; font-size: 15px; letter-spacing: .5px; }

input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 34px; background: transparent; margin: 0; touch-action: pan-y; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 6px; border-radius: 6px; background: linear-gradient(90deg, rgba(255, 180, 84, .15), rgba(255, 180, 84, .55)); }
input[type=range]::-moz-range-track { height: 6px; border-radius: 6px; background: linear-gradient(90deg, rgba(255, 180, 84, .15), rgba(255, 180, 84, .55)); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; margin-top: -10px; border-radius: 50%; border: 0;
  background: radial-gradient(circle at 40% 35%, #fff4d6, var(--sun) 55%, var(--sun2)); box-shadow: 0 0 14px var(--glow), 0 0 0 4px rgba(255, 180, 84, .16); }
input[type=range]::-moz-range-thumb { width: 26px; height: 26px; border-radius: 50%; border: 0;
  background: radial-gradient(circle at 40% 35%, #fff4d6, var(--sun) 55%, var(--sun2)); box-shadow: 0 0 14px var(--glow), 0 0 0 4px rgba(255, 180, 84, .16); }
input[type=range]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 18px var(--glow), 0 0 0 5px rgba(255, 244, 214, .5); }
#bloom { height: 44px; }
#bloom::-webkit-slider-runnable-track { height: 10px; border-radius: 10px; background: linear-gradient(90deg, rgba(255, 180, 84, .12), var(--sun2) 70%, #ffe2a8); }
#bloom::-moz-range-track { height: 10px; border-radius: 10px; background: linear-gradient(90deg, rgba(255, 180, 84, .12), var(--sun2) 70%, #ffe2a8); }
#bloom::-webkit-slider-thumb { width: 36px; height: 36px; margin-top: -13px; }
#bloom::-moz-range-thumb { width: 36px; height: 36px; }

.layers { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 4px 0 0; padding: 0; }
.layer { font: inherit; font-size: 13px; color: var(--dimmer); background: transparent; border: 1px solid var(--line); border-radius: 99px; padding: 7px 14px; min-height: 36px; cursor: pointer;
  transition: color .5s, background .5s, border-color .5s, box-shadow .5s; touch-action: manipulation; }
.layer.awake { color: var(--cream); border-color: rgba(255, 180, 84, .55); background: rgba(255, 180, 84, .12); box-shadow: 0 0 14px rgba(255, 170, 80, .22); }
.layer.pinned { border-style: solid; border-color: var(--sun); }
.layer.muted { text-decoration: line-through; opacity: .55; }
.layer:focus-visible { outline: 2px solid var(--sun); outline-offset: 2px; }

/* instruments */
.inst { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.inst button { font: inherit; font-size: 14px; color: var(--dim); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 9px 16px; min-height: 42px; cursor: pointer; touch-action: manipulation; transition: all .2s; }
.inst button[aria-checked=true] { color: #1c0e08; background: linear-gradient(180deg, #ffd08a, var(--sun)); border-color: var(--sun); box-shadow: 0 0 18px var(--glow); font-weight: 600; }
.inst button:focus-visible { outline: 2px solid var(--cream); outline-offset: 2px; }

/* keyboard */
.board { display: flex; flex-direction: column; gap: 8px; flex: 1 1 auto; min-height: 230px; }
.tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; }
.grp { display: inline-flex; align-items: center; gap: 6px; }
.range-label { min-width: 74px; text-align: center; color: var(--dim); font-size: 13px; font-variant-numeric: tabular-nums; }
.btn { font: inherit; font-size: 13px; color: var(--fg); background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px; min-height: 40px; cursor: pointer; touch-action: manipulation; transition: all .15s; }
.btn:hover:not(:disabled) { border-color: var(--sun); color: var(--sun); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: default; }
.btn:focus-visible { outline: 2px solid var(--sun); outline-offset: 2px; }
.btn.sm { padding: 6px 12px; min-height: 36px; }
.btn.toggle[aria-pressed=true] { color: #1c0e08; background: var(--sun); border-color: var(--sun); }
.sel { display: inline-flex; align-items: center; gap: 6px; color: var(--dim); font-size: 13px; }
select { font: inherit; font-size: 13px; color: var(--fg); background: #25130d; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-height: 36px; }
select:focus-visible { outline: 2px solid var(--sun); }

.keys { position: relative; flex: 1 1 auto; min-height: 190px; height: clamp(190px, 34vh, 300px); border-radius: 14px; padding: 8px 8px 10px;
  background: linear-gradient(180deg, #2a140d, #1b0d08); border: 1px solid var(--line); box-shadow: 0 10px 40px rgba(0, 0, 0, .5), inset 0 1px 0 rgba(255, 220, 170, .08);
  touch-action: none; user-select: none; -webkit-user-select: none; }
.keys-inner { position: relative; width: 100%; height: 100%; }
.key { position: absolute; top: 0; touch-action: none; -webkit-user-select: none; user-select: none; transition: box-shadow .12s, filter .12s, transform .06s; }
.key.white { height: 100%; background: linear-gradient(180deg, #fff6e6 0%, #f6dcb4 78%, #e9c48f 100%); border: 1px solid #b98a58; border-radius: 0 0 8px 8px;
  box-shadow: inset 0 -6px 0 rgba(120, 70, 30, .18); z-index: 1; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 8px; }
.key.black { height: 62%; background: linear-gradient(180deg, #3b2218, #1b0e09 85%, #120805); border: 1px solid #0b0504; border-radius: 0 0 6px 6px; z-index: 2;
  box-shadow: 0 3px 6px rgba(0, 0, 0, .5), inset 0 -4px 0 rgba(255, 190, 120, .08); }
.key .lab { font-size: 11px; color: #8a5a35; pointer-events: none; }
.key.root .lab { color: #c25a28; font-weight: 700; }
.key.root::after { content: ""; position: absolute; bottom: 24px; left: 50%; width: 7px; height: 7px; margin-left: -3.5px; border-radius: 50%; background: var(--sun2); opacity: .9; pointer-events: none; }
.key.off { filter: brightness(.55) saturate(.7); }
.key.down { transform: translateY(2px); }
.key.white.down, .key.white.ghost { background: linear-gradient(180deg, #ffd9a0 0%, #ffb454 70%, #f08a3c 100%); box-shadow: 0 0 26px var(--glow), inset 0 -4px 0 rgba(120, 50, 10, .25); }
.key.black.down, .key.black.ghost { background: linear-gradient(180deg, #ff9d4a, #c8561f 90%); box-shadow: 0 0 22px var(--glow); }
.key.ghost { transition: box-shadow 1.1s ease-out, background 1.1s ease-out; }

/* looper */
.looper { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 10px 12px; }
.btn.big { font-size: 15px; padding: 10px 18px; min-width: 150px; font-weight: 600; }
.loopbtn[data-state=countin], .loopbtn[data-state=recording] { color: #fff; background: var(--rose); border-color: var(--rose); animation: pulse 1s ease-in-out infinite; }
.loopbtn[data-state=playing] { color: #1c0e08; background: var(--sun); border-color: var(--sun); }
.loopbtn[data-state=odwait], .loopbtn[data-state=overdub] { color: #fff; background: #c4572f; border-color: #c4572f; animation: pulse 1s ease-in-out infinite; }
.loopprog { width: 90px; height: 6px; border-radius: 6px; background: rgba(255, 190, 120, .15); overflow: hidden; }
.loopprog i { display: block; height: 100%; width: 0; background: var(--sun); box-shadow: 0 0 10px var(--glow); }
.sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 4px; }
.btn.rec[data-on=true] { color: #fff; background: var(--rose); border-color: var(--rose); animation: pulse 1.2s ease-in-out infinite; }

/* tone drawer */
.tone { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 0 16px; }
.tone summary { cursor: pointer; padding: 12px 0; color: var(--dim); font-size: 14px; list-style: none; }
.tone summary::-webkit-details-marker { display: none; }
.tone summary::before { content: "▸ "; color: var(--sun); }
.tone[open] summary::before { content: "▾ "; }
.tone .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 6px 22px; padding-bottom: 14px; }
.tone label { display: flex; flex-direction: column; gap: 2px; color: var(--dim); font-size: 13px; }
.tone label.sel { flex-direction: row; justify-content: space-between; align-items: center; }
.tone output { color: var(--sun); margin-left: 6px; }

.foot { text-align: center; padding-top: 4px; }
.foot p { margin: 6px 0 0; }
kbd { font: inherit; font-size: 11px; padding: 1px 6px; border: 1px solid var(--line); border-radius: 5px; background: var(--panel2); color: var(--cream); }

/* start overlay */
.start { position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 24px; text-align: center;
  background: radial-gradient(ellipse at 50% 62%, rgba(255, 150, 70, .38), rgba(20, 10, 8, .92) 62%), var(--bg); transition: opacity .6s ease; }
.start.gone { opacity: 0; pointer-events: none; }
.startbtn { display: flex; flex-direction: column; align-items: center; gap: 6px; background: none; border: 0; color: var(--fg); cursor: pointer; font: inherit; padding: 12px; }
.startbtn:focus-visible { outline: 2px solid var(--sun); border-radius: 24px; }
.bigsun { width: min(46vw, 220px); height: auto; filter: drop-shadow(0 0 40px var(--glow)); animation: breathe 4.5s ease-in-out infinite; }
.startbtn .title { font-family: var(--serif); font-style: italic; font-size: clamp(34px, 9vw, 56px); text-shadow: 0 0 34px var(--glow); }
.startbtn .sub { color: var(--sun); letter-spacing: 3px; text-transform: uppercase; font-size: 12px; }
#startErr { color: var(--rose); min-height: 1.2em; max-width: 34em; }
.small { font-size: 12px; opacity: .8; margin: 0; }

@keyframes pulse { 50% { opacity: .62; } }
@keyframes breathe { 50% { transform: scale(1.06); filter: drop-shadow(0 0 60px var(--glow)); } }

/* guidance: beat dots, chord-tone glow, pads, coach line, how-to */
.beatrow { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 4px; min-height: 1.6em; }
.beatrow .chord { margin: 0; min-height: 0; }
.beats { display: flex; gap: 7px; align-items: center; }
.beats i { width: 10px; height: 10px; border-radius: 50%; background: rgba(255, 190, 120, .2); transition: background .1s, box-shadow .1s, transform .1s; }
.beats i.on { background: var(--sun); box-shadow: 0 0 12px var(--glow); transform: scale(1.15); }
.beats i:first-child.on { background: #fff1cf; box-shadow: 0 0 18px 3px var(--glow); transform: scale(1.4); }

.keys.guide .key.white.tone { background: linear-gradient(180deg, #ffe7bf 0%, #ffcf8a 78%, #f2a95c 100%); box-shadow: 0 0 20px rgba(255, 170, 80, .65), inset 0 -6px 0 rgba(160, 80, 20, .25); animation: tonepulse 2.4s ease-in-out infinite; }
.keys.guide .key.black.tone { background: linear-gradient(180deg, #8a4a24, #4a2210 90%); box-shadow: 0 0 16px rgba(255, 170, 80, .6); animation: tonepulse 2.4s ease-in-out infinite; }
.keys.guide .key.white:not(.tone) { filter: brightness(.62) saturate(.7); }
.keys.guide .key.black:not(.tone) { filter: brightness(.7); }
.keys.guide .key.white.down, .keys.guide .key.black.down { filter: none; animation: none; }
@keyframes tonepulse { 50% { filter: brightness(1.12); } }
.glowdot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: #ffcf8a; box-shadow: 0 0 10px var(--glow); vertical-align: -1px; }

.pads { display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(2, 1fr); gap: 10px; flex: 1 1 auto; min-height: 190px; height: clamp(190px, 34vh, 300px); touch-action: none; user-select: none; -webkit-user-select: none; }
.pad { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border-radius: 18px; border: 1px solid var(--line); cursor: pointer; touch-action: none;
  background: linear-gradient(160deg, rgba(255, 196, 140, .16), rgba(255, 150, 70, .06)); color: var(--cream); transition: box-shadow .1s, background .1s, transform .06s; }
.pad .n { font-family: var(--serif); font-style: italic; font-size: clamp(20px, 4.4vw, 30px); }
.pad .r { font-size: 11.5px; color: var(--dim); letter-spacing: .6px; text-transform: uppercase; }
.pad.root { border-color: rgba(255, 180, 84, .6); background: linear-gradient(160deg, rgba(255, 190, 110, .32), rgba(255, 140, 60, .12)); }
.pad.down { transform: scale(.97); background: linear-gradient(160deg, #ffd9a0, #ff9d4a); color: #1c0e08; box-shadow: 0 0 30px var(--glow); }
.pad.down .r { color: #5a2c10; }
.pad.ghost { box-shadow: 0 0 22px rgba(255, 170, 80, .5); }

.coach { margin: 0; min-height: 2.8em; text-align: center; color: var(--dim); font-size: 13px; line-height: 1.5; padding: 0 6px; }
.coach b, .coach em { color: var(--sun); font-style: normal; }

.howto { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 0 16px; }
.howto summary { cursor: pointer; padding: 12px 0; color: var(--cream); font-size: 14px; list-style: none; font-weight: 600; }
.howto summary::-webkit-details-marker { display: none; }
.howto summary::before { content: "▸ "; color: var(--sun); }
.howto[open] summary::before { content: "▾ "; }
.howto ol { margin: 0 0 14px; padding-left: 20px; color: var(--dim); font-size: 13.5px; line-height: 1.6; }
.howto li { margin-bottom: 8px; }
.howto b { color: var(--cream); } .howto em { color: var(--sun); font-style: normal; }

/* Phones and short screens: the keys must be on screen the moment the instrument opens. */
@media (max-width: 640px), (max-height: 560px) {
  #app { gap: 8px; padding-top: 8px; }
  .top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0; text-align: left; }
  .labs-link { position: static; font-size: 11px; padding: 4px 0; order: 3; }
  .logo { font-size: 24px; order: 1; }
  .tag { display: none; }
  .chips { position: static; order: 2; margin-left: auto; }
  .chip { padding: 5px 10px; }
  .bloom { padding: 6px 12px 6px; border-radius: 14px; }
  .bloom-head { margin-bottom: 0; }
  .bloom-head label { font-size: 17px; }
  .hint { font-size: 12px; }
  #bloom { height: 38px; }
  .layers { gap: 6px; margin-top: 0; }
  .layer { font-size: 12px; padding: 4px 10px; min-height: 30px; }
  .chord { margin: 2px 0 0; min-height: 1.2em; font-size: 13px; }
  .inst { flex-wrap: nowrap; gap: 5px; }
  .inst button { flex: 1 1 auto; font-size: 12.5px; padding: 7px 6px; min-height: 38px; border-radius: 10px; }
  .tools { gap: 6px; }
  .tools .sel span { display: none; }
  .range-label { min-width: 62px; font-size: 12px; }
  .board { min-height: 0; gap: 6px; }
  .keys, .pads { height: clamp(150px, 30vh, 210px); min-height: 150px; }
  .pads { gap: 7px; }
  .pad .r { font-size: 10px; }
  .coach { font-size: 12px; min-height: 2.6em; }
  .key .lab { font-size: 10px; }
  .btn.big { min-width: 0; flex: 1 1 140px; }
  .sep { display: none; }
}
/* Landscape phones: instrument controls on the left, keyboard on the right. */
@media (max-height: 460px) and (orientation: landscape) {
  #app { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.55fr); align-items: start; column-gap: 12px; }
  .top, .bloom, .inst { grid-column: 1; }
  .board { grid-column: 2; grid-row: 1 / span 4; height: 100%; }
  .looper, .tone, .foot { grid-column: 1 / -1; }
  .keys { height: clamp(130px, 62vh, 220px); }
  .hint.small { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: .01ms !important; }
}
