:root {
	--bg:         #ffffff;
	--panel-bg:   rgba(255, 255, 255, 0.82);
	--border:     #ddd;
	--text:       #222;
	--text-muted: #666;
	--accent:     #BE6521;
	--btn-bg:     #f0f0f0;
	--btn-hover:  #e0e0e0;
}

@media (prefers-color-scheme: dark) {
	:root {
		--bg:         #111111;
		--panel-bg:   rgba(24, 24, 24, 0.88);
		--border:     #333;
		--text:       #e8e8e8;
		--text-muted: #999;
		--btn-bg:     #2a2a2a;
		--btn-hover:  #3a3a3a;
	}
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
	width: 100%; height: 100%;
	background: var(--bg);
	overflow: hidden;
}

#coffeemolCanvas {
	position: absolute;
	top: 0; left: 0;
	width: 100%; height: 100%;
	display: block;
}

/* ── Panel ─────────────────────────────────────────── */

#mol-panel {
	position: absolute;
	top: 16px; left: 16px;
	width: 240px;
	background: var(--panel-bg);
	backdrop-filter: blur(10px);
	-webkit-backdrop-filter: blur(10px);
	border: 1px solid var(--border);
	border-radius: 10px;
	padding: 14px;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
	font-size: 13px;
	color: var(--text);
	display: flex;
	flex-direction: column;
	gap: 12px;
	z-index: 10;
}

.panel-title {
	font-size: 18px;
	font-weight: 600;
}

#mol-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 12px;
}

#mol-header .coffee { color: var(--accent); }

/* ── Picker ─────────────────────────────────────────── */

#mol-picker {
	display: flex;
	gap: 6px;
}

#pdb-input {
	flex: 1;
	padding: 5px 8px;
	border-radius: 6px;
	border: 1px solid var(--border);
	background: var(--btn-bg);
	color: var(--text);
	font-size: 13px;
	font-family: inherit;
	min-width: 0;
	text-transform: uppercase;
}

#pdb-input::placeholder {
	text-transform: none;
	color: var(--text-muted);
}

#mol-load, .action-button {
	padding: 5px 10px;
	border-radius: 6px;
	border: 1px solid var(--border);
	background: var(--btn-bg);
	color: var(--text);
	font-size: 13px;
	cursor: pointer;
	white-space: nowrap;
	text-align: center;
	user-select: none;
}

#mol-load:hover, .action-button:hover {
	background: var(--btn-hover);
}

/* ── Metadata ────────────────────────────────────────── */

#mol-title-display {
	font-weight: 600;
	font-size: 12px;
	line-height: 1.4;
	color: var(--text);
	text-transform: capitalize;
}

#mol-meta {
	display: flex;
	flex-direction: column;
	gap: 4px;
}

#mol-info-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	cursor: pointer;
	user-select: none;
	padding-top: 4px;
	border-top: 1px solid var(--border);
}

#mol-info-header:hover {
	color: var(--accent);
}

#mol-info-header .toggle-icon {
	font-size: 10px;
	color: var(--text-muted);
}

#mol-info.collapsed #mol-title-display,
#mol-info.collapsed #mol-meta {
	display: none;
}

.meta-row {
	display: flex;
	justify-content: space-between;
	gap: 8px;
	font-size: 11px;
}

.meta-link {
	color: var(--accent);
	text-decoration: none;
}

.meta-link:hover {
	text-decoration: underline;
}

.meta-key {
	color: var(--text-muted);
	flex-shrink: 0;
}

.meta-val {
	color: var(--text);
	text-align: right;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

/* ── Controls ────────────────────────────────────────── */
.control-group {
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.control-label {
	font-size: 10px;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--text-muted);
	font-weight: 600;
	margin-left: 2px;
}

.full-width {
	width: 100%;
}

.controls-row {
	display: flex;
	gap: 6px;
	width: 100%;
}

.buttons-row {
	margin-top: 4px;
}

.secondary-button {
	font-size: 11px;
	padding: 4px 8px;
	background: transparent;
	opacity: 0.8;
}

.secondary-button:hover {
	opacity: 1;
	background: var(--btn-bg);
}

.controls-row select.action-button {
	flex: 1;
	min-width: 0;
	padding: 5px 8px;
	text-overflow: ellipsis;
}

#mol-draw-method:focus, #mol-color-method:focus {
	outline: none;
	border-color: var(--accent);
}

/* ── Rotation panel ──────────────────────────────────── */

#settings-panel, #help-panel {
	position: absolute;
	top: 16px; right: 16px;
	width: 240px;
	background: var(--panel-bg);
	backdrop-filter: blur(10px);
	-webkit-backdrop-filter: blur(10px);
	border: 1px solid var(--border);
	border-radius: 10px;
	padding: 14px;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
	font-size: 13px;
	color: var(--text);
	display: flex;
	flex-direction: column;
	gap: 12px;
	z-index: 100;
	transition: transform 0.3s ease, opacity 0.3s ease;
}

#settings-panel.hidden, #help-panel.hidden {
	transform: translateX(20px);
	opacity: 0;
	pointer-events: none;
}

.help-section {
	display: flex;
	flex-direction: column;
	gap: 6px;
	margin-bottom: 4px;
}

.help-label {
	font-size: 10px;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--text-muted);
	font-weight: 600;
}

.help-row {
	display: flex;
	justify-content: space-between;
	font-size: 11px;
}

.help-text {
	font-size: 11px;
	line-height: 1.4;
	color: var(--text);
}

.settings-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 4px;
}

#mol-settings-toggle {
	font-size: 16px;
	padding: 4px 6px;
}

.color-picker-grid {
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	gap: 8px;
}

.color-picker-item {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	font-size: 11px;
	color: var(--text-muted);
}

.color-picker-item input[type="color"] {
	width: 24px;
	height: 24px;
	border: none;
	border-radius: 4px;
	cursor: pointer;
	background: none;
	padding: 0;
}

.color-picker-item input[type="color"]::-webkit-color-swatch-wrapper {
	padding: 0;
}

.color-picker-item input[type="color"]::-webkit-color-swatch {
	border: 1px solid var(--border);
	border-radius: 4px;
}

#rotation-panel {
	position: absolute;
	bottom: 16px; right: 16px;
	display: flex;
	align-items: center;
	gap: 6px;
	background: var(--panel-bg);
	backdrop-filter: blur(10px);
	-webkit-backdrop-filter: blur(10px);
	border: 1px solid var(--border);
	border-radius: 10px;
	padding: 8px 12px;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
	z-index: 10;
}

#rotation-label {
	font-size: 12px;
	color: var(--text-muted);
	margin-right: 2px;
}

/* ── Molecular Spinner ──────────────────────────────── */

.spinner-container {
	position: absolute;
	top: 50%; left: 50%;
	transform: translate(-50%, -50%);
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 15px;
	z-index: 100;
	pointer-events: none;
	opacity: 0;
	transition: opacity 0.3s;
}

.spinner-container.active { opacity: 1; }

.mol-spinner {
	width: 60px; height: 60px;
	position: relative;
	animation: mol-rotate 2s linear infinite;
}

.spinner-atom {
	position: absolute;
	width: 14px; height: 14px;
	background: var(--accent);
	border-radius: 50%;
	top: 50%; left: 50%;
	margin: -7px;
}

.spinner-atom:nth-child(1) { transform: rotate(0deg) translate(25px); }
.spinner-atom:nth-child(2) { transform: rotate(120deg) translate(25px); background: var(--text-muted); }
.spinner-atom:nth-child(3) { transform: rotate(240deg) translate(25px); background: var(--text-muted); }

.spinner-bond {
	position: absolute;
	width: 25px; height: 2px;
	background: var(--border);
	top: 50%; left: 50%;
	transform-origin: 0% 50%;
}

.spinner-bond:nth-child(4) { transform: rotate(0deg); }
.spinner-bond:nth-child(5) { transform: rotate(120deg); }
.spinner-bond:nth-child(6) { transform: rotate(240deg); }

@keyframes mol-rotate {
	from { transform: rotate(0deg); }
	to { transform: rotate(360deg); }
}

#drop-overlay {
	position: fixed;
	top: 0; left: 0;
	width: 100%; height: 100%;
	background: rgba(190, 101, 33, 0.15);
	border: 4px dashed var(--accent);
	display: none;
	justify-content: center;
	align-items: center;
	z-index: 1000;
	pointer-events: none;
}

#drop-overlay::after {
	content: "Drop PDB or mmCIF file to view";
	padding: 20px 40px;
	background: var(--bg);
	border-radius: 12px;
	font-weight: 600;
	color: var(--accent);
	box-shadow: 0 10px 30px rgba(0,0,0,0.1);
}

/* ── Info Display (Tooltip) ─────────────────────────── */

#mol-info-display {
	position: fixed;
	top: 0;
	left: 0;
	pointer-events: none;
	background: rgba(20, 20, 20, 0.7);
	backdrop-filter: blur(12px);
	-webkit-backdrop-filter: blur(12px);
	border: 1px solid rgba(255, 255, 255, 0.1);
	border-radius: 8px;
	padding: 10px 14px;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
	font-size: 12px;
	color: #fff;
	box-shadow: 0 8px 32px rgba(0,0,0,0.3), inset 0 0 0 1px rgba(255,255,255,0.05);
	z-index: 1000;
	display: none;
	line-height: 1.5;
}

#mol-panel.minimized #mol-controls-container {
	display: none;
}

@media (max-width: 600px) {
	#mol-panel {
		top: auto;
		bottom: 0;
		left: 0;
		width: 100% !important;
		border-radius: 16px 16px 0 0;
		border-left: none;
		border-right: none;
		border-bottom: none;
		padding-bottom: env(safe-area-inset-bottom, 20px);
		max-height: 50vh;
		overflow-y: auto;
	}

	#settings-panel, #help-panel {
		top: 0; right: 0;
		width: 100%; height: 100%;
		border-radius: 0;
		border: none;
	}

	#rotation-panel {
		bottom: auto;
		top: 16px;
		right: 16px;
		left: auto;
		transform: none;
	}

	#mol-info-display {
		bottom: 60px;
		top: auto !important;
		left: 50% !important;
		transform: translateX(-50%) !important;
		width: 90%;
		max-width: 300px;
	}
}
