:root {
  color-scheme: dark;
  --bg: #101218; --panel: #1c202a; --border: #414a5a; --ink: #f3f5fa;
  --muted: #bcc5d5; --accent: #aee66b; --focus: #bba4ff;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: #b9d8ff; text-underline-offset: .2em; }
button, input, select { font: inherit; }
button, select, input[type=color], input[type=range] { cursor: pointer; }
button { color: inherit; }
button:disabled { opacity: .45; cursor: not-allowed; }
button, a, input, select, summary { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
[hidden] { display: none !important; }
.icon { width: 1.1rem; height: 1.1rem; flex: 0 0 auto; fill: currentColor; pointer-events: none; }
.skip-link { position: absolute; left: 12px; top: -70px; background: white; color: #111; padding: 10px; z-index: 100; }
.skip-link:focus { top: 8px; }
.site-header { display: flex; align-items: center; gap: 20px; max-width: 1500px; margin: auto; padding: 22px 24px; }
.home-link { display: inline-flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; text-decoration: none; }
.heading { flex: 1; }
h1 { font-size: clamp(1.35rem, 3vw, 1.9rem); line-height: 1.2; margin: 0; }
.heading p { margin: 6px 0 0; color: var(--muted); font-size: .9rem; }
main { max-width: 1500px; padding: 0 24px 32px; margin: auto; }
.editor { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; padding: 12px; border-bottom: 1px solid var(--border); }
.tool-group { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.actions { margin-left: auto; }
.tw-btn, .tw-btn-icon, .pill, .tool-handle {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 44px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px;
  color: var(--ink); background: #272e3a; line-height: 1.2; font-size: .85rem;
}
.tw-btn:hover, .tw-btn-icon:hover, .pill:hover, .tool-handle:hover { background: #353e4d; }
#tools .active, .pill.active { background: #3a3152; border-color: #bba4ff; box-shadow: inset 0 0 0 1px #bba4ff; }
#tools [data-tool=marker].active { background: #19454c; border-color: #72dce9; box-shadow: inset 0 0 0 1px #72dce9; }
#tools [data-tool=eraser].active { background: #502d38; border-color: #f7a5bd; box-shadow: inset 0 0 0 1px #f7a5bd; }
#tools [data-tool=hand].active { background: #4b3e25; border-color: #edc879; box-shadow: inset 0 0 0 1px #edc879; }
#save { background: #aee66b; color: #14200d; border-color: #aee66b; font-weight: 700; }
#save:hover { background: #c4f48e; }
.color-control { display: inline-flex; align-items: center; gap: 7px; font-size: .85rem; }
.swatch { display: none; }
input[type=color] { width: 42px; height: 44px; padding: 3px; border: 1px solid var(--border); border-radius: 7px; background: #272e3a; }
input[type=range] { width: 100%; min-width: 0; margin: 4px 0; accent-color: #bba4ff; min-height: 32px; }
input[type=checkbox] { accent-color: #bba4ff; width: 18px; height: 18px; }
input[type=file], select { width: 100%; min-width: 0; padding: 9px; border: 1px solid #65718a; border-radius: 7px; background: #272e3a; color: var(--ink); }
.viewbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 12px; }
.viewbar p { margin: 0; font-size: .8rem; color: var(--muted); }
.view-controls { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.view-controls .tw-btn { min-height: 36px; padding: 7px 10px; }
#zoomLevel { font-variant-numeric: tabular-nums; min-width: 3.4em; text-align: center; font-size: .85rem; }
.canvas-wrap { position: relative; height: clamp(360px, 68svh, 800px); overflow: hidden; background: #14151a; }
#stage { position: absolute; inset: 0; }
#stage canvas { display: block; width: 100% !important; height: 100% !important; touch-action: none; }
#stage.hand-tool canvas { cursor: grab; }
#stage canvas.grabbing { cursor: grabbing; }
#loadStatus { text-align: center; padding: 60px 20px; }
.has-canvas #loadStatus { display: none; }
.tool-handle { position: absolute; top: 12px; right: 12px; z-index: 3; box-shadow: 0 3px 10px #0008; }
.toolpanel { position: absolute; top: 64px; right: 12px; z-index: 2; width: min(300px, calc(100% - 24px)); max-height: calc(100% - 76px); overflow: auto; background: #171b24f5; border: 1px solid var(--border); border-radius: 10px; padding: 16px; visibility: hidden; }
.toolpanel.open { visibility: visible; }
.toolpanel h2 { font-size: .95rem; margin: 0 0 12px; }
.tw-panel { display: grid; min-width: 0; gap: 12px; padding: 14px; border: 1px solid var(--border); border-radius: 9px; background: #202631; margin: 12px 0; }
.tw-panel h3 { font-size: .9rem; margin: 0; }
.size-pills { display: flex; gap: 10px; }
.pill { min-width: 48px; flex: 1; }
.check-label { display: flex; align-items: center; gap: 9px; font-size: .9rem; }
.field { display: grid; min-width: 0; gap: 6px; }
.field label { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; font-size: .9rem; }
.field output { font-variant-numeric: tabular-nums; color: #d2c5ff; }
.color-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.statusbar { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 20px; padding: 12px 3px; min-height: 48px; font-size: .8rem; color: var(--muted); }
.statusbar p { margin: 0; }
.statusbar span { margin-left: auto; }
#actionStatus:empty { display: none; }
.page-info { max-width: 900px; margin: 28px auto; color: var(--muted); }
.page-info h2 { font-size: 1.3rem; color: var(--ink); }
.page-info details { border-top: 1px solid var(--border); padding: 14px 0; }
.page-info summary { color: var(--ink); cursor: pointer; font-weight: 600; }
.page-info li { margin-bottom: 8px; }
.related { margin-top: 24px; }
.modal { width: min(580px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0; border: 1px solid #65718a; border-radius: 12px; color: var(--ink); background: #171c26; overflow: auto; box-shadow: 0 20px 80px #0009; }
.modal::backdrop { background: #000b; }
.modal-header, .modal-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; background: #171c26; }
.modal-header { position: sticky; top: 0; border-bottom: 1px solid var(--border); z-index: 1; }
.modal-header h2 { margin: 0; font-size: 1.1rem; }
.modal-body { padding: 18px; }
.modal-body p { font-size: .9rem; }
.modal-footer { border-top: 1px solid var(--border); justify-content: flex-end; }
.hint, #uploadStatus { color: var(--muted); font-size: .8rem; margin: 0; }
@media (max-width: 700px) {
  .site-header { padding: 16px 12px; gap: 12px; align-items: flex-start; }
  .home-link { padding: 8px; font-size: .8rem; }
  .heading p { font-size: .8rem; }
  main { padding: 0 10px 24px; }
  .toolbar { gap: 8px; padding: 8px; }
  #tools { flex: 1; flex-wrap: nowrap; }
  #tools button { flex: 1; flex-direction: column; gap: 4px; padding: 7px 8px; font-size: .75rem; min-height: 56px; }
  .color-control { gap: 4px; font-size: .75rem; flex-direction: column; }
  .color-control input { width: 38px; height: 34px; }
  .color-control span:not(.swatch) { max-width: 70px; }
  .actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); width: 100%; margin: 0; }
  .actions .tw-btn { padding: 8px 5px; font-size: .75rem; gap: 5px; }
  #save { grid-column: span 2; }
  .viewbar { flex-direction: column; align-items: stretch; padding: 8px; gap: 8px; }
  .view-controls { justify-content: center; }
  .canvas-wrap { height: clamp(340px, 58svh, 650px); }
  .toolpanel { top: auto; bottom: 10px; max-height: calc(100% - 76px); }
  .statusbar { gap: 4px 12px; }
  .statusbar span { margin-left: 0; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; } }
