/* Tô Màu Online – công cụ tô màu & thẻ tranh
 * Biến màu có thể ghi đè trong theme (khai báo lại trên :root).
 */
:root{
  --tm-pink:#e2358c; --tm-pink-2:#e64589; --tm-hot:#ff2490;
  --tm-soft:#fde2f4; --tm-softer:#fef3f9; --tm-panel:#fdf6fe;
  --tm-line:#f6d9e6; --tm-ink:#3a2430; --tm-muted:#6a6c81; --tm-bg:#fdf7f9;
  --tm-radius:14px;
}

/* ---------- Nút ---------- */
.tomau-btn{display:inline-flex;align-items:center;justify-content:center;gap:8px;min-height:40px;padding:0 16px;border-radius:10px;border:1px solid var(--tm-line);background:#fff;color:var(--tm-ink);font:inherit;font-size:13px;font-weight:800;line-height:1.1;cursor:pointer;text-decoration:none;transition:background .15s,box-shadow .15s,transform .08s}
.tomau-btn:hover{border-color:var(--tm-pink);color:var(--tm-pink)}
.tomau-btn:active{transform:translateY(1px)}
.tomau-btn--primary,.tomau-btn--primary:hover{background:var(--tm-pink-2);border-color:var(--tm-pink-2);color:#fff;box-shadow:0 4px 10px rgba(230,69,137,.3)}
.tomau-btn--hot,.tomau-btn--hot:hover{background:var(--tm-hot);border-color:var(--tm-hot);color:#fff;box-shadow:0 4px 10px rgba(255,36,144,.25)}
.tomau-btn--sm{min-height:36px;padding:0 12px;font-size:12px}
.tomau button:focus-visible,.tomau-card :focus-visible,.tomau-fav:focus-visible{outline:3px solid var(--tm-pink);outline-offset:2px}
.tomau .sm{display:none}

/* ---------- Bố cục công cụ ---------- */
.tomau{display:grid;gap:12px;grid-template-columns:minmax(0,1fr) 360px;grid-template-areas:"head head" "stage panel";color:var(--tm-ink);margin:0 0 24px}
.tomau.has-aside{grid-template-columns:168px minmax(0,1fr) 360px;grid-template-areas:"head head head" "aside stage panel"}
.tomau *,.tomau *::before,.tomau *::after{box-sizing:border-box}
.tomau__head{grid-area:head;display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap}
.tomau__crumb{min-width:0}
.tomau__actions{display:flex;gap:10px;flex-wrap:wrap;margin-left:auto}
.tomau__actions .tomau-fav{color:var(--tm-pink)}
.tomau__aside{grid-area:aside;min-width:0}

/* Khung tranh */
.tomau__stage{grid-area:stage;position:relative;display:flex;align-items:center;min-width:0;background:#fff;border:1px solid var(--tm-line);border-radius:var(--tm-radius);padding:12px}
.tomau__viewport{display:flex;width:100%;max-height:600px;overflow:auto;overscroll-behavior:contain;scrollbar-width:thin}
.tomau__canvas{position:relative;margin:auto;flex:none;width:100%}
.tomau:not(.is-ready) .tomau__canvas{visibility:hidden;height:300px}
.tomau__canvas canvas{display:block;width:100%;height:auto}
.tomau__stroke,.tomau__lines{position:absolute;inset:0;height:100%!important}
.tomau__lines{touch-action:manipulation;cursor:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='28' viewBox='0 0 24 24' fill='%23fff' stroke='%23e2358c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m19 11-8-8-8.6 8.6a2 2 0 0 0 0 2.8l5.2 5.2a2 2 0 0 0 2.8 0Z'/%3E%3Cpath d='M22 20a2 2 0 1 1-4 0c0-1.6 1.7-2.4 2-4 .3 1.6 2 2.4 2 4Z' fill='%23e2358c'/%3E%3C/svg%3E") 20 24,pointer}
.tomau[data-tool=brush] .tomau__lines,.tomau[data-tool=eraser] .tomau__lines{touch-action:none;cursor:crosshair}
.tomau[data-tool=picker] .tomau__lines{cursor:copy}
.tomau.is-zoomed[data-tool=fill] .tomau__lines{cursor:grab}
.tomau__loading{position:absolute;inset:0;display:grid;place-items:center;margin:0;font-weight:800;color:var(--tm-muted)}
.tomau__loading[hidden],.tomau[hidden]{display:none!important} /* ẩn công cụ khi bé chưa chọn ảnh */

/* Bảng điều khiển bên phải */
.tomau__panel{grid-area:panel;background:var(--tm-panel);border-radius:var(--tm-radius);padding:8px 14px 16px;min-width:0}
.tomau__tabs{display:flex;gap:4px;border-bottom:1px solid var(--tm-line);margin:0 -2px 14px}
.tomau__tabs [role=tab]{display:inline-flex;align-items:center;gap:6px;height:42px;padding:0 12px;border:0;border-bottom:2px solid transparent;border-radius:10px 10px 0 0;background:transparent;color:var(--tm-muted);font:inherit;font-size:12px;font-weight:700;cursor:pointer;margin-bottom:-1px}
.tomau__tabs [aria-selected=true]{background:#fff;color:#dc4183;border-bottom-color:#dc4183;font-weight:800}
.tomau__swatches{display:grid;grid-template-columns:repeat(7,1fr);gap:10px}
.tomau__swatches--sm{gap:8px}
.tomau__swatch{aspect-ratio:1;width:100%;max-width:40px;border-radius:50%;border:2px solid #fff;background:var(--c);box-shadow:0 1px 3px rgba(0,0,0,.18);cursor:pointer;padding:0;transition:transform .1s}
.tomau__swatches--sm .tomau__swatch{max-width:30px}
.tomau__swatch:hover{transform:scale(1.08)}
.tomau__swatch.is-active{box-shadow:0 0 0 2px #fff,0 0 0 4px var(--tm-hot)}
.tomau__swatch[data-color="#FFFFFF"]{border-color:#e7e1e5}
.tomau__picker{display:flex;align-items:center;gap:12px;font-weight:800;font-size:13px;cursor:pointer}
.tomau__picker input{width:56px;height:56px;border:0;border-radius:12px;padding:0;background:none;cursor:pointer}
.tomau__picker small{display:block;font-weight:700;color:var(--tm-muted);font-family:ui-monospace,monospace}
.tomau__hint{grid-column:1/-1;font-size:12px;color:var(--tm-muted)}
.tomau__preset{display:grid;grid-template-columns:76px 1fr;align-items:center;gap:8px;margin-bottom:10px;font-size:12px;font-weight:800}
.tomau__label{display:block;margin:16px 0 8px;font-size:13px;font-weight:800}
.tomau__tools{display:grid;grid-template-columns:repeat(6,1fr);gap:8px}
.tomau__tool{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4px;height:58px;padding:4px 2px;border:1px solid var(--tm-line);border-radius:10px;background:#fff;color:var(--tm-ink);font:inherit;font-size:10px;white-space:nowrap;font-weight:700;cursor:pointer}
.tomau__tool:hover{border-color:var(--tm-pink)}
.tomau__tool.is-active{background:var(--tm-pink-2);border-color:var(--tm-pink-2);color:#fff;box-shadow:0 4px 10px rgba(230,69,137,.3)}
.tomau__tool:disabled{opacity:.45;cursor:default;border-color:var(--tm-line)}
.tomau__size{display:flex;align-items:center;gap:12px}
.tomau__size input{flex:1;accent-color:var(--tm-hot)}
.tomau__size output{min-width:52px;padding:4px 8px;border:1px solid var(--tm-line);border-radius:8px;background:#fff;text-align:center;font-size:12px;font-weight:700}
.tomau__brushes{display:grid;grid-template-columns:repeat(3,1fr);gap:10px;margin-top:12px}
.tomau__brush{display:grid;place-items:center;height:38px;border:1px solid var(--tm-line);border-radius:8px;background:#fff;cursor:pointer;padding:0}
.tomau__brush img{width:66px;height:24px;object-fit:contain}
.tomau__brush.is-active{border:2px solid var(--tm-pink)}
.tomau__zoom{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin-top:16px}
.tomau__zoom .tomau__label{margin:0 4px 0 0}
.tomau__zoomctl{display:inline-flex;align-items:center;border:1px solid var(--tm-line);border-radius:10px;background:#fff;overflow:hidden}
.tomau__zoomctl button{width:32px;height:36px;border:0;background:none;color:var(--tm-ink);cursor:pointer;display:grid;place-items:center}
.tomau__zoomctl button:hover{color:var(--tm-pink)}
.tomau__zoomctl output{min-width:48px;height:36px;line-height:36px;text-align:center;font-size:12px;font-weight:700;border-left:1px solid var(--tm-line);border-right:1px solid var(--tm-line)}
.tomau__zoom .tomau-btn{margin-left:auto;padding:0 10px}
.tomau__danger{display:grid;grid-template-columns:1fr 1fr;gap:10px;margin-top:18px}

/* Hộp xem tranh mẫu & thông báo */
.tomau__dialog{max-width:min(560px,92vw);border:0;border-radius:18px;padding:20px;color:var(--tm-ink);text-align:center}
.tomau__dialog::backdrop{background:rgba(58,36,48,.55)}
.tomau__dialog img{display:block;max-width:100%;max-height:70vh;margin:0 auto 10px;object-fit:contain}
.tomau__dialog p{margin:0;font-weight:700;color:var(--tm-muted)}
.tomau__dialog form{position:absolute;top:8px;right:8px;margin:0}
.tomau__close{width:36px;height:36px;border:0;border-radius:50%;background:var(--tm-softer);color:var(--tm-ink);cursor:pointer;display:grid;place-items:center}
.tomau__toast{position:fixed;left:50%;bottom:calc(24px + env(safe-area-inset-bottom));transform:translate(-50%,20px);max-width:min(480px,92vw);padding:10px 18px;border-radius:999px;background:var(--tm-ink);color:#fff;font-size:14px;font-weight:700;text-align:center;opacity:0;pointer-events:none;transition:opacity .2s,transform .2s;z-index:10000}
.tomau__toast.is-show{opacity:1;transform:translate(-50%,0)}

/* Toàn màn hình */
html.tomau-noscroll{overflow:hidden}
.tomau.is-full{position:fixed;inset:0;z-index:9999;margin:0;padding:12px;background:var(--tm-bg);overflow:auto;grid-template-columns:minmax(0,1fr) 340px;grid-template-areas:"head head" "stage panel";align-content:start}
.tomau.is-full .tomau__aside,.tomau.is-full .tomau__crumb{display:none}
.tomau.is-full .tomau__viewport{max-height:calc(100vh - 110px)}

/* Máy tính bảng: cột trái xuống dưới */
@media (max-width:1100px){
  .tomau.has-aside{grid-template-columns:minmax(0,1fr) 320px;grid-template-areas:"head head" "aside aside" "stage panel"} /* hàng ảnh trong bộ nằm trên khung tranh */
}
/* Điện thoại */
@media (max-width:860px){
  .tomau,.tomau.has-aside,.tomau.is-full{grid-template-columns:minmax(0,1fr);grid-template-areas:"crumb" "aside" "stage" "actions" "panel"}
  .tomau__head{display:contents}
  .tomau__crumb{grid-area:crumb}
  .tomau__actions{grid-area:actions;display:grid;grid-template-columns:repeat(5,1fr);gap:8px;margin:0}
  .tomau__actions .tomau-btn{flex-direction:column;gap:4px;min-height:58px;padding:8px 2px;font-size:11px}
  .tomau .lg{display:none}.tomau .sm{display:inline}
  .tomau__stage{padding:8px}
  .tomau__viewport{max-height:68vh}
  .tomau__panel{padding:6px 12px 14px}
  .tomau__tabs [role=tab]{flex:1;justify-content:center;padding:0 6px;font-size:11.5px;white-space:nowrap}
  .tomau__tools{gap:6px}
  .tomau__tool{height:54px;font-size:10px}
  .tomau.is-full{grid-template-areas:"stage" "panel"}
  .tomau.is-full .tomau__actions{display:none}
  .tomau.is-full .tomau__viewport{max-height:60vh}
}
@media (max-width:380px){
  .tomau__swatches{gap:7px}
  .tomau__tool span{font-size:9px}
}

/* ---------- Lưới & thẻ tranh ---------- */
.tomau-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:12px}
.tomau-grid--row{grid-template-columns:none;grid-auto-flow:column;grid-auto-columns:minmax(132px,1fr);overflow-x:auto;scroll-snap-type:x proximity;padding-bottom:6px;scrollbar-width:thin}
.tomau-grid--row > *{scroll-snap-align:start}
.tomau-card{position:relative;display:flex;flex-direction:column;min-width:0;background:#fff;border:1px solid var(--tm-line);border-radius:12px;padding:8px;transition:box-shadow .15s,transform .15s}
.tomau-card:hover{box-shadow:0 6px 18px rgba(226,53,140,.16);transform:translateY(-2px)}
.tomau-card__link{display:flex;flex-direction:column;gap:6px;color:var(--tm-ink);text-decoration:none}
.tomau-card__link::after{content:"";position:absolute;inset:0;border-radius:inherit}
.tomau-card__img{display:block;aspect-ratio:1;overflow:hidden;border-radius:8px;background:#fff}
.tomau-card__img img{display:block;width:100%;height:100%;object-fit:contain}
.tomau-card__noimg{display:grid;place-items:center;width:100%;height:100%;color:var(--tm-line)}
.tomau-card__title{font-size:13px;font-weight:800;line-height:1.3;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.tomau-card__tags{display:flex;gap:4px;flex-wrap:wrap;margin-top:6px}
.tomau-card .tag{font-size:10.5px;font-weight:700;padding:2px 8px;border-radius:999px;background:#f3eef5;color:#795982}
.tomau-card .tag--de{background:#e3f7e7;color:#2a6a3a}
.tomau-card .tag--trung-binh{background:#fff1cf;color:#8a5a00}
.tomau-card .tag--kho{background:#ffe1e1;color:#a12a2a}
.tomau-card__badge{position:absolute;top:8px;left:8px;z-index:2;padding:2px 7px;border-radius:6px;background:var(--tm-pink);color:#fff;font-size:10px;font-weight:900;letter-spacing:.3px}
.tomau-card__img{position:relative}
.tomau-card__count{position:absolute;right:6px;bottom:6px;padding:2px 8px;border-radius:999px;background:rgba(58,36,48,.78);color:#fff;font-size:10.5px;font-weight:800} /* số ảnh trong bộ */
.tomau-fav:not(.tomau-btn){position:absolute;top:8px;right:8px;z-index:3;display:grid;place-items:center;width:28px;height:28px;padding:0;border:0;border-radius:50%;background:rgba(255,255,255,.92);color:var(--tm-pink);cursor:pointer;box-shadow:0 1px 3px rgba(0,0,0,.08)}
.tomau-fav.is-on svg{fill:currentColor}
.tomau-empty{color:var(--tm-muted);font-weight:600}

@media (prefers-reduced-motion:reduce){.tomau *,.tomau-card{transition:none!important}}
