:root {
	--bg-body: #181a1f;
	--bg-panel: #22242a;
	--bg-header: #1c1e23;
	--bg-input: #2c2e34;
	--bg-button: #343741;
	--bg-button-hover: #3f414d;
	--bg-button-active: #2a2c33;
	--bg-key: #2f323b;
	--bg-key-special: #272931;
	--bg-log: #11131a;

	--text-main: #d5d7df;
	--text-muted: #9da2b3;
	--text-bright: #ffffff;
	--text-on-accent: #ffffff;

	--border-color: #3b3f4b;
	--border-focus: #6aa9ff;
	--border-error: #f0726a;

	--accent-color: #5c94ff;
	--accent-hover: #4c81e1;

	--shadow-card: 0 10px 26px rgba(0, 0, 0, 0.45);
	--shadow-key: 0 2px 4px rgba(0, 0, 0, 0.35);

	--kb-step: 44px;
	--key-unit: 34px;
	--key-gap: 4px;
	--key-height: 34px;
	--radius-md: 10px;
	--radius-sm: 6px;
}

* {
	box-sizing: border-box;
}

body {
	font-family: "Segoe UI", "Meiryo", "Hiragino Kaku Gothic ProN", system-ui, -apple-system, sans-serif;
	margin: 0;
	color: var(--text-main);
	background: linear-gradient(135deg, #15161a, #1c1e23 60%, #17181c);
	min-height: 100vh;
	line-height: 1.35;
}

header {
	display: grid;
	grid-template-columns: auto 1fr;
	align-items: center;
	column-gap: 14px;
	padding: 10px 20px;
	background: var(--bg-header);
	border-bottom: 1px solid var(--border-color);
	box-shadow: 0 5px 12px rgba(0, 0, 0, 0.35);
	position: sticky;
	top: 0;
	z-index: 40;
}

.header-title {
	display: flex;
	align-items: baseline;
	gap: 10px;
	flex-wrap: wrap;
}
#btnLogClear {
	font-size: 10px;
	padding: 2px 10px;

}

header h1 {
	margin: 0;
	font-size: 22px;
	letter-spacing: 0.5px;
	color: var(--text-bright);
}

.header-title .manual-link {
	margin-right: 0;
	color: var(--text-muted);
	text-decoration: underline;
	font-size: 12px;
}

.header-title .manual-link:hover {
	color: var(--text-bright);
	text-decoration: underline;
}

.head-controls {
	display: flex;
	align-items: center;
	justify-content: flex-end;
	gap: 12px;
	flex-wrap: wrap;
}

.head-actions,
.head-tools {
	display: flex;
	align-items: center;
	gap: 8px;
}

.head-actions .manual-link {
	margin-right: auto;
	color: inherit;
	text-decoration: underline;
	font-size: 12px;
}

.head-actions .manual-link:hover {
	text-decoration: underline;
}

.fw-version {
	font-size: 12px;
	color: var(--text-muted);
	font-family: "Consolas", "SFMono-Regular", monospace;
}

.config-summary {
	font-size: 11px;
	color: var(--text-muted);
	padding: 2px 12px;
	border-radius: 999px;
	border: 1px solid rgba(255, 255, 255, 0.12);
	background: rgba(255, 255, 255, 0.04);
	font-family: "Consolas", "SFMono-Regular", monospace;
	line-height: 1.3;
	display: inline-flex;
	align-items: center;
}

.badge {
	padding: 4px 12px;
	background: rgba(255, 255, 255, 0.08);
	border-radius: 16px;
	border: 1px solid rgba(255, 255, 255, 0.12);
	font-size: 12px;
	color: var(--text-bright);
}

button {
	background: var(--bg-button);
	color: var(--text-main);
	border: 1px solid var(--border-color);
	border-radius: var(--radius-sm);
	padding: 5px 10px;
	font-size: 12px;
	cursor: pointer;
	transition: all 0.2s ease;
	box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 4px 12px rgba(0, 0, 0, 0.25);
}

button:hover:not(:disabled) {
	background: var(--bg-button-hover);
	color: var(--text-bright);
	transform: translateY(-1px);
}

button:active:not(:disabled) {
	background: var(--bg-button-active);
	transform: translateY(1px);
}

button:disabled {
	opacity: 0.45;
	cursor: not-allowed;
}

#btnConnect,
#btnWrite,
#btnFileSave {
	background: var(--accent-color);
	border-color: transparent;
	color: var(--text-on-accent);
}

#btnFirmwareUpdate {
	margin-left: 20px;
}

#wheel-buttons {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 6px;
}

.size-over {
	color: var(--border-error);
	font-weight: 700;
}

#btnConnect:hover:not(:disabled),
#btnWrite:hover:not(:disabled),
#btnFileSave:hover:not(:disabled) {
	background: var(--accent-hover);
}

main {
	display: flex;
	flex-direction: column;
	gap: 8px;
	padding: 14px 16px 18px;
	max-width: none;
	margin: 0;
}

section,

.pads,
.assist,
.log {
	background: var(--bg-panel);
	border: 1px solid rgba(255, 255, 255, 0.06);
	border-radius: var(--radius-md);
	padding: 8px 10px;
	box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}

h2 {
	margin: 0 0 4px;
	font-size: 15px;
	color: var(--text-bright);
}

h3 {
	margin: 0 0 4px;
	font-size: 12px;
	color: var(--text-muted);
	letter-spacing: 0.35px;
	text-transform: uppercase;
}

#pads {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
	gap: 6px;
}

#pads .row {
	display: grid;
	grid-template-columns: 86px 1fr;
	gap: 4px;
	align-items: center;
	padding: 3px 5px;
	border-radius: var(--radius-sm);
	background: rgba(0, 0, 0, 0.18);
	border: 1px solid transparent;
	transition: border-color 0.2s ease, background 0.2s ease;
}

#pads .row:hover {
	border-color: rgba(255, 255, 255, 0.15);
}

#pads label {
	font-family: "Consolas", "SFMono-Regular", monospace;
	font-size: 11px;
	color: var(--text-muted);
	line-height: 1.2;
}

#pads input[type="text"] {
	width: 100%;
	padding: 4px 7px;
	border-radius: var(--radius-sm);
	background: var(--bg-input);
	color: var(--text-bright);
	border: 1px solid var(--border-color);
	font-family: "Consolas", monospace;
	font-size: 13px;
	outline: none;
	transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#pads input[type="text"]:focus {
	border-color: var(--border-focus);
	box-shadow: 0 0 0 2px rgba(106, 169, 255, 0.2);
}

#pads input[type="text"].active {
	border-color: var(--border-error);
	box-shadow: 0 0 0 2px rgba(240, 114, 106, 0.25);
}

.assist-panels {
	display: grid;
	grid-template-columns: 2fr 0.95fr 0.9fr;
	gap: 8px;
}

.panel {
	border-radius: var(--radius-md);
	border: 1px solid rgba(255, 255, 255, 0.06);
	background: rgba(0, 0, 0, 0.18);
	padding: 6px;
}

.keyboard {
	display: flex;
	flex-direction: column;
	gap: 4px;
	padding: 2px;
}

.kb-layout {
	display: grid;
	grid-template-columns: max-content max-content max-content;
	gap: 14px;
	align-items: end;
	justify-items: start;
}

.kb-main {
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.kb-nav,
.kb-arrows,
.kb-num {
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.kb-nav {
	align-items: flex-start;
}

.kb-num {
	align-self: end;
	align-items: flex-start;
	justify-content: flex-start;
}

.kb-row {
	display: flex;
	flex-wrap: nowrap;
	gap: 3px;
}

.key {
	min-width: var(--key-unit);
	min-height: var(--key-height);
	padding: 0 6px;
	border-radius: 6px;
	border: 1px solid rgba(255, 255, 255, 0.08);
	background: var(--bg-key);
	color: var(--text-main);
	font-size: 11px;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	box-shadow: var(--shadow-key);
	transition: transform 0.1s ease, background 0.1s ease;
}

.key:hover {
	background: rgba(255, 255, 255, 0.1);
	color: var(--text-bright);
	transform: translateY(-1px);
}

.key:active {
	transform: translateY(1px);
}

.key.special {
	background: var(--bg-key-special);
}

.key.blank {
	background: transparent;
	border: none;
	box-shadow: none;
	pointer-events: none;
}

.key.wide { min-width: 64px; }
.key.w1 { min-width: calc(var(--key-unit) * 1.3); }
.key.w2 { min-width: calc(var(--key-unit) * 1.5); }
.key.w3 { min-width: calc(var(--key-unit) * 2); }
.key.w4 { min-width: calc(var(--key-unit) * 2.5); }
.key.w5 { min-width: calc(var(--key-unit) * 3); }
.key.space { min-width: 180px; }
.key.tall { min-height: 56px; }

.mouse-row {
	display: flex;
	flex-wrap: wrap;
	gap: 4px;
	margin: 2px 0;
}

.mouse-buttons-grid {
	display: grid;
	grid-template-columns: repeat(3, minmax(64px, 1fr));
	gap: 4px;
}

.mouse-buttons-grid button {
	font-size: 10px;
	padding: 4px 3px;
}

.grid-cross {
	display: grid;
	grid-template-columns: repeat(3, max-content);
	grid-template-rows: repeat(3, max-content);
	grid-template-areas:
		". up ."
		"left center right"
		". down .";
	gap: 4px 12px;
	justify-content: center;
	align-items: center;
}

.move-slot {
	display: flex;
	flex-direction: column;
	gap: 1px;
}

.move-slot.horizontal {
	flex-direction: row;
}

.move-slot button {
	width: 46px;
	height: 26px;
	font-size: 10px;
	padding: 2px 4px;
}

.move-slot.move-up { grid-area: up; align-items: center; }
.move-slot.move-down { grid-area: down; align-items: center; }
.move-slot.move-left {
	grid-area: left;
	align-items: center;
	justify-content: flex-end;
}
.move-slot.move-right {
	grid-area: right;
	align-items: center;
	justify-content: flex-start;
}


.move-center {
	grid-area: center;
	width: 28px;
	height: 28px;
	border-radius: 6px;
	border: 1px dashed rgba(255, 255, 255, 0.22);
	color: var(--text-muted);
	font-size: 10px;
	display: flex;
	align-items: center;
	justify-content: center;
}

.mouse-buttons-side .label,
.special-grid .label {
	font-size: 10px;
	color: var(--text-muted);
}

.special-grid {
	display: flex;
	flex-direction: column;
	gap: 3px;
}

.special-grid .row {
	display: flex;
	flex-wrap: wrap;
	gap: 2px 4px;
	align-items: center;
}

.special-grid button {
	font-size: 10px;
	padding: 4px 6px;
	margin: 1px 0;
}

.special-grid .row .label {
	margin-right: 2px;
	line-height: 1.1;
}

.device-settings {
	display: flex;
	gap: 10px;
	margin-top: 4px;
	flex-wrap: wrap;
}

.device-settings-left {
	flex: 1 1 190px;
}


.device-led-panel {
	flex: 1 1 200px;
	padding: 0;
	border-radius: 0;
	border: none;
	background: transparent;
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.led-indicator-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 6px;
	flex-wrap: wrap;
}

.led-caption {
	font-size: 10px;
	font-weight: 600;
	color: var(--text-bright);
	letter-spacing: 0.3px;
}

.led-indicator {
	display: flex;
	align-items: center;
	gap: 4px;
	padding: 2px 6px;
	border-radius: 12px;
	border: 1px solid rgba(255, 255, 255, 0.12);
	background: rgba(0, 0, 0, 0.35);
}

.led-indicator-dot {
	width: 14px;
	height: 14px;
	border-radius: 50%;
	background: #111;
	border: 1px solid rgba(255, 255, 255, 0.2);
	box-shadow: 0 0 0 rgba(0, 0, 0, 0);
}

.led-indicator-label {
	font-size: 9px;
	color: var(--text-muted);
}

.led-picker {
	display: flex;
	flex-direction: column;
	gap: 6px;
	margin-top: 6px;
}

.led-picker-input {
	display: flex;
	align-items: center;
	gap: 12px;
	font-size: 11px;
	color: var(--text-muted);
}

.led-picker-input input[type="color"] {
	width: 48px;
	height: 32px;
	border: none;
	background: transparent;
	padding: 0;
	cursor: pointer;
}

.led-picker-actions {
	display: flex;
	gap: 6px;
}

.led-picker-value {
	font-family: "Consolas", "SFMono-Regular", monospace;
	font-size: 11px;
	color: var(--text-muted);
}

button.led-off {
	border-color: #c97d7d;
	color: #ffdede;
}

button.led-off:hover:not(:disabled) {
	background: #632f2f;
	color: #fff;
}

.log {
	display: flex;
	flex-direction: column;
	gap: 3px;
}

.log-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-bottom: 0;
}

.log-header h2 {
	margin: 0;
}

#log {
	background: var(--bg-log);
	color: #cfd4e3;
	font-family: "Consolas", monospace;
	font-size: 11px;
	border: 1px solid rgba(255, 255, 255, 0.08);
	border-radius: var(--radius-sm);
	padding: 8px;
	min-height: 110px;
	max-height: 190px;
	overflow: auto;
	white-space: pre-wrap;
	background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent);
}

footer {
	padding: 10px 16px;
	text-align: center;
	color: var(--text-muted);
	border-top: 1px solid rgba(255, 255, 255, 0.08);
	background: rgba(0, 0, 0, 0.25);
}

footer .fw-link {
	margin-left: 12px;
	color: var(--text-muted);
	text-decoration: underline;
	font-size: 12px;
}

footer .fw-link:hover {
	color: var(--text-bright);
	text-decoration: underline;
}

::-webkit-scrollbar {
	width: 10px;
	height: 10px;
}

::-webkit-scrollbar-track {
	background: rgba(255, 255, 255, 0.04);
}

::-webkit-scrollbar-thumb {
	background: rgba(255, 255, 255, 0.18);
	border-radius: 6px;
}

::-webkit-scrollbar-thumb:hover {
	background: rgba(255, 255, 255, 0.3);
}
