:root {
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #e9eff8;
  background: #0b111b;
  --inspector-width: 340px;
  --region-width: 236px;
  --line: #2a3546;
  --muted: #9aaac0;
  --blue: #4aa3e9;
  --warm: #ffc47a;
}
* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; }
body { min-height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
button, input, select { font: inherit; }
button, .filelabel {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 34px; padding: 6px 11px;
  background: #202b3b; border: 1px solid #39485c; border-radius: 5px;
  color: #e9eff8; cursor: pointer; white-space: nowrap;
}
button:hover, .filelabel:hover { background: #2b3a50; border-color: #59708c; }
button:focus-visible, .filelabel:focus-within, input:focus-visible, select:focus-visible {
  outline: 2px solid #80bff0; outline-offset: 2px;
}
button:disabled { opacity: .42; cursor: default; }
button.active, .accent, .filelabel.primary { background: #194a70; border-color: #3b8cc7; }
button.active:hover, .accent:hover, .filelabel.primary:hover { background: #225d89; }
input[type="file"] { display: none; }
input:not([type="file"]), select {
  min-width: 0; max-width: 100%; padding: 7px 9px;
  background: #0e1723; border: 1px solid #3b4b60; border-radius: 5px;
  color: #edf3fb;
}
input[type="number"] { font-variant-numeric: tabular-nums; }
input[type="range"] { accent-color: var(--blue); padding: 0; width: 100%; }
small, .hint { color: var(--muted); }
.topbar {
  display: flex; align-items: center; gap: 18px; flex: none;
  min-height: 58px; padding: 9px 14px;
  background: #111926; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; min-width: max-content; font-size: 13px; font-weight: 700; letter-spacing: .075em; }
.brand-mark { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 5px; background: #246591; color: #eef8ff; font-size: 18px; letter-spacing: 0; }
.brand small { font-size: 11px; font-weight: 600; letter-spacing: 0; }
.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; min-width: 0; }
.mode-short { display: none; }
.tool-group { display: flex; align-items: center; gap: 2px; padding: 2px; border: 1px solid var(--line); border-radius: 7px; background: #151f2e; }
.tool-group button { border-color: transparent; background: transparent; min-height: 30px; padding: 5px 10px; }
.tool-group button:hover { background: #2a384b; }
.tool-group button.active { background: #1b527c; border-color: #327db5; }
.layout { display: grid; grid-template-columns: var(--region-width) minmax(0,1fr) var(--inspector-width); flex: 1; min-height: 0; }
#regionSidebar { display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 12px 10px; background: #131d2b; border-right: 1px solid var(--line); }
.region-sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 3px 4px 12px; border-bottom: 1px solid var(--line); }
.region-sidebar-head > div { display: flex; flex-direction: column; gap: 3px; }
.region-sidebar-head strong { font-size: 13px; }
#regionCount { display: grid; place-items: center; min-width: 25px; height: 22px; border-radius: 4px; background: #263648; color: #d6e5f5; font-size: 11px; font-variant-numeric: tabular-nums; }
#addRegion { width: 100%; margin: 12px 0; justify-content: flex-start; }
#regionListHome { flex: 1; min-height: 0; overflow: auto; }
.overview-panel { flex: none; padding: 10px 6px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.overview-panel canvas { display: block; width: 100%; height: auto; max-height: min(29dvh, 245px); object-fit: contain; margin-top: 8px; border: 1px solid #33465b; border-radius: 5px; background: #0e1723; }
.sidebar-hint { margin: 10px 4px 0; padding-top: 10px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; line-height: 1.5; }
#regionEmpty { margin: 10px 4px; font-size: 11px; line-height: 1.5; }
#regionEmpty[hidden] { display: none; }
.stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: #101827; }
#view { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.empty { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); pointer-events: none; text-align: center; color: #b6c5d7; line-height: 1.7; white-space: nowrap; }
.workspace-status {
  display: flex; align-items: center; gap: 16px; flex: none; min-height: 30px; padding: 5px 12px; overflow: hidden;
  background: #09111de8; border-top: 1px solid var(--line);
  color: #bac9db; font-size: 11px; font-variant-numeric: tabular-nums;
}
#selectionDisplay { min-width: 0; max-width: 32%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--warm); }
#modeDisplay, #coords, #zoom { white-space: nowrap; }
#dirtyState { margin-left: auto; white-space: nowrap; }
#coords, #zoom { color: #e6f2ff; }
#dirtyState { color: var(--warm); }
#inspector { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #151e2c; border-left: 1px solid var(--line); }
.inspector-head { display: flex; align-items: center; gap: 10px; flex: none; min-height: 54px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.inspector-head > div { display: flex; flex-direction: column; gap: 2px; }
.eyebrow { font-size: 9px; letter-spacing: .18em; color: #6f8eaa; }
.inspector-head strong { font-size: 13px; letter-spacing: .02em; }
.panel-size { display: flex; align-items: center; gap: 7px; width: 100px; margin-left: auto; color: var(--muted); font-size: 11px; }
.panel-size input { width: 68px; }
.loupe-toggle { display: inline-flex; align-items: center; gap: 5px; color: #d3deeb; font-size: 11px; white-space: nowrap; }
.loupe-toggle input { accent-color: var(--blue); }
.panel-toggle { display: none; }
#panelContent { display: flex; flex-direction: column; min-height: 0; flex: 1; }
#loupeDock { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; flex: none; padding: 8px 16px; border-bottom: 1px solid var(--line); background: #172232; }
#loupeDock[hidden] { display: none; }
#loupeContent { display: flex; align-items: center; gap: 10px; min-width: 0; }
#loupeContent[hidden], #loupe[hidden] { display: none; }
#loupe { display: block; width: 76px; height: 76px; flex: none; border: 1px solid var(--warm); border-radius: 5px; background: #202936; }
#loupeCaption { color: var(--warm); font-size: 11px; overflow-wrap: anywhere; }
.tabs { display: grid; grid-template-columns: repeat(5,minmax(0,1fr)); gap: 2px; flex: none; padding: 6px; background: #111b29; border-bottom: 1px solid var(--line); }
.tabs button { min-width: 0; min-height: 38px; padding: 5px 1px; background: transparent; border-color: transparent; font-size: 11px; }
.tabs button.active { background: #20557e; border-color: #398cc4; }
.panel-scroll { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; }
section { padding: 16px; border-bottom: 1px solid var(--line); }
section:last-child { border-bottom: 0; }
h2 { display: flex; align-items: center; gap: 10px; margin: 0 0 13px; font-size: 14px; font-weight: 650; }
.section-number { color: #78a7ca; font-size: 10px; font-weight: 700; letter-spacing: .08em; }
section p { margin: 8px 0 12px; font-size: 11px; line-height: 1.55; }
.field-group { display: flex; flex-direction: column; align-items: stretch; gap: 7px; margin: 0 0 12px; }
.field-label { color: #aebfd1; font-size: 11px; font-weight: 600; }
#imageInfo { color: #c4d3e2; font-size: 11px; line-height: 1.5; overflow-wrap: anywhere; }
.button-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin: 8px 0 12px; }
.history-row { margin-bottom: 16px; }
#regions { list-style: none; padding: 0; margin: 8px 0; }
#regions li { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin: 0 0 5px; padding: 6px; border: 1px solid #334255; border-radius: 5px; color: #c6d5e6; font-size: 11px; }
#regions li.selected { background: #3b302c; border-color: #d39b60; color: #ffe1b9; }
#regions li::before { content: ""; flex: none; width: 7px; height: 18px; border-radius: 2px; background: #557a9b; }
#regions li.selected::before { background: var(--warm); }
#regions li [role="button"] { min-width: 0; overflow-wrap: anywhere; }
#regions li .actions { display: flex; gap: 3px; flex: none; }
#regions li button { min-height: 30px; padding: 4px 7px; font-size: 10px; }
#vertexEditor { display: flex; flex-direction: column; align-items: stretch; gap: 9px; }
#selectedRegionName { display: block; min-width: 0; overflow: hidden; color: #c9d9ea; font-size: 12px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.vertex-navigation { display: grid; grid-template-columns: 44px minmax(0,1fr) 44px; align-items: center; gap: 6px; }
.vertex-navigation button { min-height: 44px; padding: 0; font-size: 24px; line-height: 1; }
#vertexInfo { display: block; min-width: 0; overflow: hidden; color: var(--warm); font-size: 12px; font-weight: 650; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
.coordinate-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.coordinate-row label { display: flex; flex-direction: column; gap: 5px; color: var(--muted); font-size: 11px; }
.coordinate-row input { width: 100%; }
#vertexCandidates { display: flex; flex-wrap: wrap; gap: 5px; }
#vertexCandidates button { font-size: 11px; }
.checkrow { display: flex; align-items: center; gap: 9px; margin-bottom: 16px; font-size: 12px; }
#status { flex: none; max-height: 68px; overflow: auto; margin: 0; padding: 10px 16px; border-top: 1px solid var(--line); background: #101a28; color: #a8d7f2; font-size: 11px; line-height: 1.5; white-space: pre-wrap; }
#status.warn { color: var(--warm); }
@media (max-width: 1150px) {
  .layout { grid-template-columns: minmax(0,1fr) var(--inspector-width); }
  #regionSidebar { display: none; }
  #mobileRegionListHome { margin-top: 14px; padding-top: 8px; border-top: 1px solid var(--line); }
  #regions { max-height: 230px; overflow: auto; }
  #regionEmpty { margin: 8px 0; }
}
@media (max-width: 780px), (max-width: 900px) and (max-height: 520px) {
  .topbar { gap: 8px; padding: 7px 9px; }
  .brand { font-size: 11px; }
  .brand-mark { width: 24px; height: 24px; font-size: 15px; }
  .toolbar { gap: 5px; }
  button, .filelabel { min-height: 44px; }
  .tool-group button { min-height: 44px; padding: 5px 8px; }
  .inspector-head { min-height: 42px; padding: 6px 10px; }
  .inspector-head .eyebrow { display: none; }
  .panel-size { display: none; }
  .tabs { display: grid; grid-template-columns: repeat(5,minmax(0,1fr)); gap: 2px; flex: none; padding: 6px; background: #111b29; border-bottom: 1px solid var(--line); }
  .tabs button { min-width: 0; min-height: 44px; padding: 5px 1px; background: transparent; border-color: transparent; font-size: 11px; }
  .tabs button.active { background: #20557e; border-color: #398cc4; }
  .panel-scroll section[hidden] { display: none; }
  #loupeDock { padding: 4px 10px; }
  #loupe { width: 44px; height: 44px; }
  #loupeCaption { font-size: 10px; }
  section { padding: 12px; }
  section[data-panel-section="3"] h2 { display: none; }
  section[data-panel-section="3"] { padding: 4px 10px; }
  section[data-panel-section="3"] #vertexEditor { gap: 4px; }
  section[data-panel-section="3"] > .hint { margin-top: 10px; }
  .coordinate-row input { min-height: 44px; }
  #status { padding: 3px 10px; max-height: 48px; }
}
@media (max-width: 780px) {
  .topbar { display: grid; grid-template-columns: minmax(0,1fr) 90px 90px; grid-template-rows: 44px 44px; gap: 4px 6px; padding: 5px 8px; }
  .brand { min-width: 0; overflow: hidden; white-space: nowrap; }
  .brand small { display: none; }
  .toolbar { display: contents; }
  .open-image { grid-column: 2; grid-row: 1; min-width: 88px; }
  .history-top { grid-column: 3; grid-row: 1; }
  .history-top button { min-width: 44px; }
  .toolbar .tool-group { justify-content: space-between; padding: 0; }
  .toolbar .tool-group button { min-width: 44px; }
  .toolbar .tool-group:not(.mode-switch):not(.history-top) { grid-column: 1 / 3; grid-row: 2; justify-self: start; width: max-content; }
  .mode-switch { grid-column: 2 / 4; grid-row: 2; justify-self: end; }
  .mode-long { display: none; }
  .mode-short { display: inline; }
  .layout { display: flex; flex-direction: column; }
  .stage { flex: 1; min-height: 0; }
  #inspector { height: clamp(230px, 34dvh, 300px); min-height: 0; flex: none; border-left: 0; border-top: 1px solid var(--line); }
  #inspector.vertex-panel { height: clamp(250px, 39dvh, 330px); }
  .inspector-head { gap: 8px; }
  .loupe-toggle { margin-left: auto; }
  .panel-toggle { display: inline-flex; min-height: 44px; padding: 3px 10px; font-size: 11px; }
  #inspector.collapsed, #inspector.collapsed.vertex-panel { height: 53px; }
  #inspector.collapsed #panelContent { display: none; }
  .workspace-status { gap: 6px 10px; padding: 5px 8px; font-size: 10px; }
  #selectionDisplay { max-width: 24%; }
  #dirtyState { overflow: hidden; text-overflow: ellipsis; }
  .empty { white-space: normal; width: 90%; }
}
@media (max-width: 900px) and (max-height: 520px) {
  .topbar { display: flex; min-height: 54px; flex-wrap: nowrap; }
  .toolbar { display: flex; flex-wrap: nowrap; }
  .brand small { display: none; }
  .layout { display: grid; grid-template-columns: minmax(0,1fr) 290px; }
  .stage { min-height: 0; }
  #inspector { height: auto; min-height: 0; border-left: 1px solid var(--line); border-top: 0; }
  #inspector.vertex-panel { height: auto; }
  .layout.landscape-panel-collapsed { grid-template-columns: minmax(0,1fr) 54px; }
  #inspector.collapsed { height: auto; }
  #inspector.collapsed #panelContent { display: none; }
  #inspector.collapsed .inspector-head > div, #inspector.collapsed .loupe-toggle { display: none; }
  #inspector.collapsed .inspector-head { justify-content: center; padding: 5px; }
  .panel-toggle { display: inline-flex; min-width: 44px; min-height: 44px; padding: 3px; margin-left: auto; }
  .workspace-status { font-size: 10px; }
}
@media (max-width: 780px) and (max-height: 520px) {
  .brand > span:nth-child(2) { display: none; }
}
@media (max-width: 780px) and (min-height: 521px) and (max-width: 350px) {
  .brand { font-size: 10px; gap: 5px; letter-spacing: .02em; }
  .brand > span:nth-child(2) { display: none; }
  .topbar { gap: 4px; }
  .toolbar .tool-group button { padding-inline: 5px; }
}
