:root {
  color-scheme: light;
  --bg: #c9c1b2;
  --bar: #8fa7b5;
  --panel: #8fa7b5;
  --panel-light: #b8c5cc;
  --canvas-bg: #6f5b66;
  --cream: #f1ecd8;
  --text: #111;
  --muted: #2d3f49;
  --line: #050505;
  --accent: #b24b6a;
  --radius: 0;
  --pixel-font: "DotGothic16", "MS Gothic", "Yu Gothic UI", "Hiragino Sans", Meiryo, system-ui, sans-serif;
  font-family:
    "MS Gothic", "Yu Gothic UI", "Hiragino Sans", Meiryo, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  min-width: 1120px;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.18) 1px, transparent 1px),
    var(--bg);
  background-size: 16px 16px;
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-rows: 54px minmax(0, 1fr) auto;
}

.topbar,
.editor-toolbar,
.statusbar,
.legal-footer {
  background: var(--bar);
  border-bottom: 2px solid var(--line);
  box-shadow: inset 0 1px 0 #e7edf0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 7px 10px;
}

.topbar h1 {
  margin: 0;
  font-size: 1.18rem;
  font-weight: 900;
  letter-spacing: 1px;
  text-shadow:
    1px 0 0 #000,
    0 1px 0 #000,
    2px 2px 0 #f1ecd8;
}

.topbar p {
  margin: 1px 0 0;
  color: #263943;
  font-size: 0.74rem;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 292px minmax(790px, 1fr);
  gap: 6px;
  padding: 6px;
}

.panel,
.editor-area,
.right-panel {
  min-height: 0;
  border: 2px solid var(--line);
  background: var(--panel);
}

.controls-panel,
.right-panel {
  overflow: hidden;
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 6px;
}

.controls-panel {
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}

.editor-area {
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.upload-zone,
.control-section {
  border: 2px solid var(--line);
  background: var(--panel-light);
  box-shadow: inset 1px 1px 0 #eef4f6, inset -1px -1px 0 #60737d;
}

.upload-zone {
  position: relative;
}

.upload-zone.drag-over {
  outline: 2px dashed #fff;
  outline-offset: -6px;
  background-color: #d5e2e8;
}

.canvas-stage.drag-over {
  outline: 2px dashed #fff;
  outline-offset: -6px;
  background-color: #1f63d4;
}

.upload-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-zone label {
  min-height: 58px;
  display: grid;
  grid-template-columns: 30px 1fr;
  grid-template-areas:
    "icon title"
    "icon meta";
  align-items: center;
  gap: 1px 8px;
  padding: 8px;
  cursor: pointer;
}

.upload-icon {
  grid-area: icon;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 2px solid var(--line);
  background: var(--cream);
  font-weight: 900;
}

.upload-title {
  grid-area: title;
  font-weight: 900;
}

.upload-meta {
  grid-area: meta;
  color: var(--muted);
  font-size: 0.72rem;
}

.control-section {
  padding: 7px;
}

.control-section.first {
  padding-top: 7px;
}

.section-title {
  margin-bottom: 6px;
  color: #111;
  font-size: 0.72rem;
  font-weight: 900;
}

.help-text {
  margin: -2px 0 6px;
  color: #263943;
  font-size: 0.72rem;
  line-height: 1.35;
}

.topbar-actions,
.toolbar-controls,
.tool-group,
.history-actions {
  display: flex;
  align-items: center;
  gap: 5px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 3px;
  padding: 3px;
  border: 2px solid var(--line);
  background: #d3d0c6;
}

.segmented button,
.tool-choice,
.tool-button,
.secondary-button,
.danger-button,
.primary-button {
  min-height: 28px;
  border: 2px solid var(--line);
  border-radius: 0;
  background: #d7d4ca;
  color: #111;
  font-weight: 900;
  box-shadow: inset 1px 1px 0 #fff, inset -2px -2px 0 #77736b;
}

.segmented button {
  min-width: 0;
  padding: 0 4px;
  font-size: 0.78rem;
}

.tool-choice {
  min-width: 0;
  padding: 0 8px;
  font-size: 0.8rem;
}

.segmented button.active,
.tool-choice.active {
  background: var(--cream);
  box-shadow: inset -1px -1px 0 #fff, inset 2px 2px 0 #7d7770;
}

.primary-button {
  min-width: 116px;
  padding: 0 14px;
  background: var(--cream);
}

.save-button {
  min-height: 36px;
  font-size: 0.95rem;
}

.secondary-button,
.danger-button {
  padding: 0 10px;
}

.secondary-button.full,
.danger-button.full {
  width: 100%;
  margin-top: 6px;
}

.danger-button {
  background: #d8bdc4;
}

.tool-button {
  width: 30px;
  display: grid;
  place-items: center;
  font-size: 0.95rem;
}

.field-grid {
  display: grid;
  gap: 6px;
  margin-top: 6px;
}

.field-grid.two {
  grid-template-columns: 1fr 1fr;
}

.field-grid label,
.range-row,
.check-row,
.zoom-control,
.dialog-field {
  color: #1a252c;
  font-size: 0.74rem;
}

.field-grid label {
  display: grid;
  gap: 3px;
}

.field-grid input[type="number"],
.select-input,
.hex-input,
.color-numbers input {
  width: 100%;
  height: 27px;
  padding: 0 6px;
  border: 2px solid var(--line);
  border-radius: 0;
  background: var(--cream);
  color: #111;
  outline-color: var(--accent);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  margin-top: 4px;
}

.check-row.compact {
  margin: 0;
  white-space: nowrap;
}

input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
}

.range-row,
.zoom-control {
  display: grid;
  grid-template-columns: minmax(58px, auto) 1fr minmax(32px, auto);
  align-items: center;
  gap: 6px;
  min-height: 28px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

output {
  color: #111;
  font-weight: 900;
  text-align: right;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px;
}

.toolbar-controls {
  min-width: 360px;
  justify-content: flex-end;
}

.zoom-control {
  width: 190px;
}

.paint-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(390px, 1fr) 360px;
}

.canvas-column {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) minmax(66px, auto);
  background: var(--canvas-bg);
}

.canvas-stage {
  position: relative;
  min-height: 0;
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--canvas-bg);
  scroll-behavior: auto;
  scrollbar-color: #d7d4ca #6b7f8b;
  scrollbar-width: thin;
}

.notice-slot {
  display: grid;
  place-items: center;
  min-height: 66px;
  padding: 6px 10px;
  border-top: 2px solid var(--line);
  background: #b8c5cc;
}

.mobile-draw-controls {
  display: none;
}

.notice-frame {
  width: min(728px, 100%);
  height: clamp(50px, 8vw, 90px);
  min-height: 50px;
  max-height: 90px;
  display: grid;
  place-items: center;
  gap: 2px;
  border: 2px solid var(--line);
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.42) 1px, transparent 1px),
    linear-gradient(rgba(0, 0, 0, 0.08) 1px, transparent 1px),
    #f1ecd8;
  background-size: 12px 12px;
  color: #263943;
  box-shadow: inset 1px 1px 0 #fff, inset -2px -2px 0 #77736b;
  text-align: center;
}

.banner-code-target {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  gap: 2px;
}

.banner-code-target iframe,
.banner-code-target ins {
  max-width: 100%;
}

.notice-frame span {
  color: #111;
  font-size: 0.9rem;
  font-weight: 900;
}

.notice-frame small {
  font-size: 0.68rem;
}

.canvas-stage::-webkit-scrollbar {
  width: 13px;
  height: 13px;
}

.canvas-stage::-webkit-scrollbar-track {
  background: #6b7f8b;
  border: 1px solid var(--line);
}

.canvas-stage::-webkit-scrollbar-thumb {
  background: #d7d4ca;
  border: 2px solid var(--line);
}

.canvas-stage.drag-over::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  background: rgba(24, 86, 206, 0.82);
}

.canvas-stage.drag-over::after {
  content: "画像を読み込む";
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 21;
  transform: translate(-50%, -50%);
  padding: 14px 22px;
  border: 2px solid var(--line);
  background: var(--cream);
  color: #111;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.35);
  font-size: 1.1rem;
  font-weight: 900;
  pointer-events: none;
  white-space: nowrap;
}

.canvas-stage.panning {
  cursor: grabbing;
  user-select: none;
}

body.is-panning,
body.is-panning * {
  cursor: grabbing !important;
  user-select: none;
}

.canvas-frame {
  position: relative;
  width: 640px;
  height: 640px;
  border: 2px solid var(--line);
  background: transparent;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.35);
  will-change: width, height;
}

.ruler-preview {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  image-rendering: pixelated;
  background: transparent;
}

.brush-cursor {
  position: absolute;
  z-index: 4;
  pointer-events: none;
  border: 2px solid var(--cursor-color, #f1ecd8);
  box-shadow:
    0 0 0 1px #050505,
    inset 0 0 0 1px #050505;
  background: rgba(255, 255, 255, 0.08);
  mix-blend-mode: normal;
  transform: translate3d(var(--cursor-x, 0px), var(--cursor-y, 0px), 0);
  will-change: transform, width, height;
  contain: layout paint style;
}

.mobile-cursor-label {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  display: block;
  min-width: 74px;
  padding: 3px 5px;
  border: 2px solid #050505;
  background: #fff8d8;
  color: #050505;
  box-shadow:
    inset 1px 1px 0 #fff,
    inset -2px -2px 0 #8e897e,
    3px 3px 0 rgba(0, 0, 0, 0.28);
  font-family: "MS Gothic", "Yu Gothic UI", Meiryo, monospace;
  font-size: 0.68rem;
  font-weight: 900;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
}

.mobile-cursor-label[hidden] {
  display: none;
}

#editorCanvas,
#originalCanvas {
  image-rendering: pixelated;
  background-color: transparent;
}

#editorCanvas {
  display: block;
  cursor: url("./assets/cursor.png") 0 0, crosshair;
  touch-action: none;
  will-change: width, height;
}

.grid-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  image-rendering: pixelated;
  background: transparent;
}

.canvas-stage:not(.grid-on) .grid-overlay {
  display: none;
}

.drag-hint {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  max-width: min(440px, calc(100% - 28px));
  padding: 6px 9px;
  border: 2px solid var(--line);
  background: var(--cream);
  color: #111;
  font-size: 0.76rem;
}

.right-panel {
  overflow: hidden;
}

.paint-color-ui {
  display: grid;
  grid-template-columns: 178px 1fr;
  gap: 7px;
  padding: 8px;
  border: 2px solid var(--line);
  background: var(--canvas-bg);
}

.picker-board {
  display: grid;
  grid-template-columns: 1fr 22px;
  gap: 6px;
  grid-row: 1 / span 4;
}

#svCanvas,
#hueCanvas {
  width: 100%;
  height: 126px;
  border: 2px solid var(--line);
  image-rendering: auto;
  cursor: crosshair;
}

#hueCanvas {
  cursor: ns-resize;
}

.color-preview-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.color-preview {
  height: 25px;
  border: 2px solid var(--line);
  background: #000;
}

.native-color {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.color-numbers {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.color-numbers label,
.hex-line {
  display: grid;
  gap: 2px;
  color: var(--cream);
  font-size: 0.66rem;
  font-weight: 900;
}

.color-numbers input {
  height: 23px;
  padding: 0 4px;
  font-size: 0.72rem;
}

.hex-line {
  grid-template-columns: 40px 1fr;
  align-items: center;
}

.hex-input {
  height: 24px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.82rem;
  text-transform: uppercase;
}

.swatches {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 4px;
}

.overview-section {
  align-self: end;
  display: grid;
  grid-template-rows: auto auto;
  justify-items: center;
  min-height: 184px;
}

#overviewCanvas {
  display: block;
  width: min(100%, 168px);
  height: auto;
  aspect-ratio: 1;
  border: 2px solid var(--line);
  background: var(--canvas-bg);
  image-rendering: pixelated;
}

.swatch {
  aspect-ratio: 1;
  min-width: 0;
  border: 2px solid var(--line);
  border-radius: 0;
}

#originalCanvas {
  width: 100%;
  height: auto;
  margin-top: 6px;
  border: 2px solid var(--line);
}

#originalCanvas.hidden {
  display: none;
}

.statusbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: center;
  gap: 8px 14px;
  padding: 6px 8px;
  border-top: 2px solid var(--line);
  border-bottom: 0;
  color: #111;
  font-size: 0.72rem;
}

.legal-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 14px;
  padding: 7px 10px;
  border-top: 2px solid var(--line);
  border-bottom: 0;
  font-size: 0.72rem;
}

.language-switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #111;
  font-weight: 900;
}

.language-switch .select-input {
  width: auto;
  min-width: 104px;
  height: 24px;
  padding: 0 22px 0 6px;
  font-size: 0.72rem;
}

.status-info,
.footer-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.coordinate-status {
  min-width: 76px;
  padding: 2px 6px;
  border: 2px solid var(--line);
  background: var(--cream);
  color: #111;
  font-weight: 900;
  line-height: 1.2;
  box-shadow: inset 1px 1px 0 #fff, inset -1px -1px 0 #77736b;
}

.footer-links a,
.info-document a {
  color: #111;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.footer-links a:visited,
.info-document a:visited {
  color: #263943;
}

.save-dialog {
  width: min(420px, calc(100vw - 28px));
  padding: 0;
  border: 2px solid var(--line);
  border-radius: 0;
  background: var(--panel-light);
  color: #111;
}

.save-dialog::backdrop {
  background: rgba(0, 0, 0, 0.35);
}

.mobile-start-dialog {
  width: min(430px, calc(100vw - 24px));
  padding: 0;
  border: 2px solid var(--line);
  border-radius: 0;
  background: var(--panel-light);
  color: #111;
  box-shadow:
    0 0 0 2px #d7d4ca,
    6px 6px 0 rgba(0, 0, 0, 0.28),
    inset 1px 1px 0 #eef4f6,
    inset -2px -2px 0 #60737d;
}

.mobile-start-dialog::backdrop {
  background: rgba(8, 13, 18, 0.72);
}

.save-dialog form {
  display: grid;
  gap: 12px;
  padding: 12px;
}

.mobile-start-dialog form {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.mobile-start-upload {
  position: relative;
}

.mobile-start-upload input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.mobile-start-upload label {
  min-height: 112px;
  display: grid;
  place-items: center;
  gap: 6px;
  padding: 12px;
  border: 2px solid var(--line);
  background: var(--cream);
  box-shadow: inset 2px 2px 0 #fff, inset -3px -3px 0 #77736b;
  text-align: center;
}

.mobile-start-upload strong {
  font-size: 1.08rem;
}

.mobile-start-upload span {
  color: #263943;
  font-size: 0.76rem;
}

.mobile-start-upload small {
  color: #263943;
  font-size: 0.68rem;
  font-weight: 900;
  line-height: 1.35;
}

.dialog-head,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.dialog-actions .secondary-button,
.dialog-actions .primary-button {
  flex: 1;
}

.dialog-head strong {
  font-size: 1rem;
}

.dialog-field {
  display: grid;
  gap: 5px;
  font-weight: 900;
}

.dialog-note {
  margin: 0;
  color: #263943;
  font-size: 0.78rem;
  line-height: 1.5;
}

.info-dialog {
  width: min(780px, calc(100vw - 36px));
  height: min(640px, calc(100vh - 36px));
  padding: 0;
  border: 2px solid var(--line);
  border-radius: 0;
  background: var(--panel);
  color: #111;
  box-shadow:
    0 0 0 2px #d7d4ca,
    8px 8px 0 rgba(0, 0, 0, 0.35),
    inset 1px 1px 0 #fff,
    inset -2px -2px 0 #60737d;
}

.info-dialog::backdrop {
  background: rgba(0, 0, 0, 0.28);
}

.info-window {
  height: 100%;
  display: grid;
  grid-template-rows: 34px minmax(0, 1fr);
  border: 3px solid #c8d6dd;
}

.info-window-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 6px 4px 9px;
  border-bottom: 2px solid var(--line);
  background: linear-gradient(90deg, #0b2f7f 0%, #1856b8 58%, #83a9d8 100%);
  color: #fff;
  box-shadow: inset 1px 1px 0 #d9edf7, inset -1px -1px 0 #08225e;
}

.info-window-head strong {
  min-width: 0;
  overflow: hidden;
  font-size: 0.86rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#infoFrame {
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--bg);
  overflow: auto;
}

.info-html,
.info-html body {
  width: 100%;
  height: auto;
  min-height: 100%;
  overflow: auto;
}

body.info-page {
  min-width: 0;
  height: auto;
  min-height: 100%;
  overflow: auto;
}

.info-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding-bottom: 1px;
}

.info-header,
.info-footer {
  background: var(--bar);
  border-bottom: 2px solid var(--line);
  box-shadow: inset 0 1px 0 #e7edf0;
}

.info-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 10px 14px;
}

.info-header h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 900;
}

.info-main {
  width: min(880px, calc(100% - 24px));
  margin: 16px auto;
  border: 2px solid var(--line);
  background: var(--panel-light);
  box-shadow: inset 1px 1px 0 #eef4f6, inset -1px -1px 0 #60737d;
}

.info-document {
  padding: 18px;
  background: rgba(241, 236, 216, 0.64);
}

.info-document h2 {
  margin: 0 0 14px;
  font-size: 1.15rem;
}

.info-document h3 {
  margin: 18px 0 8px;
  font-size: 0.95rem;
}

.info-document p,
.info-document li {
  color: #1a252c;
  font-size: 0.86rem;
  line-height: 1.75;
}

.info-document ul {
  margin: 8px 0 0;
  padding-left: 1.3rem;
}

.info-note {
  margin-top: 14px;
  padding: 10px;
  border: 2px solid var(--line);
  background: var(--cream);
}

.info-footer {
  padding: 8px 14px;
  border-top: 2px solid var(--line);
  border-bottom: 0;
  font-size: 0.72rem;
}

@media (max-width: 820px) {
  html,
  body {
    height: auto;
    min-height: 100%;
    overflow: auto;
  }

  body {
    min-width: 0;
    font-family: var(--pixel-font);
  }

  button,
  input,
  select,
  textarea {
    font-family: var(--pixel-font);
  }

  .app-shell {
    height: auto;
    min-height: 100svh;
    grid-template-rows: auto auto auto;
  }

  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    flex-wrap: nowrap;
    position: sticky;
    top: 0;
    z-index: 60;
    min-height: 88px;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 10px 10px;
    border-bottom-width: 3px;
    box-shadow:
      inset 0 1px 0 #e7edf0,
      0 3px 0 rgba(0, 0, 0, 0.18);
  }

  .topbar > div:first-child {
    min-width: 0;
    overflow: hidden;
  }

  .topbar h1 {
    font-size: clamp(1rem, 5vw, 1.2rem);
    line-height: 1.1;
    overflow: visible;
    text-wrap: balance;
  }

  .topbar p {
    margin-top: 5px;
    max-width: 100%;
    overflow: hidden;
    color: #17242d;
    font-size: clamp(0.64rem, 3.15vw, 0.76rem);
    line-height: 1.35;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .topbar-actions {
    align-self: center;
    justify-self: end;
    flex: none;
  }

  .topbar .save-button {
    min-width: 74px;
    min-height: 42px;
    padding: 0 10px;
    font-size: 0.84rem;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr);
    gap: 5px;
    padding: 5px;
  }

  .editor-area {
    order: -1;
    overflow: visible;
  }

  .controls-panel,
  .right-panel {
    overflow: visible;
  }

  .editor-toolbar,
  .toolbar-controls,
  .tool-group {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .editor-toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: stretch;
    gap: 6px;
    position: sticky;
    top: calc(88px + env(safe-area-inset-top, 0px));
    z-index: 50;
    border-top: 0;
    box-shadow:
      inset 0 1px 0 #e7edf0,
      0 3px 0 rgba(0, 0, 0, 0.18);
  }

  .tool-group {
    display: grid;
    width: 100%;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 5px;
  }

  .tool-choice {
    width: 100%;
    min-height: 38px;
    height: 38px;
    padding: 0;
    display: grid;
    place-items: center;
    font-size: 0;
    line-height: 1;
    white-space: nowrap;
  }

  .tool-choice[data-tool="gradient"] {
    display: none;
  }

  .desktop-only-tool {
    display: none;
  }

  .tool-choice::before {
    content: attr(data-mobile-label);
    font-size: clamp(0.72rem, 2.2vw, 0.96rem);
    font-weight: 900;
    line-height: 1;
    transform: translateY(1px);
  }

  .toolbar-controls {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 7px;
    min-width: 0;
    width: 100%;
  }

  .zoom-control {
    width: 100%;
    min-width: 0;
  }

  .history-actions {
    flex-wrap: nowrap;
  }

  .paint-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .canvas-column {
    grid-template-rows: minmax(340px, 62svh) auto auto;
  }

  .canvas-stage {
    min-height: 340px;
    max-height: 72svh;
    padding: 14px;
    touch-action: none;
    overscroll-behavior: contain;
  }

  .canvas-frame,
  #editorCanvas {
    touch-action: none;
  }

  #editorCanvas {
    cursor: none;
  }

  .brush-cursor {
    z-index: 4;
    border: 3px solid var(--cursor-color, #050505);
    background: transparent;
    box-shadow: 0 0 0 1px #050505;
    mix-blend-mode: normal;
    will-change: transform, width, height;
    transform: translate3d(var(--cursor-x, 0px), var(--cursor-y, 0px), 0);
    contain: layout paint style;
  }

  .brush-cursor::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    width: 32px;
    height: 32px;
    background-image: url("./assets/cursor.png");
    background-repeat: no-repeat;
    background-size: 32px 32px;
    image-rendering: pixelated;
    transform: translate(-1px, -1px);
  }

  .brush-cursor::after {
    content: none;
  }

  .mobile-cursor-label {
    display: block;
    min-width: 74px;
    padding: 3px 5px;
    border: 2px solid #050505;
    background: #fff8d8;
    color: #050505;
    box-shadow:
      inset 1px 1px 0 #fff,
      inset -2px -2px 0 #8e897e,
      3px 3px 0 rgba(0, 0, 0, 0.28);
    font-family: "MS Gothic", "Yu Gothic UI", Meiryo, monospace;
    font-size: 0.68rem;
    font-weight: 900;
    line-height: 1;
    text-align: center;
    white-space: nowrap;
  }

  .mobile-draw-controls {
    position: sticky;
    bottom: 0;
    z-index: 12;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 6px;
    align-items: center;
    justify-items: center;
    padding: 9px 10px calc(9px + env(safe-area-inset-bottom, 0px));
    border-top: 2px solid var(--line);
    background: var(--bar);
    box-shadow: inset 0 1px 0 #e7edf0;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }

  .push-button {
    width: min(100%, 760px);
    min-height: 64px;
    border: 2px solid var(--line);
    border-radius: 0;
    background: var(--cream);
    color: #111;
    font-size: 1.22rem;
    font-weight: 900;
    box-shadow: inset 2px 2px 0 #fff, inset -3px -3px 0 #77736b;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
  }

  .push-button.active {
    background: #f0c84b;
    box-shadow: inset -1px -1px 0 #fff, inset 3px 3px 0 #7d7770;
    transform: translate(1px, 1px);
  }

  .mobile-draw-controls strong,
  .mobile-draw-controls span {
    display: block;
  }

  .mobile-draw-controls strong {
    text-align: center;
    font-size: 0.78rem;
  }

  .mobile-draw-controls span {
    color: #263943;
    text-align: center;
    font-size: 0.68rem;
    line-height: 1.35;
  }

  .mobile-start-dialog {
    display: block;
  }

  .mobile-start-dialog:not([open]) {
    display: none;
  }

  .mobile-start-presets button {
    min-height: 36px;
    font-size: 0.95rem;
  }

  .overview-section {
    min-height: 236px;
  }

  #overviewCanvas {
    width: min(100%, 220px);
  }

  .right-panel {
    display: grid;
    gap: 5px;
  }

  .paint-color-ui {
    grid-template-columns: 1fr;
  }

  .picker-board {
    grid-row: auto;
  }

  .statusbar {
    align-items: flex-start;
  }

  .legal-footer {
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  }

  .footer-links {
    justify-content: center;
    gap: 6px 10px;
  }

  .info-dialog {
    width: min(94vw, 780px);
    height: min(78svh, 640px);
  }
}

@media (pointer: coarse) and (min-width: 821px) and (max-width: 1366px) {
  body {
    min-width: 1000px;
    font-family: var(--pixel-font);
  }

  button,
  input,
  select,
  textarea {
    font-family: var(--pixel-font);
  }

  .app-shell {
    grid-template-rows: 60px minmax(0, 1fr) auto;
  }

  .topbar {
    min-height: 60px;
    padding: 8px 10px;
  }

  .topbar h1 {
    font-size: 1.28rem;
    line-height: 1.05;
  }

  .topbar p {
    max-width: 620px;
    font-size: 0.78rem;
    line-height: 1.25;
  }

  .workspace {
    grid-template-columns: 258px minmax(0, 1fr);
    gap: 6px;
    padding: 6px;
  }

  .paint-layout {
    grid-template-columns: minmax(0, 1fr) 318px;
  }

  .editor-toolbar {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 6px;
  }

  .tool-group {
    flex-wrap: wrap;
    gap: 5px;
  }

  .tool-choice {
    min-height: 30px;
    padding: 0 7px;
    font-size: 0.74rem;
    line-height: 1;
  }

  .desktop-only-tool {
    display: none;
  }

  .toolbar-controls {
    min-width: 0;
    flex: 1 1 360px;
  }

  .zoom-control {
    width: 170px;
  }

  .canvas-column {
    grid-template-rows: minmax(0, 1fr) auto minmax(66px, auto);
  }

  .canvas-stage {
    padding: 14px;
    touch-action: none;
    overscroll-behavior: contain;
  }

  .canvas-frame,
  #editorCanvas {
    touch-action: none;
  }

  #editorCanvas {
    cursor: none;
  }

  .mobile-draw-controls {
    display: grid;
    grid-template-columns: minmax(220px, 360px) minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    padding: 9px 10px;
    border-top: 2px solid var(--line);
    background: var(--bar);
    box-shadow: inset 0 1px 0 #e7edf0;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }

  .push-button {
    width: 100%;
    min-height: 58px;
    border: 2px solid var(--line);
    border-radius: 0;
    background: var(--cream);
    color: #111;
    font-size: 1.2rem;
    font-weight: 900;
    box-shadow: inset 2px 2px 0 #fff, inset -3px -3px 0 #77736b;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
  }

  .push-button.active {
    background: #f0c84b;
    box-shadow: inset -1px -1px 0 #fff, inset 3px 3px 0 #7d7770;
    transform: translate(1px, 1px);
  }

  .mobile-draw-controls strong,
  .mobile-draw-controls span {
    display: block;
  }

  .mobile-draw-controls strong {
    font-size: 0.84rem;
  }

  .mobile-draw-controls span {
    color: #263943;
    font-size: 0.72rem;
    line-height: 1.35;
  }
}

@media (max-height: 760px) {
  .app-shell {
    grid-template-rows: 48px minmax(0, 1fr) auto;
  }

  .workspace {
    padding: 4px;
    gap: 4px;
  }

  .controls-panel,
  .right-panel {
    padding: 5px;
    gap: 4px;
  }

  .control-section {
    padding: 5px;
  }

  .upload-zone label {
    min-height: 48px;
  }

  #svCanvas,
  #hueCanvas {
    height: 108px;
  }

  .overview-section {
    min-height: 146px;
  }

  #overviewCanvas {
    width: min(100%, 130px);
  }

  .notice-slot {
    min-height: 58px;
    padding: 4px 8px;
  }

  .notice-frame {
    height: 50px;
  }
}

@media (max-width: 820px) and (max-height: 760px) {
  .overview-section {
    min-height: 220px;
  }

  #overviewCanvas {
    width: min(100%, 204px);
  }
}

@media (pointer: coarse) and (min-width: 821px) and (max-width: 1366px) and (max-height: 760px) {
  .app-shell {
    grid-template-rows: 60px minmax(0, 1fr) auto;
  }

  .topbar {
    min-height: 60px;
    padding: 8px 10px;
  }

  .workspace {
    padding: 6px;
    gap: 6px;
  }

  .overview-section {
    min-height: 146px;
  }

  #overviewCanvas {
    width: min(100%, 130px);
  }
}
