/*
 * Elysium scripting guide - the editor page. Uses the colours of css/style.css.
 *
 *   .ide           the whole page under the header
 *   .ide-bar       toolbar            .ide-tabs     one tab per file
 *   .ide-main      .ide-ref (API reference) next to .ide-code (editor + problems)
 *   .ide-status    line at the bottom
 *   .dialog        snippets, shortcuts, share
 */

body[data-page="editor"] {
	overflow: hidden;
}

/* the editor fills the window, so its header does too */
body[data-page="editor"] .header-inner {
	max-width: none;
}

.ide {
	display: flex;
	flex-direction: column;
	height: calc(100vh - var(--header-h));
	height: calc(100dvh - var(--header-h));
}

/* ---------------------------------------------------------------- toolbar */

.ide-bar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 6px;
	padding: 8px 12px;
	border-bottom: 1px solid var(--line);
	background: var(--bg-raised);
}

.ide-bar button,
.dialog button {
	height: 30px;
	padding: 0 11px;
	border: 1px solid var(--line);
	border-radius: var(--radius);
	background: var(--surface);
	color: var(--text);
	font: 600 12.5px var(--sans);
	white-space: nowrap;
	cursor: pointer;
}

.ide-bar button:hover,
.dialog button:hover {
	border-color: var(--accent-line);
	background: var(--accent-soft);
}

.ide-bar button.primary,
.dialog button.primary {
	border-color: transparent;
	background: var(--accent-strong);
	color: #fff;
}

.ide-bar button.on {
	border-color: var(--accent-line);
	color: var(--accent);
}

.ide-gap {
	width: 1px;
	height: 18px;
	margin: 0 4px;
	background: var(--line);
}

.ide-space {
	flex: 1;
}

/* ------------------------------------------------------------------- tabs */

.ide-tabs {
	display: flex;
	align-items: stretch;
	min-height: 36px;
	padding: 0 8px;
	border-bottom: 1px solid var(--line);
	background: var(--bg);
	overflow-x: auto;
	scrollbar-width: thin;
}

.ide-tab {
	display: flex;
	align-items: center;
	gap: 6px;
	padding: 0 6px 0 12px;
	border: 0;
	border-bottom: 2px solid transparent;
	background: none;
	color: var(--text-dim);
	font: 13px var(--mono);
	white-space: nowrap;
	cursor: pointer;
}

.ide-tab:hover {
	color: var(--text);
}

.ide-tab.active {
	border-bottom-color: var(--accent);
	color: var(--text);
}

.ide-tab.has-errors .ide-tab-name {
	color: var(--bad);
}

.ide-tab input {
	width: 150px;
	padding: 2px 6px;
	border: 1px solid var(--accent);
	border-radius: var(--radius);
	background: var(--bg-sunken);
	font: inherit;
	outline: none;
}

.ide-tab-close,
.ide-tab-add {
	display: grid;
	place-items: center;
	width: 20px;
	height: 20px;
	padding: 0;
	border: 0;
	border-radius: var(--radius);
	background: none;
	color: var(--text-faint);
	font-size: 15px;
	line-height: 1;
	cursor: pointer;
}

.ide-tab-add {
	align-self: center;
	width: 26px;
	height: 26px;
	margin-left: 4px;
	font-size: 18px;
}

.ide-tab-close:hover,
.ide-tab-add:hover {
	background: var(--surface-2);
	color: var(--text);
}

/* ------------------------------------------------------------------- main */

.ide-main {
	display: flex;
	flex: 1;
	min-height: 0;
}

.ide-ref {
	display: flex;
	flex-direction: column;
	flex: none;
	width: 300px;
	border-right: 1px solid var(--line);
	background: var(--bg);
}

.ide-ref[hidden] {
	display: none;
}

.ide-ref input {
	margin: 10px;
	height: 34px;
	padding: 0 12px;
	border: 1px solid var(--line);
	border-radius: var(--radius);
	background: var(--surface);
	font-size: 13.5px;
}

.ide-ref input:focus {
	outline: none;
	border-color: var(--accent);
	box-shadow: 0 0 0 3px var(--accent-soft);
}

.ide-ref-list {
	flex: 1;
	padding: 0 6px 16px;
	overflow-y: auto;
	scrollbar-width: thin;
}

.ide-ref-group > summary {
	padding: 6px 8px;
	border-radius: var(--radius);
	color: var(--text-faint);
	font: 600 12.5px var(--mono);   /* module names are code: no capitals */
	cursor: pointer;
	user-select: none;
}

.ide-ref-group > summary:hover {
	color: var(--text-dim);
}

.ide-ref-row {
	display: flex;
	align-items: center;
	border-radius: var(--radius);
}

.ide-ref-row:hover {
	background: var(--surface);
}

.ide-ref-row button {
	flex: 1;
	min-width: 0;
	padding: 3px 8px 3px 16px;
	border: 0;
	background: none;
	color: var(--text-dim);
	font: 12.5px/1.5 var(--mono);
	text-align: left;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	cursor: pointer;
}

.ide-ref-row button b {
	color: var(--text);
	font-weight: 500;
}

.ide-ref-row a {
	flex: none;
	padding: 0 8px;
	color: var(--text-faint);
	font-size: 12px;
	opacity: 0;
}

.ide-ref-row:hover a,
.ide-ref-row a:focus-visible {
	opacity: 1;
}

.ide-ref-empty {
	padding: 12px;
	color: var(--text-faint);
	font-size: 13px;
}

.ide-code {
	display: flex;
	flex-direction: column;
	flex: 1;
	min-width: 0;
}

.ide-editor {
	position: relative;
	flex: 1;
	min-height: 0;
}

.ide-loading {
	display: grid;
	place-items: center;
	height: 100%;
	padding: 24px;
	color: var(--text-faint);
	text-align: center;
}

/* shown instead of the editor when the CDN cannot be reached */
.ide-fallback {
	display: flex;
	flex-direction: column;
	height: 100%;
}

.ide-fallback p {
	margin: 0;
	padding: 10px 14px;
	border-bottom: 1px solid var(--line);
	color: var(--warn);
	font-size: 13.5px;
}

.ide-fallback textarea {
	flex: 1;
	padding: 14px;
	border: 0;
	outline: 0;
	resize: none;
	background: var(--bg-sunken);
	color: var(--text);
	font: 13.5px/1.6 var(--mono);
	tab-size: 4;
	white-space: pre;
}

.ide-problems {
	max-height: 30%;
	border-top: 1px solid var(--line);
	background: var(--bg-raised);
	overflow-y: auto;
	scrollbar-width: thin;
}

.ide-problem {
	display: flex;
	gap: 10px;
	width: 100%;
	padding: 5px 14px;
	border: 0;
	border-bottom: 1px solid var(--line-soft);
	background: none;
	color: var(--text);
	font-size: 13px;
	text-align: left;
	cursor: pointer;
}

.ide-problem:hover {
	background: var(--surface);
}

.ide-problem i {
	flex: none;
	width: 62px;
	color: var(--bad);
	font-size: 11px;
	font-style: normal;
	font-weight: 700;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	line-height: 20px;
}

.ide-problem.warning i {
	color: var(--warn);
}

.ide-problem span {
	flex: none;
	color: var(--text-faint);
	font: 12px/20px var(--mono);
}

/* ----------------------------------------------------------------- status */

.ide-status {
	display: flex;
	align-items: center;
	gap: 16px;
	min-height: 28px;
	padding: 0 14px;
	border-top: 1px solid var(--line);
	background: var(--bg-raised);
	color: var(--text-faint);
	font-size: 12px;
	white-space: nowrap;
}

.ide-status button {
	padding: 0;
	border: 0;
	background: none;
	color: var(--good);
	font: inherit;
	cursor: pointer;
}

.ide-status button.errors { color: var(--bad); }
.ide-status button.warnings { color: var(--warn); }

#ide-message {
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	color: var(--text);
}

/* ---------------------------------------------------------------- dialogs */

.dialog-layer {
	position: fixed;
	inset: 0;
	z-index: 60;
	display: flex;
	align-items: flex-start;
	justify-content: center;
	padding: 9vh 16px 16px;
	background: rgba(0, 0, 0, 0.6);
	backdrop-filter: blur(3px);
}

.dialog {
	display: flex;
	flex-direction: column;
	width: min(760px, 100%);
	max-height: 80vh;
	border: 1px solid var(--line);
	border-radius: var(--radius);
	background: var(--bg-raised);
	box-shadow: var(--shadow);
	overflow: hidden;
}

.dialog-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 12px 16px;
	border-bottom: 1px solid var(--line);
	font-weight: 700;
}

.dialog-body {
	padding: 8px 16px 16px;
	overflow-y: auto;
	scrollbar-width: thin;
}

.dialog h4 {
	margin: 16px 0 6px;
	color: var(--text-faint);
	font-size: 11.5px;
	letter-spacing: 0.08em;
	text-transform: uppercase;
}

.snippet {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 8px 0;
	border-bottom: 1px solid var(--line-soft);
}

.snippet div {
	flex: 1;
	min-width: 0;
}

.snippet strong {
	display: block;
	font: 600 13.5px var(--mono);
}

.snippet span {
	display: block;
	color: var(--text-dim);
	font-size: 13px;
	line-height: 1.45;
}

.keys {
	display: grid;
	grid-template-columns: max-content 1fr;
	gap: 8px 18px;
	margin: 10px 0 0;
	font-size: 14px;
}

.keys dt {
	white-space: nowrap;
}

.keys dd {
	margin: 0;
	color: var(--text-dim);
}

.share-link {
	width: 100%;
	height: 38px;
	margin: 8px 0;
	padding: 0 12px;
	border: 1px solid var(--line);
	border-radius: var(--radius);
	background: var(--bg-sunken);
	font: 12.5px var(--mono);
}

/* ---------------------------------------------------------- small screens */

@media (max-width: 900px) {
	.ide-ref {
		position: absolute;
		z-index: 30;
		top: 0;
		bottom: 0;
		left: 0;
		width: min(300px, 86vw);
		box-shadow: var(--shadow);
	}

	.ide-main {
		position: relative;
	}

	.ide-gap {
		display: none;
	}

	#ide-saved {
		display: none;
	}
}

/* icons on the toolbar */
.ide-bar button i {
	margin-right: 6px;
	font-size: 12px;
	opacity: 0.85;
}
