/* ==[ Document ] ========================================================================================= */
:root {
	--control-size: 30px;
	--control-corners: 6px;
	--font-size: 10.5pt;
}

html {
	color-scheme: dark;
	background-color: #000;
	color: #c5c8c6;
	font: var(--font-size) sans-serif;
	flex: 1; /* For flex layout in body */
}

body {
	margin: 0;
	display: flex; /* For centering content */
    flex-direction: column;
    min-height: 100vh;
}

a {
	text-decoration: none;
}

a:link, a:visited {
	color: #89c2ff;
}

a:hover, a:active {
	color: #ed88fb !important;
}

:focus-visible {
	outline: 2px solid #614fdb;
}

.hidden {
	display: none !important;
}

option {
    background: white;
    color: black;
    font-size: var(--font-size);
}

/* ==[ Containers ] ======================================================================================= */
.container-expanded {
	height: 100vh;
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 100;
	background: #000;
	max-width: none !important;
	padding: 2px;
	box-sizing: border-box;
}

.container-expanded + #container-scroll {
	display: none;
}

#container-fixed {
	display: flex;
	flex-direction: column;
	max-width: 1028px;
    width: 100%;
	flex: 1; /* Allow container to grow */
}

#container-scroll {
	max-width: 1028px;
	width: 100%;
	margin-top: 2px;
}

#content {
	display: flex;
	flex-flow: column;
	align-items: center;
	min-height: 100vh;
    box-sizing: border-box;
    padding: 2px;
	width: 100%; /* Ensure content takes full width */
}

footer {
	margin-left: 9px;
    padding: 10px 0;
}

/* ==[ Canvas ] =========================================================================================== */
#canvas-container {
	display: flex;
	flex-shrink: 0;
	position: relative;
	box-sizing: border-box;
	border: 2px solid #bac2cc;
	overflow: hidden;
	cursor: pointer;
    margin: 3px 2px 0 2px;
	flex: 1;
}

#canvas-main {
	width: 100%;
	height: auto;
    background-color: #1b1d20;
}

#canvas-timecursor {
	position: absolute;
	top: 0;
	bottom: 0;
	border-left: 2px solid blue;
	box-shadow: 0 0 8px #6ab2ff, 0 0 16px #fff;
	left: 0;
    display: none; /* managed by JS */
}

/* ==[ Canvas play/pause button ] ========================================================================= */
#canvas-container:hover > #canvas-play {
	display: block;
	background-image: linear-gradient(to bottom, #92aeec, #181f33) !important;
}

.canvas-initial #canvas-play {
	display: block !important;
	background-image: linear-gradient(to bottom, #67789d, #181f33);
}

.canvas-pause > #svg-canvas-play, .canvas-play > #svg-canvas-pause, .canvas-initial > #svg-canvas-pause {
	display: none;
}

.canvas-pause > #svg-canvas-pause, .canvas-play > #svg-canvas-play {
	display: block;
}

#canvas-play {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    padding: 1px 8px;
    border-radius: 16px;
    border: none;
    color: #c5c8c6;
    line-height: 0;
    transform: translate(-50%, -50%);
    cursor: pointer;
}

#canvas-play > svg {
	width: 46px;
	height: 46px;
	fill: currentColor;
}

.canvas-play-backward > #svg-canvas-play {
	transform: scaleX(-1);
}

/* ==[ Editor ] =========================================================================================== */
button[name="close"] {
	color: #abb2bf;
}

#container-fixed.container-expanded {
	flex: 1;
}

.container-expanded > #editor-container, .container-expanded > #canvas-container {
	flex: 1;
}

#editor-container {
	width: calc(100% - 4px);
	min-height: 128px;
	border: 2px solid #bac2cc;
	resize: vertical;
	overflow: hidden;
    margin: 0 2px;
	flex-basis: 256px;
	display: flex;
	flex-direction: row;
}

#editor-l-container, #editor-r-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
}

#editor-r-container {
    display: none;
    border-left: 1px solid #444;
}

.stereo-enabled #editor-l-container, .stereo-enabled #editor-r-container {
    width: 50%;
}
.stereo-enabled #editor-r-container {
    display: flex;
}

.editor-label {
    position: absolute;
    top: 4px;
    right: 8px;
    font-size: 10px;
    color: #7f848e;
    z-index: 10;
    pointer-events: none;
    font-family: sans-serif;
}

.cm-content {
	font-weight: bold;
	caret-color: #fff !important;
}

.cm-editor {
	height: 100%;
	background-color: #1b1d20;
}

.cm-scroller {
	line-height: var(--font-size) !important;
    font-family: monospace;
}

.cm-gutters {
    background-color: #1b1d20;
    border-right: 1px solid #444;
}

.cm-matchingBracket, .cm-selectionMatch {
	margin: -1px;
	border: 1px solid gray;
	border-radius: 3px;
    background-color: #3e4451;
}

.cm-searchMatch-selected {
	background-color: #d541ffba !important;
}

.tok-number { color: #ff8dfd; }
.tok-keyword { color: #96cbfe; }
.tok-operator { color: #96cbfe; }
.tok-propertyName { color: #ffd2a7; }
.tok-punctuation, .tok-variableName { color: #c5c8c6; }
.tok-string { color: #a8ff60; }
.tok-comment { color: #7f848e; }
.tok-invalid { color: #f92672; }
.tok-definition { color: #ffd2a7; }

/* Simple editor styles */
.simple-editor {
    width: 100%;
    height: 100%;
    padding: 8px;
    border: none;
    background-color: #1b1d20;
    color: #c5c8c6;
    font: var(--font-size)/1.4 monospace;
    font-weight: bold;
    outline: none;
    resize: none;
    box-sizing: border-box;
    caret-color: #fff;
	flex-grow: 1;
}

.simple-editor:focus {
    outline: none;
}

#error {
    min-height: 18px;
    color: #f92672;
    font: 14px/14px monospace;
    word-break: break-all;
    padding: 4px;
    background-color: rgba(249, 38, 114, 0.1);
    border-radius: 3px;
    margin: 2px 0;
}

#ai-generator {
    display: flex;
    margin: 3px 2px 0 2px;
    gap: 3px;
}

#ai-prompt {
    flex-grow: 1;
    height: var(--control-size);
    padding: 0 8px;
    border: none;
    border-radius: var(--control-corners);
    background: linear-gradient(to top, #3a445e, #181c26);
    color: #e3e3e3;
    font: var(--font-size) sans-serif;
    box-shadow: inset 0 0 12px rgba(202, 202, 202, 0.5);
}

#ai-prompt::placeholder {
    color: #8f949b;
}

#ai-generate-btn {
	height: var(--control-size);
	padding: 0 12px;
	border: none;
	border-radius: var(--control-corners);
	background-image: linear-gradient(to bottom, #959595, #242a37);
	color: #e3e3e3;
	font: bold var(--font-size) sans-serif;
	cursor: pointer;
}

#ai-generate-btn:not([disabled]):hover {
	background-image: linear-gradient(to bottom, #738cc1, #28314a);
	color: #c2dfff;
}

#ai-generate-btn[disabled] {
    opacity: 0.5;
    cursor: wait;
}

::selection {
	background-color: #596999 !important;
}

/* ==[ Library ] ========================================================================================== */
.code-text {
	display: inline-block;
	margin: 0;
	padding: 0;
	border: none;
	color: #ffcc53;
	background: none;
	font: var(--font-size)/16px monospace;
	text-align: left;
	text-decoration: none;
	white-space: pre-wrap;
	word-wrap: break-word;
	word-break: break-all;
	user-select: text;
	cursor: pointer;
}

.code-text:hover {
	color: #ed88fb !important;
}

.code-button {
	margin: 1px 0 0 6px;
	padding: 2px 6px;
	border: none;
	border-radius: 3px;
	background-image: linear-gradient(to bottom, #424242, #171b22);
	color: #ced5e1;
	font: var(--font-size)/var(--font-size) sans-serif;
	white-space: nowrap;
	cursor: pointer;
}

.code-button:hover {
	background-image: linear-gradient(to bottom, #3c508a, #1f2331);
	color: #c2dfff;
}

.code-length, .code-info {
	color: gray;
	cursor: default;
}

.code-stereo {
	color: #008040;
}

.code-exotic {
	color: #a61107;
}

#shared-beats-container .library-content {
	margin-bottom: 4px;
}

#shared-beats-container .code-text {
	max-width: calc(100% - 200px);
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	display: inline-block;
    vertical-align: middle;
}

#shared-beats-container .shared-by {
	color: #999;
	font-size: 0.9em;
	margin-left: 8px;
}

#shared-beats-container .shared-by img {
	width: 16px;
	height: 16px;
	border-radius: 50%;
	vertical-align: middle;
	margin-right: 4px;
}

.entry {
	position: relative;
}

.entry-children > .entry:not(:last-child) {
	margin-bottom: 4px;
}

.entry-children > .entry::before {
	content: "\25CF";
	position: absolute;
	top: 2px;
	left: -11px;
	color: #555;
	font-size: 12px;
}

.entry-children > .entry > .entry-children {
	margin-left: 11px;
}

.entry-top {
	padding: 6px 4px 8px 16px;
}

.entry-top:not(:first-child) {
	border-top: 1px solid #404040;
}

.library-content {
	margin: 4px 0;
	border-right: 1px solid #444;
	border-bottom: 1px solid #444;
	border-left: 1px solid #444;
	border-radius: 3px;
	background: #0a0a0a;
}

.library-header {
	padding: 4px 8px;
	border-radius: 3px;
	background-image: linear-gradient(to bottom, #000000, #0b0d17);
	cursor: pointer;
}

.library-header:hover, .library-header:focus-visible {
	background-image: linear-gradient(to bottom, #32426c, #151b2b);
	color: #94c7ff;
}

.library-header > h1 {
	display: inline;
	margin: inherit;
	font-size: var(--font-size);
}

.loading-error {
	text-align: center;
	color: #f92672;
}

@keyframes wait-anim {
	to {
		transform: rotate(360deg);
	}
}

.loading-wait {
    width: 16px;
    height: 16px;
    margin-left: 6px;
    vertical-align: top;
    animation: wait-anim 1s linear infinite;
    display: inline-block;
}

#about-section {
    margin: 4px 2px;
	border: 1px solid #444;
	border-radius: 3px;
	background: #0a0a0a;
    padding: 8px 16px;
    color: #c5c8c6;
}

#about-section h2 {
    margin: 0 0 10px 0;
    padding-bottom: 8px;
    border-bottom: 1px solid #404040;
    font-size: var(--font-size);
    font-weight: bold;
    color: #94c7ff;
}

#about-section p {
    line-height: 1.5;
    margin: 0 0 1em 0;
}

#about-section p:last-child {
    margin-bottom: 0;
}

#about-section code {
    background-color: #1b1d20;
    padding: 2px 4px;
    border-radius: 3px;
    font-family: monospace;
    color: #ffcc53;
}

/* ==[ Cheat Sheet Section ] ============================================================================= */
#cheatsheet-section {
    margin: 4px 2px;
	border: 1px solid #444;
	border-radius: 3px;
	background: #0a0a0a;
    padding: 8px 16px;
    color: #c5c8c6;
}

#cheatsheet-section h2 {
    margin: 0 0 10px 0;
    padding-bottom: 8px;
    border-bottom: 1px solid #404040;
    font-size: var(--font-size);
    font-weight: bold;
    color: #94c7ff;
}

#cheatsheet-section h3 {
    margin: 16px 0 8px 0;
    color: #89c2ff;
    font-size: var(--font-size);
    font-weight: bold;
}

#cheatsheet-section p {
    line-height: 1.5;
    margin: 0 0 0.5em 0;
}

#cheatsheet-section p:last-of-type {
    margin-bottom: 1em;
}

#cheatsheet-section code {
    background-color: #1b1d20;
    padding: 2px 4px;
    border-radius: 3px;
    font-family: monospace;
    color: #ffcc53;
}

#cheatsheet-section pre.code-text {
    display: block;
    background-color: #1b1d20;
    padding: 8px;
    border-radius: 3px;
    margin: 8px 0 12px;
    white-space: pre-wrap;
    word-wrap: break-word;
    word-break: break-all;
    cursor: pointer;
    border: 1px solid #444;
}

#cheatsheet-section pre.code-text:hover {
    color: #ed88fb !important;
    border-color: #888;
}

/* ==[ Controls ] ========================================================================================= */
.control-button, .control-select, #control-samplerate-label {
	height: var(--control-size);
	padding: 0;
	border: none;
	border-radius: var(--control-corners);
	background-image: linear-gradient(to bottom, #959595, #242a37);
	color: #e3e3e3;
	font: bold var(--font-size)/var(--control-size) sans-serif;
	cursor: pointer;
}

.control-button[disabled] {
	opacity: 0.5;
	cursor: default;
}

.control-button:not([disabled]):hover, .control-select:hover, #control-samplerate-label:hover {
	background-image: linear-gradient(to bottom, #738cc1, #28314a);
	color: #c2dfff;
}

.control-button:not([disabled]):active, .control-select:active, #control-samplerate-label:active {
	background-image: linear-gradient(to bottom, #505f84, #1c1e26);
}

.control-button.active {
    background-image: linear-gradient(to bottom, #505f84, #1c1e26);
    box-shadow: inset 0 0 12px rgba(0,0,0,0.5);
    color: #94c7ff;
}

.control-button > svg {
	width: var(--control-size);
	height: var(--control-size);
	fill: currentColor;
    vertical-align: top;
}

#control-codesize {
	min-width: 56px;
	cursor: default;
}

#control-counter, #control-samplerate, #control-samplerate-custom {
	height: var(--control-size);
	padding: 0 4px;
	background: linear-gradient(to top, #3a445e, #181c26);
}

#control-codesize, #control-counter, #control-samplerate {
	height: var(--control-size);
	padding: 0 4px;
	background: linear-gradient(to top, #3a445e, #181c26);
	color: #e3e3e3;
	border: none;
	font: bold var(--font-size)/var(--control-size) monospace;
	box-shadow: inset 0 0 12px rgba(202, 202, 202, 0.5);
}

#control-samplerate-custom {
    color: #e3e3e3;
    border: none;
    font: bold var(--font-size)/var(--control-size) monospace;
    box-shadow: inset 0 0 12px rgba(202, 202, 202, 0.5);
    flex-grow: 1;
    text-align: right;
    padding-right: 8px;
    -moz-appearance: textfield; /* Firefox */
}
#control-samplerate-custom::-webkit-inner-spin-button,
#control-samplerate-custom::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

#control-counter {
    min-width: 88px;
    border-radius: 0 var(--control-corners) var(--control-corners) 0;
    text-align: right;
    padding-right: 8px;
}

#control-counter-units {
	width: 32px;
	text-align: center;
	user-select: none;
}

.control-playing .svg-play { display: none; }
.control-paused .svg-pause { display: none; }

.control-reversing .svg-pause {
    transform: scaleX(-1);
}

.control-fast > .svg-play, .control-play > .svg-fast, .control-play > .control-fast-multiplier {
	display: none;
}

.control-fast-multiplier {
	position: absolute;
}

#control-play-backward, #control-play-forward {
	position: relative;
}

#control-play-backward > .control-fast-multiplier {
	right: 5px;
}

#control-play-backward > .control-fast-multiplier-large {
	right: 4px;
	letter-spacing: -2px;
}

#control-play-backward > svg {
	transform: scaleX(-1);
}

#control-play-forward > .control-fast-multiplier {
	left: 5px;
}

#control-play-forward > .control-fast-multiplier-large {
	left: 2px;
	letter-spacing: -2px;
}

#control-rec.control-recording {
	color: #b50000;
}

@keyframes blink {
	50% {
		opacity: 0.0;
	}
}

.control-recording > svg {
	animation: blink 1s step-start 0s infinite;
}

#control-samplerate {
    width: 56px;
    border-radius: var(--control-corners) 0 0 var(--control-corners);
    appearance: none;
    background: transparent;
    box-shadow: none;
    padding-left: 8px;
}

#control-samplerate-label {
    padding: 0;
    padding-right: 8px;
    border-radius: var(--control-corners) 0 0 var(--control-corners);
}

.control-select {
	padding-left: 2px;
	border: none;
}

.control-select > option {
	color: #435071;
}

#control-volume {
	flex-grow: 1;
	appearance: none;
	height: 10px;
	margin: 10px;
	border-radius: 4px;
	background-color: #393d44;
	align-self: center;
}

#control-volume::-moz-range-thumb {
	width: 10px;
	height: var(--control-size);
	border: none;
	border-radius: 4px;
	background-image: linear-gradient(to bottom, #aeaeae, #484c55);
	cursor: pointer;
}

#control-volume::-moz-range-thumb:hover {
	background-image: linear-gradient(to bottom, #90a7d7, #3f4c71);
}

#control-volume::-webkit-slider-thumb {
	appearance: none;
	width: 10px;
	height: var(--control-size);
	border: none;
	border-radius: 4px;
	background-image: linear-gradient(to bottom, #aeaeae, #484c55);
	cursor: pointer;
}

#control-volume::-webkit-slider-thumb:hover {
	background-image: linear-gradient(to bottom, #90a7d7, #3f4c71);
}

.controls {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 3px;
	padding: 3px 0;
	margin: 3px 2px 0 2px;
}

.controls-group {
	display: flex;
}

.controls-group > .control-button,
.controls-group > .control-select,
.controls-group > #control-counter,
.controls-group > #control-samplerate-label {
    border-left: 1px solid #5c636c;
    border-radius: 0;
}

.controls-group > :first-child {
	border: none;
	border-radius: var(--control-corners) 0 0 var(--control-corners);
}

.controls-group > :last-child {
	border-radius: 0 var(--control-corners) var(--control-corners) 0;
}

.controls-grow, .controls-grow > input {
	flex-grow: 1;
}

/* ==[ Adaptive screen ] ================================================================================== */
@media screen and (max-height: 768px) and (min-width: 768px) {
	#container-fixed {
		flex-shrink: 0;
		max-width: 516px;
		height: 100%;
	}

	#container-scroll {
		display: block !important;
		height: 100%;
		margin-top: 0;
		margin-left: 6px;
		padding-right: 6px;
	}

	#content {
		flex-flow: row;
		align-items: start;
	}

	#control-counter {
		width: 66px;
	}

	#control-expand {
		display: none;
	}

	#editor-container {
		flex: auto;
		resize: none;
	}
}

@media screen and (max-width: 768px) {
	#container-fixed, #container-scroll {
		max-width: 516px;
	}
}

@media screen and (min-width: 1440px) {
	#container-fixed {
		flex-shrink: 0;
        max-width: 1028px;
		height: 100%;
	}

	#container-scroll {
		display: block !important;
		height: 100%;
		margin-top: 0;
		margin-left: 6px;
		padding-right: 6px;
	}

	#content {
		flex-flow: row;
		align-items: start;
	}

	#control-expand {
		display: none;
	}

	#editor-container {
		flex: auto;
		resize: none;
	}
}