/* Kawairun 2 Skin Maker - matches the main site's wood/plank palette and the
 * "Kawairun" webfont (see Server/kawairun2.html for the @font-face source and
 * Server/profile.html / kawairun2.html for the color values reused below). */

@font-face {
  font-family: "Kawairun";
  src: url('/assets/fonts/Kawairun.ttf') format("truetype");
  font-display: swap;
}

:root {
  --wood-dark: #3b2a1a;
  --wood: #5C4227;
  --wood-light: #7b5936;
  --wood-lighter: #9c7144;
  --cream: #e0bc98;
  --cream-strong: #F2E1C4;
  --panel-fill: #7B4F2E;
  --panel-border: #452812;
  --green-fill: #61923F;
  --green-border: #2F471D;
  --input-fill: #CFAE81;
  --input-border: #4A2A15;
  --danger: #C0392B;
  --text-on-dark: #f4e6d0;
  --bg-app: #241811;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  /* a pen dragged across the panels shouldn't select text */
  -webkit-user-select: none; user-select: none;
  background: var(--bg-app);
  color: var(--text-on-dark);
  font-family: "Kawairun", Tahoma, Verdana, sans-serif;
  font-size: 13px;
  overflow: hidden;
}
h1, h2, h3 { margin: 0 0 8px 0; font-weight: normal; color: var(--cream-strong); text-shadow: 1px 1px 2px rgba(0,0,0,0.5); }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid var(--wood-light); padding-bottom: 4px; }
button { font-family: inherit; }
input, textarea { -webkit-user-select: text; user-select: text; }
.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; display: block; }

/* No visible scrollbars anywhere: panels still scroll with the wheel, touch
 * or a pen, and nothing is allowed to scroll sideways. */
* { scrollbar-width: none; }
*::-webkit-scrollbar { display: none; width: 0; height: 0; }

/* ---- shared controls --------------------------------------------------- */
.kr2-btn {
  background: var(--panel-fill); color: var(--text-on-dark);
  border: 2px solid var(--panel-border); border-radius: 6px;
  padding: 7px 12px; cursor: pointer; font-size: 13px;
  box-shadow: 2px 2px 4px rgba(0,0,0,0.4);
}
.kr2-btn:hover { background: var(--wood-light); }
.kr2-btn:active { box-shadow: inset 1px 1px 3px rgba(0,0,0,0.5); }
.kr2-btn:focus-visible { outline: 2px solid var(--cream-strong); outline-offset: 1px; }
.kr2-btn:disabled { opacity: 0.4; cursor: default; }
.kr2-btn-sm { padding: 5px 9px; font-size: 12px; }
.kr2-btn-primary { background: var(--green-fill); border-color: var(--green-border); }
.kr2-btn-primary:hover { background: #6fa84a; }
.kr2-btn-danger:hover { background: var(--danger); }
.kr2-btn.active { background: var(--green-fill); border-color: var(--green-border); box-shadow: inset 1px 1px 3px rgba(0,0,0,0.5); }

.kr2-input, .kr2-select {
  background: var(--input-fill); color: #2b1c10; border: 2px solid var(--input-border);
  border-radius: 5px; padding: 5px 7px; font-size: 13px; font-family: inherit;
}
.kr2-input:focus-visible, .kr2-select:focus-visible { outline: 2px solid var(--cream-strong); }
.kr2-hidden-input { display: none; }
.kr2-hidden { display: none !important; }

input[type=range] { accent-color: var(--green-fill); }
input[type=checkbox] { accent-color: var(--green-fill); }

/* ---- top bar ------------------------------------------------------------ */
.topbar {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  background: linear-gradient(var(--wood), var(--wood-dark));
  border-bottom: 3px solid var(--panel-border);
  flex-wrap: wrap;
}
.topbar-name { width: 160px; }
.topbar-group { display: flex; gap: 6px; align-items: center; }
.topbar-spacer { flex: 1 1 auto; }
.topbar-account-mini { position: relative; font-size: 12px; color: var(--cream); }
.topbar-account-mini a.kr2-btn { display: inline-block; text-decoration: none; }
.acct-user-btn { display: flex; align-items: center; gap: 6px; padding: 3px 9px 3px 3px; }
.acct-avatar { width: 22px; height: 22px; border-radius: 4px; object-fit: cover; background: #D0F3F9; }
.acct-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 60; width: 230px;
  display: flex; flex-direction: column; gap: 6px; padding: 10px;
  background: var(--panel-fill); border: 2px solid var(--panel-border); border-radius: 8px; box-shadow: 0 6px 16px rgba(0,0,0,0.5);
}
.acct-menu a.kr2-btn { text-align: center; }
.mode-badge { font-size: 11px; padding: 3px 8px; border-radius: 10px; background: rgba(0,0,0,0.3); color: var(--cream); cursor: help; white-space: nowrap; }

/* ---- layout -------------------------------------------------------------- */
.main-layout { display: flex; height: calc(100% - 54px); }
.side-panel {
  width: 260px; flex: 0 0 260px; overflow-y: auto; overflow-x: hidden; padding: 10px;
  background: var(--wood-dark);
  border-right: 3px solid var(--panel-border);
}
.right-panel { border-right: none; border-left: 3px solid var(--panel-border); }
.center-panel { flex: 1 1 auto; min-width: 0; min-height: 0; display: flex; flex-direction: column; background: #1c130d; }
/* #regionEditor is centerPanel's only child (filled by Regions.init -> buildEditorDom
 * with .editor-toolbar + #regionViewport). It must itself be a column flexbox so
 * #regionViewport's `flex: 1 1 auto` has a flex container to size against - without
 * this, #regionEditor is a plain block box whose only child positioned content
 * (.region-stage, position:absolute) contributes nothing to auto height, so
 * #regionViewport collapses to 0px tall and fitToView()/zoom math (which divides by
 * viewportEl.clientHeight) goes negative, placing the drawable canvas outside the
 * visible viewport entirely. */
#regionEditor { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.panel-section { margin-bottom: 16px; }

/* ---- parts list ----------------------------------------------------------*/
.parts-list { display: flex; flex-direction: column; gap: 4px; }
.part-row {
  display: flex; align-items: center; gap: 8px; padding: 6px; border-radius: 6px;
  background: var(--wood); border: 1px solid var(--wood-dark); cursor: pointer;
}
.part-row:hover { background: var(--wood-light); }
.part-row.active { background: var(--green-fill); border-color: var(--green-border); }
.part-row:focus-visible { outline: 2px solid var(--cream-strong); }
.part-thumb { border-radius: 4px; border: 1px solid var(--panel-border); flex: 0 0 auto; image-rendering: pixelated; }
.part-label { flex: 1 1 auto; font-size: 12px; }
.part-badge { font-size: 10px; padding: 2px 6px; border-radius: 4px; white-space: nowrap; }
.part-badge.empty { background: rgba(0,0,0,0.3); color: var(--cream); }
.part-badge.custom { background: var(--green-fill); color: #fff; }

/* ---- tool palette ---------------------------------------------------------*/
.tool-palette { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-bottom: 8px; }
.tool-btn {
  background: var(--wood); border: 1px solid var(--wood-dark); border-radius: 5px; color: var(--text-on-dark);
  padding: 6px 2px 4px; cursor: pointer; line-height: 1;
  display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 0;
}
.tool-btn-label { font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tool-hint {
  font-size: 11px; line-height: 1.35; color: var(--cream); background: rgba(0,0,0,0.25);
  border-radius: 5px; padding: 6px 8px; margin-bottom: 8px; min-height: 2.7em;
}
.tool-hint b { color: var(--cream-strong); font-weight: normal; }
.tool-btn:hover { background: var(--wood-light); }
.tool-btn.active { background: var(--green-fill); border-color: var(--green-border); }
.tool-options { display: flex; flex-direction: column; gap: 6px; font-size: 12px; }
.opt-slider, .opt-select { display: flex; align-items: center; gap: 6px; }
.opt-label { flex: 0 0 66px; }
.opt-slider input[type=range] { flex: 1 1 auto; min-width: 0; }
.opt-select select, .opt-select input { flex: 1 1 auto; }
.opt-num { width: 46px; flex: 0 0 46px; padding: 2px 4px; font-size: 12px; text-align: right; }
.opt-unit { flex: 0 0 auto; font-size: 10px; color: var(--cream); width: 14px; }
.opt-check { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.opt-note { font-size: 11px; color: var(--cream); opacity: 0.85; }

.sticker-palette { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; margin-top: 8px; }
.sticker-swatch { background: var(--wood); border: 1px solid var(--wood-dark); border-radius: 4px; cursor: pointer; padding: 2px; }
.sticker-swatch:hover { background: var(--wood-light); }
.sticker-swatch canvas { display: block; width: 100%; image-rendering: pixelated; }

.image-import-box { display: flex; flex-direction: column; gap: 6px; }
.image-drop-zone {
  border: 2px dashed var(--wood-light); border-radius: 6px; padding: 14px 8px; text-align: center;
  font-size: 11px; color: var(--cream);
}
.placement-actions { display: flex; flex-direction: column; gap: 6px; }
.placement-btn-row { display: flex; gap: 4px; flex-wrap: wrap; }

/* ---- center editor --------------------------------------------------------*/
.editor-toolbar {
  display: flex; align-items: center; gap: 10px; padding: 6px 10px; flex-wrap: wrap;
  background: var(--wood-dark); border-bottom: 1px solid var(--panel-border); font-size: 12px;
}
.editor-tb-item { display: flex; align-items: center; gap: 4px; color: var(--cream); white-space: nowrap; }
.region-viewport {
  flex: 1 1 auto; position: relative; overflow: hidden;
  background: #100b07;
  background-image: linear-gradient(45deg, #1a120c 25%, transparent 25%), linear-gradient(-45deg, #1a120c 25%, transparent 25%);
  background-size: 24px 24px;
}
.region-stage { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
.stage-layer { position: absolute; top: 0; left: 0; image-rendering: pixelated; }
.stage-input { touch-action: none; cursor: crosshair; }
.region-viewport { touch-action: none; }
.stage-smooth, .region-stage.smooth .stage-guide { image-rendering: auto; }
.brush-cursor {
  position: absolute; pointer-events: none; border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.9); box-shadow: 0 0 0 1px rgba(0,0,0,0.7);
}
.brush-cursor.square { border-radius: 0; }

/* ---- layers panel ----------------------------------------------------------*/
.layer-list { display: flex; flex-direction: column-reverse; gap: 2px; margin-bottom: 6px; }
.layer-row {
  display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-radius: 5px;
  background: var(--wood); border: 1px solid var(--wood-dark); cursor: pointer;
}
.layer-row.active { background: var(--green-fill); border-color: var(--green-border); }
.layer-vis-btn { background: none; border: none; color: var(--text-on-dark); cursor: pointer; padding: 0 2px; }
.layer-vis-btn .icon { width: 18px; height: 18px; }
.layer-vis-btn.off { opacity: 0.45; }
.layer-thumb { border: 1px solid var(--panel-border); border-radius: 3px; image-rendering: pixelated; flex: 0 0 auto; }
.layer-name-input { flex: 1 1 auto; min-width: 0; background: transparent; border: none; color: var(--text-on-dark); font-size: 12px; padding: 2px; }
.layer-name-input:focus { background: rgba(0,0,0,0.25); border-radius: 3px; }
.layer-opacity { width: 46px; }
.layer-toolbar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px; }
.layer-toolbar .kr2-btn { padding: 5px 2px; font-size: 11px; white-space: nowrap; }

/* ---- color panel ---------------------------------------------------------*/
.cp-sv-wrap { position: relative; width: 160px; height: 160px; margin-bottom: 6px; }
.cp-sv { border-radius: 4px; border: 1px solid var(--panel-border); display: block; cursor: crosshair; }
.cp-sv-cursor {
  position: absolute; width: 10px; height: 10px; border: 2px solid #fff; border-radius: 50%;
  box-shadow: 0 0 2px #000; transform: translate(-5px, -5px); pointer-events: none;
}
.cp-hue { border-radius: 4px; border: 1px solid var(--panel-border); display: block; width: 100%; cursor: pointer; margin-bottom: 6px; }
.cp-alpha { width: 100%; margin-bottom: 6px; }
.cp-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.cp-swatch { width: 30px; height: 30px; border-radius: 5px; border: 2px solid var(--panel-border); }
.cp-swatch2 { margin-left: -14px; margin-top: 10px; }
.cp-label { font-size: 11px; color: var(--cream); margin: 4px 0 2px; }
.cp-swatch-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 3px; }
.cp-swatch-sm { width: 100%; aspect-ratio: 1; border-radius: 3px; border: 1px solid var(--panel-border); cursor: pointer; }
.cp-swatch-sm.empty { border: 1px dashed rgba(224,188,152,0.25); background: transparent; cursor: default; }
.cp-swatch-sm.selected { outline: 2px solid var(--cream-strong); outline-offset: 1px; }

/* ---- adjust / options / costume panels -------------------------------------*/
#adjustPanel, #optionsPanel, #costumePanel { display: flex; flex-direction: column; gap: 6px; font-size: 12px; }
#adjustPanel label, #optionsPanel label, #costumePanel label { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
#adjustPanel input[type=range] { flex: 1 1 auto; }
.opt-row { display: flex; flex-direction: column; gap: 2px; }
.opt-row small { color: var(--cream); opacity: 0.85; }

/* ---- preview panel ---------------------------------------------------------*/
#previewCanvas { width: 100%; aspect-ratio: 300 / 260; border-radius: 6px; border: 2px solid var(--panel-border); background: #000; display: block; }
.preview-message { font-size: 12px; color: var(--cream); padding: 8px; background: rgba(0,0,0,0.25); border-radius: 6px; margin-top: 6px; }
.preview-controls { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 12px; min-width: 0; }
.preview-controls select { flex: 1 1 auto; min-width: 0; }
.preview-zoom { flex: 1 1 auto; min-width: 0; }
.preview-zoom input { flex: 1 1 auto; min-width: 0; width: 100%; }
.preview-hat { flex: 1 1 auto; min-width: 0; }
.preview-window-head { display: flex; align-items: center; justify-content: space-between; }
.preview-close, .preview-resize { display: none; }

/* Floating preview window (when the right panel has no room for it). */
.preview-window.floating {
  position: fixed; z-index: 40; display: flex; flex-direction: column;
  background: var(--wood-dark); border: 2px solid var(--panel-border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.6); overflow: hidden;
}
.preview-window.floating .preview-window-head {
  padding: 6px 6px 6px 10px; background: linear-gradient(var(--wood), var(--wood-dark));
  cursor: move; touch-action: none; flex: 0 0 auto;
}
.preview-window.floating .preview-window-head h3 { margin: 0; border: none; padding: 0; }
.preview-window.floating .preview-close {
  display: block; background: var(--danger); color: #fff; border: none; border-radius: 50%;
  width: 24px; height: 24px; cursor: pointer; font-size: 12px; line-height: 1;
}
.preview-window.floating .preview-window-body { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; padding: 8px; }
.preview-window.floating #previewCanvas { aspect-ratio: auto; flex: 1 1 auto; min-height: 0; height: 0; }
.preview-window.floating .preview-resize {
  display: block; position: absolute; right: 0; bottom: 0; width: 22px; height: 22px; cursor: nwse-resize; touch-action: none;
  background: linear-gradient(135deg, transparent 50%, var(--cream) 50%, var(--cream) 58%, transparent 58%, transparent 70%, var(--cream) 70%, var(--cream) 78%, transparent 78%);
}
.preview-window.dragging { opacity: 0.92; }
#btnPreview.active { background: var(--green-fill); border-color: var(--green-border); }

/* ---- account panel ---------------------------------------------------------*/
.acct-skin-status { font-size: 11px; color: var(--cream); }

/* ---- text editor overlay ----------------------------------------------------*/
.text-editor-overlay {
  position: fixed; z-index: 50; background: var(--wood); border: 2px solid var(--panel-border);
  border-radius: 8px; padding: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.6); width: 260px;
}
.text-editor-input { width: 100%; resize: vertical; margin-bottom: 6px; }
.text-editor-row { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.text-editor-size { width: 52px; }

/* ---- help modal ---------------------------------------------------------*/
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-panel {
  position: relative; max-width: 560px; width: 92%; max-height: 80vh; overflow-y: auto;
  background: var(--panel-fill); border: 3px solid var(--panel-border); border-radius: 10px; padding: 20px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.6);
}
.modal-close {
  position: absolute; top: 10px; right: 10px; background: var(--danger); color: #fff; border: none;
  border-radius: 50%; width: 28px; height: 28px; cursor: pointer;
}
.new-project-panel { max-width: 640px; }
.new-project-warn { color: #ffd9a0; }
.mode-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 12px 0; }
.mode-card {
  display: flex; flex-direction: column; gap: 6px; text-align: left; cursor: pointer;
  background: var(--wood); color: var(--text-on-dark); border: 2px solid var(--panel-border); border-radius: 8px; padding: 12px;
  font-size: 12px; line-height: 1.4;
}
.mode-card:hover, .mode-card:focus-visible { background: var(--wood-light); border-color: var(--cream); outline: none; }
.mode-card b { font-size: 16px; font-weight: normal; color: var(--cream-strong); }
.mode-card-art { height: 72px; border-radius: 6px; background-color: #f2e1c4; background-repeat: no-repeat; background-position: center; }
.mode-art-smooth {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 80 60'%3E%3Ccircle cx='40' cy='30' r='22' fill='%23fff' stroke='%23000' stroke-width='3'/%3E%3Cpath d='M48 26q3-5 6 0' fill='none' stroke='%23000' stroke-width='2.5' stroke-linecap='round'/%3E%3Cellipse cx='44' cy='36' rx='4' ry='2.5' fill='%23f5a3b0'/%3E%3C/svg%3E");
}
.mode-art-pixel {
  image-rendering: pixelated;
  background-size: 66px 66px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 11 11' shape-rendering='crispEdges'%3E%3Cpath d='M3 1h5v1h1v1h1v5H9v1H8v1H3V9H2V8H1V3h1V2h1z' fill='%23000'/%3E%3Cpath d='M3 2h5v1h1v5H8v1H3V8H2V3h1z' fill='%23fff'/%3E%3Cpath d='M6 4h2v1H6z' fill='%23000'/%3E%3Cpath d='M6 6h2v1H6z' fill='%23f5a3b0'/%3E%3C/svg%3E");
}
@media (max-width: 560px) { .mode-cards { grid-template-columns: 1fr; } }
.shortcut-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 8px; }
.shortcut-table td { padding: 4px 6px; border-bottom: 1px solid rgba(255,255,255,0.15); }
.shortcut-table td:first-child { font-family: monospace; color: var(--cream-strong); white-space: nowrap; }

/* ---- upload dialog ------------------------------------------------------*/
.upload-panel { max-width: 420px; }
.upload-field { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; font-size: 13px; color: var(--cream-strong); }
.upload-check { margin: 10px 0; font-size: 13px; }
.upload-error { color: #ffd9a0; min-height: 16px; font-size: 12px; margin: 4px 0; }
.upload-actions { display: flex; gap: 8px; margin-top: 10px; }
a.kr2-btn { text-decoration: none; display: inline-block; }
.toast a { color: var(--cream-strong); text-decoration: underline; }

/* ---- toasts ---------------------------------------------------------------*/
.toast-host { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: var(--panel-fill); border: 2px solid var(--panel-border); border-radius: 8px; padding: 10px 14px;
  color: var(--text-on-dark); font-size: 12px; max-width: 320px; box-shadow: 0 4px 10px rgba(0,0,0,0.5);
}
.toast.error { border-color: var(--danger); }
.toast.success { border-color: var(--green-border); background: var(--green-fill); }

/* ---- responsive / tablet degrade -------------------------------------------*/
@media (max-width: 1100px) {
  .side-panel { width: 210px; flex-basis: 210px; }
  .tool-palette { grid-template-columns: repeat(3, 1fr); }
}

/* ---- mobile shell ---------------------------------------------------------
 * Phones and short screens (portrait OR landscape): one canvas-first screen,
 * no page scrolling. Same query as js/mobile.js, which moves the panel
 * sections into the sheets below / the tool palette into the bottom bar and
 * puts everything back when the query stops matching. */
.m-only { display: none; }
@media (max-width: 900px), (max-height: 560px) {
  :root { --m-top-h: 44px; --m-bar-h: 60px; }
  html, body { overflow: hidden; height: 100%; overscroll-behavior: none; }
  body { position: fixed; inset: 0; width: 100%; height: 100dvh; display: flex; flex-direction: column; touch-action: manipulation; }
  button, a, label, select, .part-row, .layer-row { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
  .region-viewport, .stage-input, .cp-sv, .cp-hue, .preview-window.floating .preview-window-head, .preview-resize { touch-action: none; }
  .stage-input { -webkit-touch-callout: none; }
  .region-viewport.touch-pan .stage-input { cursor: grab; }

  /* top bar: one slim row */
  .topbar { flex: 0 0 auto; flex-wrap: nowrap; height: var(--m-top-h); padding: 4px 8px; gap: 6px; border-bottom-width: 2px; position: relative; z-index: 70; }
  .topbar-name { order: 1; flex: 1 1 70px; min-width: 0; width: auto; max-width: 200px; padding: 4px 6px; }
  .topbar-spacer { display: none; }
  .topbar .topbar-group { order: 2; flex: 0 0 auto; gap: 4px; }
  #btnHelp { order: 3; flex: 0 0 auto; }
  .topbar .m-menu-btn { display: block; order: 4; flex: 0 0 auto; }
  .topbar .kr2-btn-sm { padding: 5px 9px; min-height: 34px; }
  .m-menu-btn.active { background: var(--green-fill); border-color: var(--green-border); }

  /* canvas fills everything between the bars */
  .main-layout { flex: 1 1 auto; min-height: 0; height: auto; display: block; }
  .side-panel { display: none; }
  .center-panel { height: 100%; }
  .editor-toolbar { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; padding: 3px 8px; gap: 12px; touch-action: pan-x; }
  .editor-toolbar > *, .editor-toolbar .editor-zoom > * { flex: 0 0 auto; }
  .editor-toolbar .editor-zoom { display: flex; align-items: center; gap: 4px; }
  .region-viewport { height: auto; min-height: 0; }

  /* menu dropdown */
  .m-menu {
    display: flex; flex-direction: column; gap: 8px; position: fixed; z-index: 75; right: 8px; top: calc(var(--m-top-h) + 4px);
    width: min(280px, calc(100vw - 16px)); max-height: calc(100dvh - var(--m-top-h) - var(--m-bar-h) - 16px); overflow-y: auto; padding: 10px;
    background: var(--panel-fill); border: 2px solid var(--panel-border); border-radius: 10px; box-shadow: 0 8px 20px rgba(0,0,0,0.6);
  }
  .m-menu .topbar-group { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  .m-menu .kr2-btn { display: block; text-align: center; text-decoration: none; min-height: 38px; font-size: 13px; }
  .m-menu .mode-badge { align-self: flex-start; white-space: normal; }
  .m-menu .topbar-account-mini { position: static; }
  .m-menu .acct-menu { position: static; width: auto; margin-top: 6px; box-shadow: none; }

  /* bottom tool bar */
  .m-bar {
    display: flex; flex: 0 0 auto; height: var(--m-bar-h); align-items: stretch; position: relative; z-index: 70;
    background: linear-gradient(var(--wood), var(--wood-dark)); border-top: 3px solid var(--panel-border);
  }
  .m-tool-row {
    flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 4px; padding: 4px 6px;
    overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; touch-action: pan-x; overscroll-behavior-x: contain;
  }
  .m-tool-row .tool-palette { display: flex; flex-wrap: nowrap; gap: 4px; margin: 0; flex: 0 0 auto; }
  .m-sep { flex: 0 0 2px; align-self: stretch; margin: 4px 2px; background: var(--panel-border); }
  .m-tool-row .tool-btn, .m-btn {
    flex: 0 0 auto; width: 50px; height: 100%; max-height: 50px; padding: 4px 2px; cursor: pointer; line-height: 1; color: var(--text-on-dark);
    background: var(--wood); border: 1px solid var(--wood-dark); border-radius: 6px;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 0;
  }
  .m-btn.active { background: var(--green-fill); border-color: var(--green-border); }
  .m-btn-label { font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .m-toggles { flex: 0 0 auto; display: flex; align-items: center; gap: 4px; padding: 4px 6px; border-left: 2px solid var(--panel-border); background: var(--wood-dark); }
  .m-color-dot { display: block; width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--cream-strong); background: #000; box-shadow: 0 0 0 1px rgba(0,0,0,0.7); }
  @media (max-width: 480px) {
    .m-tool-row .tool-btn, .m-btn { width: 44px; }
    .m-btn-label, .tool-btn-label { font-size: 9px; }
    .m-lbl { display: none; }
  }

  /* slide-up sheets */
  .m-backdrop { display: block; position: fixed; left: 0; right: 0; top: var(--m-top-h); bottom: var(--m-bar-h); z-index: 60; background: rgba(0,0,0,0.35); }
  .m-sheet {
    display: flex; flex-direction: column; position: fixed; left: 0; right: 0; margin: 0 auto; max-width: 760px; bottom: var(--m-bar-h); z-index: 65;
    max-height: min(60dvh, calc(100dvh - var(--m-top-h) - var(--m-bar-h) - 8px));
    background: var(--wood-dark); border: 3px solid var(--panel-border); border-bottom: none; border-radius: 16px 16px 0 0;
    box-shadow: 0 -6px 18px rgba(0,0,0,0.5); animation: m-sheet-up 0.18s ease-out;
  }
  @keyframes m-sheet-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
  .m-sheet-head { position: relative; flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 4px; }
  .m-sheet-head h3 { margin: 0; border: none; padding: 0; }
  .m-sheet-grab { position: absolute; top: 6px; left: 50%; width: 44px; height: 4px; margin-left: -22px; border-radius: 2px; background: var(--cream); opacity: 0.55; }
  .m-sheet-close {
    width: 32px; height: 32px; border: none; border-radius: 50%; background: var(--danger); color: #fff; cursor: pointer; font-size: 14px; line-height: 1;
  }
  .m-sheet-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 6px 12px 14px; -webkit-overflow-scrolling: touch; touch-action: pan-y; overscroll-behavior: contain; }
  .m-pane[hidden] { display: none; }
  .m-pane-single > .panel-section > h3:first-child { display: none; }
  .m-pane .panel-section { margin-bottom: 14px; }
  .m-pane .parts-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
  .m-pane .part-row { padding: 8px; }
  .m-tool-opts { margin-bottom: 14px; }
  .m-sheet input[type=range] { min-height: 28px; }
  .cp-hue { width: 100%; max-width: 320px; }

  /* options chip + placement strip above the bar */
  .m-opt-chip { display: block; position: fixed; right: 8px; bottom: calc(var(--m-bar-h) + 8px); z-index: 55; border-radius: 16px; padding: 7px 13px; }
  .m-place-bar { display: block; position: fixed; left: 0; right: 0; bottom: var(--m-bar-h); z-index: 56; padding: 6px 8px; background: var(--wood-dark); border-top: 2px solid var(--panel-border); }
  .m-place-bar .placement-actions { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; }

  /* floating preview + toasts + resize grip sized for fingers */
  .preview-window.floating .preview-resize { width: 34px; height: 34px; }
  .preview-window.floating .preview-close { width: 30px; height: 30px; }
  .toast-host { bottom: calc(var(--m-bar-h) + 12px); right: 8px; left: 8px; align-items: flex-end; }
}

.ms-panel { max-width: 760px; width: 94%; height: 86vh; max-height: 86vh; display: flex; flex-direction: column; padding: 16px; overflow: hidden; }
.ms-head { display: flex; align-items: center; gap: 8px; padding-right: 36px; }
.ms-head h2 { margin: 0; }
.ms-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 8px; }
.ms-tab { font-size: 13px; }
.ms-body { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding-bottom: 12px; }
.ms-body input { -webkit-user-select: text; user-select: text; }
.ms-note { color: var(--cream); text-align: center; margin: 24px 8px; line-height: 1.5; }
.ms-note a, .ms-small a { color: var(--cream-strong); }
.ms-error { color: #ffd9a0; margin: 6px 0; }
.ms-small { color: var(--cream); font-size: 12px; line-height: 1.45; margin: 4px 0; }
.ms-card { background: var(--wood); border: 2px solid var(--panel-border); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; }
.ms-card-title { color: var(--cream-strong); font-size: 15px; margin-bottom: 4px; }
.ms-discord-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.kr2-btn.ms-discord-btn { background: #5865F2; border-color: #3c45a5; color: #fff; font-size: 14px; padding: 8px 16px; margin-top: 4px; }
.kr2-btn.ms-discord-btn:hover { background: #6d78f5; }
.ms-chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 10px; }
.ms-list { display: flex; flex-direction: column; gap: 8px; }
.ms-row { display: flex; gap: 10px; align-items: flex-start; background: var(--wood); border: 2px solid var(--panel-border); border-radius: 8px; padding: 8px; min-width: 0; }
.ms-thumb { width: 84px; height: 84px; flex: 0 0 84px; border-radius: 6px; background: #D0F3F9; overflow: hidden; }
.ms-thumb img, .ms-thumb canvas { width: 100%; height: 100%; object-fit: contain; display: block; }
.ms-info { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.ms-name { color: var(--cream-strong); font-size: 15px; word-break: break-word; }
.ms-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.ms-kind { font-size: 11px; color: var(--wood-dark); background: var(--cream); border-radius: 4px; padding: 0 6px; line-height: 1.6; }
.ms-kind.hat { background: #f3d27a; }
.ms-kind.trail { background: #b9dff2; }
.ms-badge { font-size: 11px; border-radius: 4px; padding: 0 6px; line-height: 1.6; color: #fff; border: 1px solid rgba(0,0,0,0.35); }
.ms-badge.ok { background: var(--green-fill); }
.ms-badge.wait { background: #c98a2b; }
.ms-badge.bad { background: var(--danger); }
.ms-acts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.ms-acts .kr2-btn { min-height: 34px; }
.ms-move { min-width: 36px; }
.ms-edit { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; padding: 8px; border: 1px dashed var(--cream); border-radius: 6px; }
.ms-field { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--cream-strong); }
.ms-field .kr2-input { width: 100%; max-width: 320px; min-height: 34px; font-size: 14px; }
.ms-field .ms-price { max-width: 140px; }
.ms-check { font-size: 13px; display: flex; align-items: center; gap: 6px; }
.ms-check input { width: 20px; height: 20px; }
.ms-edit .kr2-btn { align-self: flex-start; min-height: 34px; }
.ms-review-list { display: flex; flex-direction: column; gap: 12px; }
.ms-review { background: var(--wood); border: 2px solid var(--panel-border); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.ms-review-pics { display: flex; gap: 8px; align-items: flex-start; }
.ms-review-pics a { flex: 1 1 auto; min-width: 0; }
.ms-atlas { width: 100%; display: block; border-radius: 6px; border: 2px solid var(--panel-border);
  background: #fff repeating-conic-gradient(#d8d8d8 0 25%, #fff 0 50%) 0 0 / 16px 16px; image-rendering: auto; }
.ms-review-prev { width: 96px; height: 96px; flex: 0 0 96px; object-fit: contain; border-radius: 6px; background: #D0F3F9; border: 2px solid var(--panel-border); }
.ms-creator .ms-info { gap: 6px; }

@media (max-width: 600px), (max-height: 560px) {
  .ms-modal { align-items: stretch; }
  .ms-panel { width: 100%; max-width: none; height: 100%; max-height: none; border-radius: 0; border-width: 0; padding: 12px 12px 0; }
  .ms-head { padding-right: 40px; }
  .ms-tabs { flex-wrap: nowrap; overflow-x: auto; }
  .ms-tab { flex: 0 0 auto; min-height: 38px; font-size: 13px; }
  .ms-acts .kr2-btn, .ms-chips .kr2-btn { min-height: 40px; font-size: 13px; padding: 6px 12px; }
  .ms-move { min-width: 44px; }
  .ms-thumb { width: 72px; height: 72px; flex-basis: 72px; }
  .ms-review-pics { flex-direction: column; }
  .ms-review-prev { width: 120px; height: 120px; }
  .modal-close { width: 34px; height: 34px; }
}
