/* ════════════════════════════════
   MS PAINT
   ════════════════════════════════ */
.paint-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}
.paint-toolbox {
  width: 54px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 2px;
  gap: 5px;
  background: var(--c-material);
  border-right: 2px solid var(--c-border-dark);
}
.paint-tools {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
}
.paint-tool {
  width: 24px;
  height: 24px;
  background: var(--c-material);
  border: none;
  box-shadow: var(--shadow-btn);
  padding: 2px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}
.paint-tool svg { width: 14px; height: 14px; }
.paint-tool.active,
.paint-tool:active {
  box-shadow: var(--shadow-btn-active);
}
.paint-tool-options {
  box-shadow: var(--shadow-btn-active);
  padding: 4px 5px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.paint-line-opt {
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  padding: 2px 2px;
  cursor: pointer;
  display: flex;
  align-items: center;
}
.paint-line-opt.active {
  border-color: var(--c-border-dark);
  background: #000080;
}
.paint-line-opt.active .paint-line-preview { background: #fff; }
.paint-line-preview {
  width: 100%;
  background: #000;
  display: block;
}
.paint-canvas-wrap {
  flex: 1;
  overflow: auto;
  background: #808080;
  padding: 10px;
  min-width: 0;
}
.paint-canvas-inner {
  position: relative;
  display: inline-block;
}
.paint-canvas {
  display: block;
  border: 1px solid #808080;
  cursor: crosshair;
  box-shadow: 2px 2px 0 #404040;
}
.paint-canvas-handle {
  position: absolute;
  width: 6px;
  height: 6px;
  background: #000;
  border: 1px solid #fff;
}
.paint-handle-r  { right: -4px; top: 50%; transform: translateY(-50%); cursor: e-resize; }
.paint-handle-b  { bottom: -4px; left: 50%; transform: translateX(-50%); cursor: s-resize; }
.paint-handle-br { bottom: -4px; right: -4px; cursor: se-resize; }
.paint-palette {
  display: flex;
  align-items: center;
  padding: 3px 4px;
  gap: 6px;
  border-top: 2px solid var(--c-border-dark);
  background: var(--c-material);
  flex-shrink: 0;
  height: 38px;
}
.paint-fg-bg {
  position: relative;
  width: 36px;
  height: 30px;
  flex-shrink: 0;
  margin-right: 4px;
}
.paint-color-box {
  position: absolute;
  width: 22px;
  height: 22px;
  border: 2px solid;
}
.paint-fg-color {
  top: 0; left: 0;
  background: #000;
  border-top-color: var(--c-border-lightest);
  border-left-color: var(--c-border-lightest);
  border-bottom-color: var(--c-border-dark);
  border-right-color: var(--c-border-dark);
  z-index: 2;
}
.paint-bg-color {
  bottom: 0; right: 0;
  background: #fff;
  border-top-color: var(--c-border-dark);
  border-left-color: var(--c-border-dark);
  border-bottom-color: var(--c-border-lightest);
  border-right-color: var(--c-border-lightest);
  z-index: 1;
}
.paint-color-grid {
  display: grid;
  grid-template-rows: 14px 14px;
  grid-auto-columns: 14px;
  grid-auto-flow: column;
  gap: 1px;
}
.paint-color-swatch {
  width: 14px;
  height: 14px;
  border: 1px solid var(--c-border-dark);
  cursor: pointer;
  box-sizing: border-box;
}
.paint-color-swatch:hover {
  outline: 1px solid #fff;
  z-index: 1;
  position: relative;
}

/* ── Drawing (js/apps/paint.js) ── */
.paint-app {
  touch-action: manipulation; /* no double-tap zoom on the tool and color boxes */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.paint-canvas {
  box-sizing: content-box; /* the style size is the picture size; the border is extra */
  background: #fff;
  touch-action: none; /* finger drags draw instead of scrolling or zooming */
}
/* Live preview of lines and shapes, on top of the picture */
.paint-overlay {
  box-sizing: content-box;
  position: absolute;
  left: 1px;
  top: 1px;
  pointer-events: none;
}
.paint-tool,
.paint-line-opt,
.paint-color-swatch,
.paint-fg-bg {
  touch-action: manipulation;
}
.paint-fg-bg { cursor: pointer; }
.paint-text-input {
  position: absolute;
  z-index: 2;
  height: 22px;
  padding: 0 1px;
  border: 1px dashed #000080;
  background: transparent;
  font-family: "w95fa", 'MS Sans Serif', Tahoma, sans-serif;
  font-size: 16px;
  line-height: 18px;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}
.paint-hidden-input {
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* Drop-down menus */
.menu-item.paint-menu-open {
  background-color: #000080;
  color: #fff;
}
.paint-menu {
  position: absolute;
  z-index: 20;
  min-width: 160px;
  padding: 3px;
  background: var(--c-material);
  box-shadow: var(--shadow-window-frame);
  overflow-y: auto;
  overscroll-behavior: contain;
  font-family: "w95fa", 'MS Sans Serif', Tahoma, sans-serif;
  font-size: 14px;
}
.paint-menu-item {
  display: flex;
  align-items: center;
  padding: 2px 10px 2px 0;
  white-space: nowrap;
  cursor: pointer;
}
.paint-menu-item:hover {
  background: #000080;
  color: #fff;
}
.paint-menu-item.disabled {
  color: #808080;
  text-shadow: 1px 1px 0 #fff;
  cursor: default;
}
.paint-menu-item.disabled:hover { background: transparent; }
.paint-menu-check {
  width: 20px;
  flex-shrink: 0;
  text-align: center;
}
.paint-menu-label { flex: 1; }
.paint-menu-key { padding-left: 24px; }
.paint-menu-key:empty { padding-left: 0; }
.paint-menu-sep {
  margin: 3px 1px;
  border-top: 1px solid var(--c-border-dark);
  border-bottom: 1px solid var(--c-border-lightest);
}

/* Message box ("not available", About) */
.paint-msg-backdrop {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
}
.paint-msg {
  width: 320px;
  max-width: calc(100% - 16px);
  max-height: calc(100% - 16px);
  overflow: auto;
  padding: 3px;
  background: var(--c-material);
  box-shadow: var(--shadow-window-frame), var(--shadow-window-drop);
  font-family: "w95fa", 'MS Sans Serif', Tahoma, sans-serif;
}
.paint-msg-title {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 22px;
  padding: 1px 2px 1px 5px;
  background: var(--c-header);
  color: #fff;
  font-size: 14px;
}
.paint-msg-title span { flex: 1; }
.paint-msg-title .win-btn { width: 18px; height: 16px; }
.paint-msg-body {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px 14px 14px;
  font-size: 13px;
  line-height: 1.4;
}
.paint-msg-icon { flex-shrink: 0; }
.paint-msg-text { margin: 4px 0 0; }
.paint-msg-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  padding: 0 8px 12px;
}

/* ════════════════════════════════
   PAINT ON PHONES
   Bigger tools and swatches; the picture fills the gray area (paint.js).
   Portrait: 4 rows of 7 colors. Landscape: tools in 4 columns beside the
   line widths, colors in 2 rows, so the canvas keeps its height.
   ════════════════════════════════ */
body.is-phone .paint-menubar { flex-wrap: wrap; }
body.is-phone .paint-menubar .menu-item { padding: 4px 8px; }
@media (max-width: 360px) {
  body.is-phone .paint-menubar .menu-item { padding: 4px 5px; }
}
body.is-phone .paint-toolbox {
  width: auto;
  padding: 3px;
  gap: 6px;
  overflow-x: hidden;
  overflow-y: auto; /* last resort on tiny screens; never shows a scrollbar */
  overscroll-behavior: contain;
  scrollbar-width: none;
}
body.is-phone .paint-toolbox::-webkit-scrollbar { display: none; }
body.is-phone .paint-tools {
  grid-template-columns: repeat(2, 30px);
  gap: 2px;
}
body.is-phone .paint-tool {
  width: 30px;
  height: 30px;
}
body.is-phone .paint-tool svg { width: 18px; height: 18px; }
body.is-phone .paint-tool-options {
  padding: 4px;
  gap: 4px;
  flex-shrink: 0;
}
body.is-phone .paint-line-opt { min-height: 20px; }
body.is-phone .paint-canvas-wrap { padding: 6px; }
body.is-phone .paint-palette {
  height: auto;
  padding: 4px;
  gap: 6px;
}
body.is-phone .paint-fg-bg {
  width: 44px;
  height: 40px;
  margin-right: 0;
}
body.is-phone .paint-color-box { width: 28px; height: 28px; }
body.is-phone .paint-color-grid {
  flex: 1;
  min-width: 0;
  max-width: calc(14 * 28px + 13px);
  grid-template-rows: auto auto;
  grid-auto-columns: minmax(0, 1fr);
}
body.is-phone .paint-color-swatch {
  width: auto;
  height: auto;
  min-height: 16px;
  aspect-ratio: 1 / 1;
}
body.is-phone .paint-menu { font-size: 16px; }
body.is-phone .paint-menu-item { min-height: 36px; }
body.is-phone .paint-msg-title { min-height: 34px; font-size: 16px; }
body.is-phone .paint-msg-title .win-btn { width: 32px; height: 28px; }
body.is-phone .paint-msg-body { font-size: 15px; }
body.is-phone .paint-msg .dialog-btn { min-width: 80px; }

@media (orientation: portrait) {
  body.is-phone .paint-color-grid {
    max-width: calc(7 * 28px + 6px);
    grid-auto-flow: row;
    grid-template-rows: none;
    grid-template-columns: repeat(7, minmax(0, 1fr));
  }
  body.is-phone .paint-color-swatch { order: var(--o4); }
}
@media (orientation: landscape) {
  body.is-phone .paint-toolbox {
    flex-direction: row;
    align-items: flex-start;
  }
  body.is-phone .paint-tools { grid-template-columns: repeat(4, 30px); }
  body.is-phone .paint-tool-options { width: 44px; }
  body.is-phone .paint-color-grid { max-width: calc(14 * 24px + 13px); }
}
@media (orientation: portrait) and (max-height: 700px) {
  body.is-phone .paint-tools { grid-template-columns: repeat(2, 28px); }
  body.is-phone .paint-tool { width: 28px; height: 28px; }
  body.is-phone .paint-line-opt { min-height: 16px; }
}

/* Compact tool box: set by paintFitToolbox() (js/apps/paint.js) when the
   layout above is taller than the window, so nothing is cut off. */
body.is-phone .paint-toolbox-compact .paint-tools { grid-template-columns: repeat(3, 28px); }
body.is-phone .paint-toolbox-compact .paint-tool { width: 28px; height: 28px; }
body.is-phone .paint-toolbox-compact .paint-line-opt { min-height: 16px; }
@media (orientation: portrait) {
  body.is-phone .paint-toolbox-compact .paint-tool-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}
@media (orientation: landscape) {
  body.is-phone .paint-toolbox-compact .paint-tools { grid-template-columns: repeat(6, 28px); }
}
