/* ==========================================================================
   EasyDraw · 快乐小画家
   A friendly, open-source drawing app for kids on tablets.
   ========================================================================== */

:root {
  --bg: #FFF6EC;            /* 奶油底色 */
  --paper: #FFFFFF;
  --ink: #4A3B32;
  --muted: #A08B7A;
  --accent: #FF8A5C;
  --danger: #F25555;
  --shadow: 0 3px 10px rgba(94, 62, 40, 0.13);
  --shadow-lg: 0 8px 22px rgba(94, 62, 40, 0.18);
  --tool-size: 62px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Icon symbols are outline drawings; the logo symbol keeps its own fills */
svg:not(.brand-logo) {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;   /* iOS 长按呼出菜单：画画应用要的是落笔，不是复制 */
  touch-action: manipulation;
}

/* ---------- 整体布局：横屏（平板主力形态） ---------- */
#app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-areas:
    "top   top"
    "tools stage"
    "colors colors";
  grid-template-rows: auto 1fr auto;
  grid-template-columns: 96px 1fr;
}

/* ---------- 顶栏 ---------- */
#topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px 6px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 21px;
  letter-spacing: 0.3px;
}

.brand-logo { width: 34px; height: 34px; }

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.v-divider {
  width: 2px;
  height: 34px;
  margin: 0 4px;
  border-radius: 2px;
  background: rgba(94, 62, 40, 0.12);
}

/* ---------- 通用大按钮（儿童手指友好 ≥56px） ---------- */
.btn {
  border: none;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.14s ease, background 0.14s ease;
  font: inherit;
  padding: 0;
}

.btn:active { transform: scale(0.9); }

.btn.round {
  width: 56px;
  height: 56px;
  border-radius: 50%;
}

.btn svg { width: 26px; height: 26px; pointer-events: none; }

.btn:disabled { opacity: 0.32; cursor: default; transform: none; }

.btn.primary { background: var(--accent); color: #fff; box-shadow: 0 4px 12px rgba(255, 138, 92, 0.45); }
.btn.danger  { color: var(--danger); }

/* ---------- 左侧工具栏 ---------- */
#toolbar {
  grid-area: tools;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  padding: 8px 0 12px;
  overflow-y: auto;
  scrollbar-width: none;
}
#toolbar::-webkit-scrollbar { display: none; }

.btn.tool {
  width: var(--tool-size);
  height: var(--tool-size);
  border-radius: 22px;
  color: #8B7D72;
  flex: 0 0 auto;
}

.btn.tool svg { width: 30px; height: 30px; }

.btn.tool.active {
  transform: scale(1.1);
  color: #fff;
  box-shadow: var(--shadow-lg);
}

/* 每个工具一个专属主题色，直观又好玩 */
.btn.tool[data-tool="brush"]       { --tc: #4D9FFF; }
.btn.tool[data-tool="inkbrush"]    { --tc: #4A4A55; }
.btn.tool[data-tool="crayon"]      { --tc: #FF9F43; }
.btn.tool[data-tool="marker"]      { --tc: #34C08B; }
.btn.tool[data-tool="highlighter"] { --tc: #F5B70A; }
.btn.tool[data-tool="rainbow"] {
  --tc: #9B6CFF;
  background: conic-gradient(#ff8a8a, #ffd28a, #b8f3a0, #8ad9ff, #b8a0ff, #ff8ad0, #ff8a8a);
  color: #fff;
}
.btn.tool[data-tool="fill"]        { --tc: #FF6FA5; }
.btn.tool[data-tool="eraser"]      { --tc: #8FA6B8; }

.btn.tool.active { background: var(--tc); }
.btn.tool[data-tool="rainbow"].active {
  background: conic-gradient(#ff8a8a, #ffd28a, #b8f3a0, #8ad9ff, #b8a0ff, #ff8ad0, #ff8a8a);
}

/* ---------- 画布区域 ---------- */
#stage {
  grid-area: stage;
  position: relative;
  margin: 4px 16px 12px 0;
  border-radius: 24px;
  background: var(--paper);
  background-image: radial-gradient(rgba(120, 100, 80, 0.09) 1.2px, transparent 1.2px);
  background-size: 26px 26px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* phones in landscape: keep the canvas from getting absurdly wide */
@media (orientation: landscape) and (max-height: 520px) {
  #stage {
    justify-self: center;
    width: 100%;
    max-width: min(165vh, 100%);
    margin: 4px 10px 10px;
    border-radius: 18px;
  }
}

#board, #overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#board { touch-action: none; cursor: crosshair; }
#overlay { pointer-events: none; opacity: 0; }

/* the WHOLE-PAPER bitmap shown while panning/zooming: the gesture only
 * CSS-transforms this layer (compositor-only, zero canvas re-render), and
 * because the entire sheet is rendered, dragging can never expose blanks.
 * One crisp viewport render happens when the gesture ends. */
#paper-layer {
  position: absolute;
  display: none;
  transform-origin: 0 0;
  pointer-events: none;
}

/* ---------- 缩放比例提示 + 重置按钮（缩放时短暂显示在画布顶部） ---------- */
#zoom-indicator {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%) translateY(-6px);
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 7;
}
#zoom-indicator.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#zoom-indicator.show #zoom-reset { pointer-events: auto; }

#zoom-tip {
  background: rgba(74, 59, 50, 0.88);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  padding: 8px 16px;
  border-radius: 19px;
}

#zoom-reset {
  pointer-events: none;          /* only clickable while the indicator is shown */
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  padding: 0;
  background: rgba(74, 59, 50, 0.88);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}
#zoom-reset:active { transform: scale(0.9); }
#zoom-reset svg { width: 20px; height: 20px; }

/* ---------- 画纸滚动条（纸大于视口时出现） ---------- */
.sb {
  position: absolute;
  background: rgba(74, 59, 50, 0.12);
  border-radius: 4px;
  display: none;
  z-index: 5;
}
.sb-v { right: 5px; top: 10px; bottom: 10px; width: 7px; }
.sb-h { left: 10px; right: 10px; bottom: 5px; height: 7px; }
.sb-thumb {
  position: absolute;
  background: rgba(74, 59, 50, 0.4);
  border-radius: 4px;
  cursor: grab;
}
.sb-v .sb-thumb { left: 0; width: 100%; height: 48px; top: 0; }
.sb-h .sb-thumb { top: 0; height: 100%; width: 48px; left: 0; }
.sb-thumb:active { cursor: grabbing; background: rgba(74, 59, 50, 0.6); }
@media (hover: none) and (pointer: coarse) {
  .sb { opacity: 0.6; }
}

/* ---------- 小地图（画布位置预览） ---------- */
#minimap {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: 132px;
  height: 96px;
  background: rgba(255, 252, 247, 0.95);
  border-radius: 10px;
  box-shadow: var(--shadow), 0 0 0 1.5px rgba(74, 59, 50, 0.15);
  opacity: 0;
  transition: opacity 0.25s ease;
  cursor: pointer;
  z-index: 6;
  overflow: hidden;
  pointer-events: none;          /* faded = not clickable: never block drawing */
}
#minimap.show { opacity: 1; pointer-events: auto; }
#minimap canvas { width: 100%; height: 100%; display: block; }

/* viewport rectangle: a DOM element, so panning never redraws the
 * minimap canvas — it just moves this box with 4 style writes */
#mm-view {
  position: absolute;
  left: 0; top: 0;
  border: 2px solid #FF6FA5;
  box-sizing: border-box;
  pointer-events: none;
  display: none;
}

/* ---------- 底部：颜色 + 粗细 ---------- */
#colorbar {
  grid-area: colors;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 20px calc(10px + env(safe-area-inset-bottom, 0px));
  min-width: 0;
}

.current-color {
  position: relative;
  width: 66px;
  height: 66px;
  border-radius: 50%;
  border: none;
  padding: 0;
  background: var(--paper);
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  cursor: pointer;
}

.current-color:active { transform: scale(0.92); }

.current-color span {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #3D7BFF;
  border: 3px solid #fff;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.22);
  transition: background 0.15s ease;
}

/* little badge hinting the color picker */
.cc-plus {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-style: normal;
  font-size: 19px;
  font-weight: 700;
  line-height: 23px;
  text-align: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

.palette {
  display: flex;
  gap: 10px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  /* extra room so the enlarged selected swatch never clips */
  padding: 14px 12px;
  scrollbar-width: none;
}
.palette::-webkit-scrollbar { display: none; }

.swatch {
  position: relative;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  flex: 0 0 auto;
  cursor: pointer;
  padding: 0;
  box-shadow: inset 0 -4px 7px rgba(0, 0, 0, 0.14), 0 2px 4px rgba(0, 0, 0, 0.14);
  transition: transform 0.14s ease;
}

.swatch:active { transform: scale(0.85); }

.swatch .check {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 24px;
  height: 24px;
  transform: translate(-50%, -50%);
  stroke-width: 3;
  display: none;
  pointer-events: none;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.3));
}

.swatch.selected {
  transform: scale(1.22);
  z-index: 1;
  box-shadow: 0 0 0 3px #fff, 0 0 0 5.5px var(--ink), 0 3px 8px rgba(0, 0, 0, 0.2);
}

.swatch.selected .check { display: block; }

.swatch.light { box-shadow: inset 0 -4px 7px rgba(0, 0, 0, 0.10), 0 0 0 1.5px rgba(94, 62, 40, 0.28); }

.swatch.light.selected {
  box-shadow: 0 0 0 3px #fff, 0 0 0 5.5px var(--ink), inset 0 -4px 7px rgba(0, 0, 0, 0.10);
}

.sizes {
  display: flex;
  gap: 10px;
  flex: 0 0 auto;
}

.size-btn {
  width: 52px;
  height: 52px;
  border-radius: 17px;
  color: var(--ink);
}

.size-btn i {
  display: block;
  border-radius: 50%;
  background: currentColor;
  transition: transform 0.14s ease;
}

.size-btn.selected {
  background: var(--accent);
  color: #fff;
  transform: scale(1.08);
  box-shadow: 0 4px 12px rgba(255, 138, 92, 0.45);
}

/* ---------- 清空确认弹窗 ---------- */
.dialog {
  position: fixed;
  inset: 0;
  background: rgba(74, 59, 50, 0.4);
  display: grid;
  place-items: center;
  z-index: 50;
}

.dialog-card {
  background: #fff;
  border-radius: 28px;
  padding: 30px 36px 26px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: pop 0.18s ease;
  max-width: 88vw;
}

.dialog-emoji { line-height: 1; margin-bottom: 12px; }
.dialog-icon { width: 56px; height: 56px; color: var(--danger); stroke-width: 1.8; }

.dialog-card p {
  margin: 0 0 22px;
  font-size: 21px;
  font-weight: 600;
}

/* buttons never wrap their label; if the row gets too tight the whole
 * button moves to the next line instead of the text breaking inside */
.dialog-actions {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
}
.dialog-actions .btn { flex-shrink: 0; }

.btn.pill {
  height: 56px;
  padding: 0 24px;
  border-radius: 28px;
  font-size: 19px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}

/* small phones: tighter card + button padding so the pair always fits */
@media (max-width: 420px) {
  .dialog-card { padding: 22px 16px 20px; }
  .btn.pill { padding: 0 16px; font-size: 17px; }
}

.btn.pill.ok { background: var(--danger); color: #fff; box-shadow: 0 4px 12px rgba(242, 85, 85, 0.4); }

@keyframes pop {
  from { transform: scale(0.85); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

.hidden { display: none !important; }

/* ---------- 专业调色板 Color picker ---------- */
.picker-card { width: min(380px, 94vw); }

.picker-title {
  margin: 0 0 16px;
  font-size: 22px;
  font-weight: 700;
}

.picker-title-sub { color: var(--muted); font-size: 15px; font-weight: 600; }

.sv-box {
  position: relative;
  width: 100%;
  height: 170px;
  border-radius: 14px;
  touch-action: none;
  cursor: crosshair;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08), var(--shadow);
  /* pure hue comes from JS via background-color */
  background-image:
    linear-gradient(to top, #000, rgba(0, 0, 0, 0)),
    linear-gradient(to right, #fff, rgba(255, 255, 255, 0));
}

.sv-dot, .slider-dot {
  position: absolute;
  top: 50%;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 0 0 1.5px rgba(0, 0, 0, 0.35), 0 1px 4px rgba(0, 0, 0, 0.3);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.sv-dot { top: 50%; }
.sv-box .sv-dot { top: auto; transform: translate(-50%, -50%); }

.slider {
  position: relative;
  height: 26px;
  border-radius: 13px;
  margin-top: 14px;
  touch-action: none;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.10);
}

.hue-bar {
  background: linear-gradient(to right,
    #ff0000, #ffff00, #00ff00, #00ffff, #0000ff, #ff00ff, #ff0000);
}

.alpha-bar {
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #d9d2ca 25%, transparent 25%, transparent 75%, #d9d2ca 75%),
    linear-gradient(45deg, #d9d2ca 25%, transparent 25%, transparent 75%, #d9d2ca 75%);
  background-size: 16px 16px;
  background-position: 0 0, 8px 8px;
}

.alpha-fill {
  position: absolute;
  inset: 0;
  border-radius: 13px;
}

.picker-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
}

.picker-swatch {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  flex: 0 0 auto;
  box-shadow: inset 0 -3px 6px rgba(0, 0, 0, 0.12), 0 1px 4px rgba(0, 0, 0, 0.2);
  border: 3px solid #fff;
  outline: 1.5px solid rgba(94, 62, 40, 0.25);
}

.picker-swatch.new { width: 52px; height: 52px; cursor: default; }
.picker-swatch.old { cursor: pointer; }
.picker-swatch.old:active { transform: scale(0.9); }

.hex-input {
  flex: 1;
  min-width: 0;
  height: 52px;
  border-radius: 16px;
  border: none;
  background: #F6EFE7;
  box-shadow: inset 0 2px 5px rgba(94, 62, 40, 0.12);
  font-family: Consolas, "Courier New", monospace;
  font-size: 19px;
  font-weight: 600;
  color: var(--ink);
  text-align: center;
  padding: 0 12px;
  outline: none;
}

.hex-input:focus { box-shadow: inset 0 0 0 2.5px var(--accent); }

.rgba-text {
  margin: 12px 2px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
  letter-spacing: 0.4px;
}

.picker-card .dialog-actions { margin-top: 18px; }

.btn.pill.confirm { background: var(--accent); color: #fff; box-shadow: 0 4px 12px rgba(255, 138, 92, 0.45); }

/* ---------- 顶栏问号小按钮（操作手册入口） ---------- */
.btn.help {
  width: 30px;
  height: 30px;
  color: #B09C8C;
}
.btn.help svg { width: 17px; height: 17px; }

/* 小号圆按钮（手册关闭钮等） */
.btn.small { width: 40px; height: 40px; }
.btn.small svg { width: 18px; height: 18px; }

/* ---------- 操作手册 ---------- */
.manual-card {
  width: min(620px, 94vw);
  /* vh fallback FIRST: old Android WebViews drop declarations using dvh
   * wholesale — without the fallback the card had NO height cap and
   * overflowed short landscape screens */
  max-height: 86vh;
  max-height: min(86vh, 86dvh);
  padding: 22px 24px 14px;
  text-align: left;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.manual-head {
  display: flex;
  align-items: center;
  gap: 10px;
}
.manual-head-icon { width: 30px; height: 30px; flex: 0 0 auto; }
.manual-head h2 {
  margin: 0;
  flex: 1;
  font-size: 23px;
  font-weight: 800;
  text-align: left;
}
#manual-close { color: var(--muted); flex: 0 0 auto; }

.manual-sub {
  margin: 6px 0 4px;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
  letter-spacing: 0.4px;
}

/* scrollable content — pan-y so touch scrolling works inside the overlay */
.manual-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  margin-top: 4px;
  padding: 2px 8px 8px 2px;
}
.manual-body::-webkit-scrollbar { width: 8px; }
.manual-body::-webkit-scrollbar-thumb { background: rgba(94, 62, 40, 0.18); border-radius: 4px; }

.manual-sec {
  width: fit-content;
  margin: 14px 0 4px;
  padding: 4px 14px;
  border-radius: 13px;
  background: rgba(255, 138, 92, 0.13);
  color: var(--accent);
  font-size: 14.5px;
  font-weight: 800;
  letter-spacing: 0.4px;
}

.manual-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 7px 0;
}
.manual-ico {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: rgba(94, 62, 40, 0.07);
  color: var(--tc, var(--accent));
}
.manual-ico svg { width: 22px; height: 22px; }
.manual-row p {
  margin: 0;
  flex: 1;
  font-size: 15px;
  line-height: 1.45;
}
.manual-row b {
  display: block;
  font-size: 16px;
  margin-bottom: 1px;
}

/* per-entry accent colors, mirroring the tool rail */
.manual-ico.g          { --tc: #FF8A5C; }
.manual-ico.t-brush    { --tc: #4D9FFF; }
.manual-ico.t-inkbrush { --tc: #4A4A55; }
.manual-ico.t-crayon   { --tc: #FF9F43; }
.manual-ico.t-marker   { --tc: #34C08B; }
.manual-ico.t-highlighter { --tc: #E8A800; }
.manual-ico.t-rainbow  { --tc: #9B6CFF; }
.manual-ico.t-spray    { --tc: #FF6FA5; }
.manual-ico.t-fill     { --tc: #FF6FA5; }
.manual-ico.t-eraser   { --tc: #8FA6B8; }
.manual-ico.t-undo     { --tc: #8B7D72; }
.manual-ico.t-redo     { --tc: #8B7D72; }
.manual-ico.t-paper    { --tc: #00B8C2; }
.manual-ico.t-gallery  { --tc: #46A758; }
.manual-ico.t-clear    { --tc: #F25555; }
.manual-ico.t-save     { --tc: #FF8A5C; }
.manual-ico.t-color    { --tc: #3D7BFF; }
.manual-ico.t-size     { --tc: #34C08B; }

/* small phones: tighten the manual card */
@media (max-width: 420px) {
  .manual-card { padding: 16px 14px 10px; }
  .manual-row { gap: 10px; padding: 6px 0; }
  .manual-ico { width: 36px; height: 36px; border-radius: 12px; }
  .manual-ico svg { width: 20px; height: 20px; }
  .manual-row p { font-size: 14px; }
}

/* ---------- 画纸大小选择 ---------- */
.paper-card { width: min(430px, 94vw); }

.paper-options {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin: 4px 0 14px;
}

.paper-opt {
  flex: 1 1 0;
  min-width: 0;
  border: none;
  background: var(--paper);
  border-radius: 18px;
  padding: 12px 6px 10px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  font: inherit;
  color: var(--ink);
  transition: transform 0.14s ease, box-shadow 0.14s ease, background 0.14s ease;
}
.paper-opt:active { transform: scale(0.94); }
.paper-opt.selected {
  background: #FFF1E7;
  box-shadow: 0 0 0 3px #fff, 0 0 0 5.5px var(--accent), var(--shadow-lg);
}

.paper-opt b { font-size: 24px; font-weight: 800; letter-spacing: 0.5px; }
.paper-opt i {
  font-style: normal;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.3px;
}

/* orientation toggle + custom size row */
.paper-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 0 0 12px;
}

.paper-chip {
  height: 44px;
  padding: 0 24px;
  border: none;
  border-radius: 22px;
  background: #F6EFE7;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: background 0.14s ease, color 0.14s ease;
}
.paper-chip.selected {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 12px rgba(255, 138, 92, 0.45);
}

.paper-custom label { font-size: 15px; font-weight: 700; color: var(--muted); }
.paper-custom span { font-size: 16px; font-weight: 700; color: var(--muted); }
.paper-unit { font-size: 13px; font-weight: 700; color: var(--muted); }

.paper-input {
  width: 96px;
  height: 48px;
  border: none;
  border-radius: 14px;
  background: #F6EFE7;
  box-shadow: inset 0 2px 5px rgba(94, 62, 40, 0.12);
  font: inherit;
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  color: var(--ink);
  outline: none;
}
.paper-input:focus { box-shadow: inset 0 0 0 2.5px var(--accent); }
.paper-input.bad { box-shadow: inset 0 0 0 2.5px var(--danger); }
/* number spinners off — kids type with the numeric keypad */
.paper-input::-webkit-outer-spin-button,
.paper-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.paper-input[type=number] { -moz-appearance: textfield; appearance: textfield; }

.paper-warning {
  color: var(--danger);
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 12px;
}
.paper-card .dialog-actions { margin-top: 10px; }

/* ---------- 保存确认弹窗 ---------- */
.save-card { width: min(430px, 94vw); }
.save-card .manual-sub { margin-bottom: 12px; }
.save-input {
  width: 100%;
  height: 52px;
  text-align: left;
  padding: 0 16px;
  font-family: Consolas, "Courier New", monospace;
}
#save-exists { margin: 10px 0 0; }
.save-card .dialog-actions { margin-top: 14px; }

/* ---------- 我的画册 ---------- */
.gallery-card {
  width: min(760px, 96vw);
  /* vh fallback FIRST: old WebViews drop dvh rules wholesale */
  max-height: 86vh;
  max-height: min(86vh, 86dvh);
  padding: 18px 20px 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  text-align: left;
}
.gallery-list {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  padding: 2px;
  margin-top: 10px;
}
.gallery-item {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow);
  background: #fff;
}
.gi-open {
  display: block;
  width: 100%;
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}
.gi-open img {
  display: block;
  width: 100%;
  height: 108px;
  object-fit: contain;
  background: #fff;
}
.gi-name {
  display: block;
  font-size: 13.5px;
  font-weight: 700;
  padding: 5px 8px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gi-date {
  display: block;
  font-style: normal;
  font-size: 11.5px;
  color: var(--muted);
  padding: 1px 8px 8px;
}
.gi-del {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  padding: 0;
  background: rgba(74, 59, 50, 0.55);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.gi-del:active { transform: scale(0.9); }
.gi-del svg { width: 14px; height: 14px; }
#gallery-add { color: #46A758; }

/* ---------- 通用确认弹窗 ---------- */
.confirm-card { width: min(420px, 94vw); }

/* small phones: tighter paper options */
@media (max-width: 420px) {
  .paper-options { gap: 8px; }
  .paper-opt { padding: 10px 4px 8px; border-radius: 14px; }
  .paper-opt b { font-size: 20px; }
  .paper-opt i { font-size: 11px; }
  .paper-chip { height: 40px; padding: 0 18px; font-size: 15px; }
  .paper-input { width: 78px; height: 42px; font-size: 16px; }
  .paper-row { gap: 6px; margin-bottom: 10px; }
}

/* ---------- 保存提示 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(110px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(16px);
  background: rgba(74, 59, 50, 0.88);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  padding: 12px 26px;
  border-radius: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  z-index: 60;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 竖屏（手机 / 竖放平板）：工具移到底部 ---------- */
@media (orientation: portrait) {
  #app {
    grid-template-areas:
      "top"
      "stage"
      "colors"
      "tools";
    grid-template-rows: auto 1fr auto auto;
    grid-template-columns: 1fr;
  }

  #toolbar {
    flex-direction: row;
    justify-content: flex-start;   /* centered overflow hides the first buttons */
    padding: 4px 10px calc(8px + env(safe-area-inset-bottom, 0px));
    overflow-x: auto;
    overflow-y: hidden;
    touch-action: pan-x;
    -webkit-overflow-scrolling: touch;
  }

  #stage { margin: 2px 12px 10px; justify-self: stretch; max-width: none; }

  /* sizes collapse into a 2×2 grid so the palette keeps its room */
  .sizes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
  .current-color { width: 48px; height: 48px; }
  .current-color span { width: 34px; height: 34px; }
  .cc-plus { width: 20px; height: 20px; font-size: 15px; line-height: 19px; }
  .swatch { width: 36px; height: 36px; }
  .swatch .check { width: 20px; height: 20px; }
  .palette { touch-action: pan-x; padding: 12px 10px; gap: 8px; }

  #stage { margin: 2px 12px 10px; }

  .toast { bottom: calc(172px + env(safe-area-inset-bottom, 0px)); }

  :root { --tool-size: 52px; }
}

/* 小屏手机进一步压缩 */
@media (max-width: 560px) {
  .brand-name { display: none; }
  .top-actions { gap: 8px; }
  .btn.round { width: 46px; height: 46px; }
  .btn.round svg { width: 23px; height: 23px; }
  .v-divider { height: 28px; }
  #topbar { padding: 8px 12px 4px; }
}

/* ---------- 手机横屏：颜色/粗细移到右侧细列，画布最大化 ---------- */
@media (orientation: landscape) and (max-height: 520px) {
  #app {
    grid-template-areas:
      "top  top   top"
      "tools stage colors";
    grid-template-rows: auto 1fr;
    grid-template-columns: 68px 1fr 76px;
  }

  #topbar { padding: 6px 12px 4px; }

  #toolbar {
    justify-content: flex-start;
    padding: 6px 0 8px;
    gap: 8px;
  }
  :root { --tool-size: 46px; }
  .btn.tool { border-radius: 16px; }
  .btn.tool svg { width: 26px; height: 26px; }

  #stage { margin: 4px 10px 10px; border-radius: 18px; }

  /* colors become a narrow right-hand column */
  #colorbar {
    flex-direction: column;
    justify-content: flex-start;
    gap: 10px;
    padding: 8px 6px calc(8px + env(safe-area-inset-bottom, 0px));
    overflow: hidden;
  }
  .current-color { width: 48px; height: 48px; order: -1; }
  .current-color span { width: 34px; height: 34px; }
  .cc-plus { width: 20px; height: 20px; font-size: 15px; line-height: 19px; }

  .palette {
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
    touch-action: pan-y;
    flex: 1 1 auto;
    min-height: 0;
    padding: 4px 2px;
    gap: 8px;
    align-items: center;
    -webkit-overflow-scrolling: touch;
  }
  .swatch { width: 36px; height: 36px; }
  .swatch .check { width: 20px; height: 20px; }

  .sizes {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    width: 100%;
    justify-items: center;
  }
  .size-btn { width: 30px; height: 30px; border-radius: 10px; }
  .size-btn i { transform: scale(0.8); }
}

/* ---------- 描红字帖（学习模式） ---------- */
#btn-practice { color: #8B7D72; }
#btn-practice.active {
  background: #9B6CFF;
  color: #fff;
  box-shadow: 0 4px 12px rgba(155, 108, 255, 0.45);
}

.practice-card { width: min(480px, 94vw); }
.practice-tabs { margin: 2px 0 12px; }

.practice-presets {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 0 0 14px;
}

.preset-chip {
  height: 44px;
  padding: 0 16px;
  border: none;
  border-radius: 22px;
  background: #F6EFE7;
  color: var(--ink);
  font: inherit;
  font-size: 15.5px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: background 0.14s ease, color 0.14s ease, transform 0.14s ease;
}
.preset-chip:active { transform: scale(0.95); }
.preset-chip.selected {
  background: #9B6CFF;
  color: #fff;
  box-shadow: 0 4px 12px rgba(155, 108, 255, 0.45);
}

.practice-custom {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 4px;
}
.practice-custom label { font-size: 15px; font-weight: 700; color: var(--muted); flex: 0 0 auto; }
.practice-input {
  flex: 1;
  width: auto;
  min-width: 0;
  height: 48px;
  text-align: left;
  padding: 0 14px;
  font-size: 17px;
}

/* 自定义格子行列：两个窄数字框 + 自动按钮 */
.practice-grid-row { justify-content: center; margin-bottom: 10px; }
.practice-grid-in {
  flex: 0 0 auto;
  width: 76px;
  height: 46px;
  text-align: center;
  padding: 0 6px;
  font-size: 17px;
}
.practice-grid-x { font-size: 16px; font-weight: 700; color: var(--muted); }
.practice-auto-chip { height: 40px; padding: 0 16px; font-size: 14px; border-radius: 20px; }
.practice-auto-chip.selected { background: #9B6CFF; color: #fff; }
.practice-card .dialog-actions { margin-top: 14px; }

.manual-ico.t-learn { --tc: #9B6CFF; }

/* short landscape phones: match the tightened dialog metrics */
@media (orientation: landscape) and (max-height: 520px) {
  .practice-card { width: min(430px, 96vw); }
  .practice-tabs { margin: 2px 0 8px; }
  .practice-presets { gap: 6px; margin-bottom: 10px; }
  .preset-chip { height: 36px; padding: 0 14px; font-size: 14px; border-radius: 18px; }
  .practice-input { height: 38px; font-size: 15px; }
}

/* small phones */
@media (max-width: 420px) {
  .preset-chip { height: 40px; padding: 0 13px; font-size: 14px; }
  .practice-input { height: 44px; }
}

/* ---------- 弹窗自适应（小屏不超界） ---------- */
.dialog-card {
  max-height: calc(100vh - 16px);   /* fallback: old WebViews drop dvh rules */
  max-height: calc(100dvh - 16px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sv-box { height: clamp(110px, 26vh, 170px); }

@media (orientation: landscape) and (max-height: 520px) {
  .picker-card { width: min(340px, 94vw); padding: 18px 22px 18px; }
  .sv-box { height: 96px; }
  .picker-row { margin-top: 10px; }
  .dialog-actions { margin-top: 10px; }
  .btn.pill { height: 48px; padding: 0 22px; font-size: 16px; }

  /* every dialog gets tighter on short landscape phones — content must fit
   * (or scroll) inside ~340px of height */
  .dialog-card { padding: 14px 16px 12px; }
  .dialog-card p { font-size: 17px; margin-bottom: 12px; }
  .dialog-icon { width: 40px; height: 40px; }

  .manual-card { width: min(600px, 96vw); padding: 10px 12px 6px; }
  .manual-head h2 { font-size: 18px; }
  .manual-sub { font-size: 13px; margin: 3px 0 2px; }
  .manual-sec { font-size: 13px; margin: 9px 0 3px; }
  .manual-row { padding: 4px 0; gap: 9px; }
  .manual-ico { width: 30px; height: 30px; border-radius: 10px; }
  .manual-ico svg { width: 17px; height: 17px; }
  .manual-row p { font-size: 13px; line-height: 1.35; }
  .manual-row b { font-size: 14px; }

  .paper-card { width: min(430px, 96vw); }
  .paper-options { margin: 2px 0 8px; }
  .paper-opt { padding: 7px 4px 5px; gap: 2px; }
  .paper-opt b { font-size: 18px; }
  .paper-opt i { font-size: 11px; }
  .paper-chip { height: 36px; padding: 0 16px; font-size: 14px; border-radius: 18px; }
  .paper-input { width: 84px; height: 38px; font-size: 16px; border-radius: 11px; }
  .paper-row { margin-bottom: 8px; }
  .paper-warning { margin: 0 0 8px; font-size: 13px; }

  .save-card .manual-sub { margin-bottom: 8px; }
  .save-input { height: 44px; font-size: 15px; }
  .save-card .dialog-actions { margin-top: 10px; }
  .gallery-card { width: min(700px, 96vw); padding: 12px 14px 10px; }
  .gallery-list { gap: 8px; margin-top: 6px; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .gi-open img { height: 78px; }
  .confirm-card p { font-size: 15px; }
}
