:root {
  --bg: #ffffff;
  --panel: #f7f9fc;
  --surface: #ffffff;
  --canvas: #1e252d;
  --canvas-top: #252d36;
  --text: #10264b;
  --muted: #66758c;
  --border: #d8dee8;
  --border-strong: #b9c4d3;
  --blue: #1768d5;
  --blue-soft: #e9f2ff;
  --green: #4aa73b;
  --danger: #b42318;
  --shadow: 0 8px 22px rgb(12 28 53 / 12%);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body { min-width: 320px; overflow: hidden; }
button, input, select { font: inherit; }
button, summary { -webkit-tap-highlight-color: transparent; }
button:focus-visible, summary:focus-visible, input:focus-visible, select:focus-visible, canvas:focus-visible {
  outline: 3px solid rgb(23 104 213 / 30%);
  outline-offset: 1px;
}

.app-shell { height: 100%; display: grid; grid-template-rows: 68px minmax(0, 1fr) 34px; }
.app-bar { display: flex; align-items: stretch; border-bottom: 1px solid var(--border); background: var(--surface); z-index: 5; }
.brand { display: flex; align-items: center; gap: 14px; padding: 0 24px; margin-right: auto; font-size: 25px; font-weight: 720; letter-spacing: -0.035em; }
.brand svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.brand small { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); border-left: 1px solid var(--border); padding-left: 12px; }
.file-actions { display: flex; align-items: stretch; }
.toolbar-button { min-height: 100%; display: inline-flex; align-items: center; justify-content: center; gap: 10px; padding: 0 20px; border: 0; border-left: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 14px; font-weight: 650; cursor: pointer; white-space: nowrap; }
.toolbar-button:hover:not(:disabled), .export-menu[open] > summary { background: var(--panel); }
.toolbar-button.primary { color: #fff; background: var(--blue); border-color: var(--blue); }
.toolbar-button.primary:hover:not(:disabled) { background: #0f58b9; }
.toolbar-button:disabled { color: #99a4b4; cursor: not-allowed; background: #f8f9fb; }
.toolbar-button svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.toolbar-button .chevron { width: 14px; height: 14px; }
.export-menu { position: relative; }
.export-menu summary { list-style: none; height: 100%; }
.export-menu summary::-webkit-details-marker { display: none; }
.export-popover { position: absolute; right: 8px; top: calc(100% + 6px); width: 180px; padding: 6px; border: 1px solid var(--border); border-radius: 7px; background: #fff; box-shadow: var(--shadow); z-index: 20; }
.export-popover button { width: 100%; border: 0; border-radius: 5px; background: transparent; padding: 10px 12px; color: var(--text); text-align: left; font-size: 13px; cursor: pointer; }
.export-popover button:hover { background: var(--blue-soft); }

.workspace { min-height: 0; display: grid; grid-template-columns: 280px minmax(360px, 1fr) 320px; }
.left-panel, .inspector { min-height: 0; overflow: auto; background: var(--panel); }
.left-panel { display: flex; flex-direction: column; padding: 20px 16px 14px; border-right: 1px solid var(--border); }
.inspector { border-left: 1px solid var(--border); }
.inspector section { padding: 19px 20px 21px; border-bottom: 1px solid var(--border); }
h2 { margin: 0 0 14px; font-size: 11px; line-height: 1.2; font-weight: 760; letter-spacing: .065em; text-transform: uppercase; color: #44536a; }
.mode-switch { border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: #fff; }
.mode-button { position: relative; width: 100%; display: flex; align-items: center; gap: 13px; height: 52px; border: 0; border-bottom: 1px solid var(--border); background: #fff; color: var(--text); font-size: 14px; font-weight: 650; text-align: left; cursor: pointer; }
.mode-button:last-child { border-bottom: 0; }
.mode-button:hover { background: #f9fbfd; }
.mode-button.active { background: var(--blue-soft); color: #0d4eaa; box-shadow: inset 4px 0 var(--blue); }
.rect-icon { display: block; width: 22px; height: 22px; margin-left: 16px; border: 2px solid; }
.rect-icon.lcd { border-color: var(--green); }
.rect-icon.key { border-color: var(--blue); border-style: dashed; }
.key-section { flex: 1; min-height: 0; display: flex; flex-direction: column; margin-top: 24px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; }
.section-heading h2 { margin-bottom: 12px; }
.section-heading > span { font-size: 11px; color: var(--muted); margin-bottom: 12px; }
.search-box { height: 40px; display: flex; align-items: center; gap: 8px; padding: 0 11px; border: 1px solid var(--border); border-radius: 5px; background: #fff; }
.search-box:focus-within { border-color: var(--blue); box-shadow: 0 0 0 2px rgb(23 104 213 / 12%); }
.search-box svg { width: 19px; height: 19px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.search-box input { width: 100%; border: 0; outline: 0; color: var(--text); background: transparent; font-size: 13px; }
.search-box input::placeholder { color: #8490a1; }
.key-list { flex: 1; min-height: 120px; margin-top: 10px; border: 1px solid var(--border); border-radius: 5px; overflow-y: auto; background: #fff; }
.key-row { width: 100%; display: grid; grid-template-columns: 36px 1fr 10px; align-items: center; gap: 8px; min-height: 38px; padding: 0 11px; border: 0; border-bottom: 1px solid #e5e9ef; background: #fff; color: var(--text); font-size: 13px; text-align: left; cursor: pointer; }
.key-row:last-child { border-bottom: 0; }
.key-row:hover { background: #f5f8fc; }
.key-row.selected { color: #0d4eaa; background: var(--blue-soft); box-shadow: inset 3px 0 var(--blue); }
.key-index { color: var(--muted); font-variant-numeric: tabular-nums; }
.key-defined { width: 7px; height: 7px; border: 1px solid #aab4c1; border-radius: 50%; }
.key-defined.yes { border-color: var(--blue); background: var(--blue); }
.keyboard-help { margin: 12px 2px 0; font-size: 11px; line-height: 1.45; color: var(--muted); }

.canvas-panel { min-width: 0; min-height: 0; display: grid; grid-template-rows: 48px minmax(0, 1fr); background: var(--canvas); }
.canvas-toolbar { display: flex; justify-content: space-between; align-items: center; min-width: 0; padding: 0 16px; color: #dce4ed; border-bottom: 1px solid #3d4752; background: var(--canvas-top); }
.tool-hint { min-width: 0; display: flex; align-items: center; gap: 9px; font-size: 12px; color: #c2ccd7; }
.tool-hint span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-hint svg { flex: 0 0 auto; width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.zoom-controls { display: flex; height: 32px; border: 1px solid #53606c; border-radius: 5px; overflow: hidden; }
.zoom-controls button, .zoom-controls output { display: grid; place-items: center; min-width: 36px; border: 0; border-right: 1px solid #53606c; background: #29323b; color: #fff; font-size: 13px; }
.zoom-controls button { cursor: pointer; }
.zoom-controls button:hover { background: #35414d; }
.zoom-controls output { min-width: 62px; font-variant-numeric: tabular-nums; }
.zoom-controls button:last-child { border-right: 0; min-width: 46px; }
.canvas-scroller { position: relative; min-height: 0; overflow: auto; padding: 36px; background-color: var(--canvas); background-image: linear-gradient(45deg, rgb(255 255 255 / 2%) 25%, transparent 25%), linear-gradient(-45deg, rgb(255 255 255 / 2%) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, rgb(255 255 255 / 2%) 75%), linear-gradient(-45deg, transparent 75%, rgb(255 255 255 / 2%) 75%); background-size: 24px 24px; background-position: 0 0, 0 12px, 12px -12px, -12px 0; }
.canvas-stage { width: max-content; min-width: 100%; min-height: 100%; }
#skinCanvas { display: block; margin: auto; cursor: crosshair; box-shadow: 0 16px 42px rgb(0 0 0 / 42%); image-rendering: auto; touch-action: none; }
.empty-state { position: absolute; inset: 0; display: grid; grid-template-columns: minmax(0, 540px); place-content: center; justify-items: center; padding: 32px; color: #e8edf3; text-align: center; }
.empty-visual { width: 92px; height: 116px; margin-bottom: 22px; color: #607180; }
.empty-visual svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 2; }
.empty-visual g { fill: #374550; stroke-width: 1.5; }
.empty-state h1 { max-width: 100%; margin: 0; font-size: 21px; letter-spacing: -.015em; overflow-wrap: anywhere; }
.empty-state p { max-width: 410px; margin: 10px 0 21px; color: #aeb9c5; font-size: 14px; line-height: 1.5; }
.empty-state > div:last-of-type { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; }
.empty-state button { min-height: 40px; padding: 0 16px; border-radius: 5px; font-size: 13px; font-weight: 670; cursor: pointer; }
.empty-primary { border: 1px solid var(--blue); background: var(--blue); color: #fff; }
.empty-secondary { border: 1px solid #667685; background: transparent; color: #e8edf3; }
.empty-state small { margin-top: 18px; color: #8794a1; }
.canvas-scroller.drag-over::after { content: "Drop file to open"; position: absolute; inset: 14px; display: grid; place-items: center; border: 2px dashed #66a4f5; background: rgb(20 54 91 / 88%); color: #fff; font-size: 18px; font-weight: 700; z-index: 4; }

.inspector label { display: grid; gap: 7px; margin-top: 13px; color: #263a59; font-size: 12px; font-weight: 650; }
.inspector input[type="text"], .inspector input[type="number"], .inspector select { width: 100%; height: 39px; border: 1px solid var(--border-strong); border-radius: 5px; padding: 0 10px; background: #fff; color: var(--text); font-size: 13px; font-weight: 430; }
.inspector input:disabled, .inspector select:disabled { background: #f0f2f5; color: #8b96a5; }
.inspector input:not(:disabled):focus, .inspector select:not(:disabled):focus { border-color: var(--blue); }
.color-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.inspector input[type="color"] { width: 100%; height: 39px; padding: 4px; border: 1px solid var(--border-strong); border-radius: 5px; background: #fff; cursor: pointer; }
.coordinate-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.selection-name { margin: 14px 0 0; padding: 10px 11px; border-left: 3px solid var(--green); background: #eef7ed; color: #315d2a; font-size: 12px; }
.selection-name.key { border-color: var(--blue); background: var(--blue-soft); color: #164e99; }
.text-button { border: 0; padding: 2px 0; background: transparent; font-size: 11px; font-weight: 700; cursor: pointer; }
.text-button.danger { color: var(--danger); }
.text-button:disabled { color: #9ca5b1; cursor: default; }
.file-info dl { margin: 0; }
.file-info dl > div { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; font-size: 12px; }
.file-info dt { color: var(--muted); }
.file-info dd { margin: 0; color: var(--text); text-align: right; }

.status-bar { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 0 14px; border-top: 1px solid var(--border); background: #fff; color: #57667b; font-size: 11px; }
.status-bar > div { display: flex; gap: 14px; }
.status-bar > div span + span { border-left: 1px solid var(--border); padding-left: 14px; }
.status-bar p { margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toast { position: fixed; left: 50%; bottom: 50px; transform: translate(-50%, 12px); max-width: min(520px, calc(100vw - 32px)); padding: 11px 15px; border-radius: 6px; background: #10264b; color: #fff; box-shadow: var(--shadow); font-size: 13px; opacity: 0; visibility: hidden; transition: opacity 160ms ease, transform 160ms ease, visibility 160ms; z-index: 100; }
.toast.show { opacity: 1; visibility: visible; transform: translate(-50%, 0); }
.toast.error { background: #8f2018; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 1050px) {
  .workspace { grid-template-columns: 220px minmax(340px, 1fr) 270px; }
  .toolbar-button { padding: 0 13px; }
  .toolbar-button svg { display: none; }
  .brand { padding: 0 16px; }
}

@media (max-width: 800px) {
  body { overflow: auto; }
  .app-shell { height: auto; min-height: 100%; grid-template-rows: auto auto auto; }
  .app-bar { flex-wrap: wrap; }
  .brand { height: 58px; }
  .file-actions { width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); border-top: 1px solid var(--border); }
  .toolbar-button { min-width: 0; min-height: 48px; overflow: hidden; text-overflow: ellipsis; font-size: 12px; padding: 0 8px; border-bottom: 1px solid var(--border); }
  .export-menu .toolbar-button { width: 100%; }
  .export-popover { top: calc(100% + 3px); }
  .workspace { grid-template-columns: 1fr; grid-template-rows: auto minmax(480px, 72vh) auto; }
  .left-panel { border-right: 0; border-bottom: 1px solid var(--border); }
  .left-panel .key-section, .keyboard-help { display: none; }
  .mode-switch { display: grid; grid-template-columns: 1fr 1fr; }
  .mode-button { border-bottom: 0; }
  .mode-button:first-child { border-right: 1px solid var(--border); }
  .canvas-toolbar { padding: 0 8px; }
  .tool-hint span { display: none; }
  .zoom-controls { flex: 0 0 auto; }
  .empty-state { padding: 24px 16px; }
  .empty-state h1 { font-size: 18px; }
  .inspector { border-left: 0; border-top: 1px solid var(--border); display: grid; grid-template-columns: 1fr 1fr; }
  .status-bar { min-height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
