MiniMax M3.1 Flash
by MiniMaxReasoningClean
Running live in a sandboxed frame. Click inside it before using the keyboard.
How it went
- Total time
- 27.6 s
- Cost
- $0.0052
- Output tokens
- 8,644
- Spent thinking
- 0 tokens
- Speed
- 320.4 tok/s
- Console errors
- 0
- First token after
- 601 ms
- First visible text after
- 601 ms
- Prompt tokens
- 678
- Code size
- 27.7 KB
- Finish reason
- stop
- Served by
- Nebius
- Model id
minimax/minimax-m3.1-flash- Reasoning sent
{"effort":"xhigh"}- Max output
- 64,000 tokens
- Generated
- Nov 11, 2026
What it was asked
The prompt
Build an interactive Kanban board in vanilla HTML, CSS and JavaScript (no framework, no library). Requirements: - Three columns: "To do", "In progress", "Done", each showing its card count. - Pre-populate the board with 6 realistic cards spread across the columns so the first screenshot looks alive. - Each card has a title and a priority (low / medium / high) shown as a colored badge. - Add a card through a small modal form (title required), and delete a card with a button on it. - Drag and drop cards between columns with the mouse, with a clear visual drop indicator. - A search field that filters cards live by title. - A light / dark theme toggle. - State lives in memory only (no storage APIs).
System prompt, sent with every prompt
You are generating a self-contained web demo. It will be rendered automatically in a sandboxed iframe and compared side by side with the output of other AI models given the exact same task. Output rules: - Reply with exactly ONE fenced code block containing the complete file: ```html (or ```svg when the task asks for an SVG). No text before or after the code block. - Everything must be inline: CSS in <style>, JavaScript in <script>. No external files, images, fonts or network requests, except the CDN URLs explicitly allowed by the task. - Do not use localStorage, sessionStorage, cookies, IndexedDB, alert(), confirm(), prompt() or window.open(): they are blocked in the sandbox and will throw. - The page must look right in a 1280×800 viewport and adapt gracefully down to 375px wide. No horizontal scrollbar. - Something meaningful must be visible on first paint: a screenshot is taken automatically about 3 seconds after load, without any interaction. - Everything that makes the demo interesting must be visible within the first seconds: nothing hidden behind a high score, a later level or a long play session. - Games must start in a self-playing demo mode (a simple AI plays) behind a "Click or press a key to start" message, so the game can be judged in action without playing. - The iframe only receives keyboard events after the user clicks it: if the demo uses the keyboard, display a clear "Click or press a key to start" message. - The code must run with zero errors in the console of the latest Chrome.
Code run-1.html · 849 lines
<!DOCTYPE html>
<html lang="en" data-theme="light">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Kanban Board</title>
<style>
:root {
--bg: #eef1f6;
--bg-grad: radial-gradient(1200px 600px at 10% -10%, #dfe7f5 0%, transparent 60%),
radial-gradient(900px 500px at 100% 0%, #e8e3f6 0%, transparent 55%);
--panel: #ffffff;
--panel-2: #f7f8fb;
--text: #1b2230;
--muted: #6b7488;
--line: #e2e6ee;
--accent: #4f6ef7;
--accent-soft: rgba(79, 110, 247, .12);
--shadow: 0 1px 2px rgba(19, 25, 40, .06), 0 8px 24px rgba(19, 25, 40, .07);
--shadow-lg: 0 18px 50px rgba(19, 25, 40, .22);
--hi: #e5484d;
--me: #f5a524;
--lo: #30a46c;
--hi-bg: rgba(229, 72, 77, .12);
--me-bg: rgba(245, 165, 36, .15);
--lo-bg: rgba(48, 164, 108, .14);
--drop: #4f6ef7;
}
html[data-theme="dark"] {
--bg: #0d1017;
--bg-grad: radial-gradient(1100px 600px at 0% -10%, #18233a 0%, transparent 60%),
radial-gradient(900px 500px at 100% 0%, #241d3a 0%, transparent 55%);
--panel: #151a23;
--panel-2: #1b2130;
--text: #e6eaf3;
--muted: #93a0b8;
--line: #262d3b;
--accent: #7b91ff;
--accent-soft: rgba(123, 145, 255, .16);
--shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 28px rgba(0,0,0,.35);
--shadow-lg: 0 20px 60px rgba(0,0,0,.6);
--hi: #ff6369;
--me: #ffb224;
--lo: #3dd68c;
--hi-bg: rgba(255, 99, 105, .16);
--me-bg: rgba(255, 178, 36, .16);
--lo-bg: rgba(61, 214, 140, .15);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
margin: 0;
font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
background: var(--bg);
background-image: var(--bg-grad);
color: var(--text);
-webkit-font-smoothing: antialiased;
transition: background-color .25s ease, color .25s ease;
}
.wrap {
max-width: 1240px;
margin: 0 auto;
padding: 26px 22px 48px;
}
/* ---------- Header ---------- */
header.top {
display: flex;
align-items: center;
gap: 16px;
flex-wrap: wrap;
margin-bottom: 22px;
}
.brand { display: flex; align-items: center; gap: 13px; }
.logo {
width: 44px; height: 44px; border-radius: 13px;
background: linear-gradient(135deg, var(--accent), #8f5cf6);
display: grid; place-items: center;
box-shadow: 0 8px 22px var(--accent-soft);
flex: none;
}
.logo svg { width: 24px; height: 24px; }
.brand h1 {
margin: 0; font-size: 21px; letter-spacing: -.3px; font-weight: 700;
}
.brand p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.spacer { flex: 1 1 auto; }
.search {
position: relative;
flex: 1 1 240px;
max-width: 340px;
}
.search svg {
position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
width: 16px; height: 16px; color: var(--muted); pointer-events: none;
}
.search input {
width: 100%;
padding: 10px 34px 10px 35px;
border-radius: 11px;
border: 1px solid var(--line);
background: var(--panel);
color: var(--text);
font-size: 14px;
outline: none;
box-shadow: var(--shadow);
transition: border-color .18s, box-shadow .18s;
}
.search input:focus {
border-color: var(--accent);
box-shadow: 0 0 0 3px var(--accent-soft);
}
.search .clear {
position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
border: 0; background: transparent; color: var(--muted); cursor: pointer;
font-size: 16px; line-height: 1; padding: 4px 6px; border-radius: 7px;
display: none;
}
.search .clear:hover { background: var(--panel-2); color: var(--text); }
.search.has-value .clear { display: block; }
.icon-btn {
display: inline-flex; align-items: center; gap: 8px;
height: 40px; padding: 0 14px;
border-radius: 11px;
border: 1px solid var(--line);
background: var(--panel);
color: var(--text);
font-size: 13.5px; font-weight: 600;
cursor: pointer;
box-shadow: var(--shadow);
transition: transform .12s ease, border-color .18s, background .18s;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.icon-btn:active { transform: translateY(1px); }
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn.primary {
background: var(--accent); border-color: var(--accent); color: #fff;
box-shadow: 0 8px 20px var(--accent-soft);
}
.icon-btn.primary:hover { filter: brightness(1.07); color: #fff; }
/* ---------- Board ---------- */
.board {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 18px;
align-items: start;
}
.col {
background: var(--panel-2);
border: 1px solid var(--line);
border-radius: 16px;
padding: 12px 12px 14px;
min-height: 300px;
transition: background .18s, border-color .18s, box-shadow .18s;
}
.col.is-over {
background: var(--accent-soft);
border-color: var(--accent);
box-shadow: inset 0 0 0 1px var(--accent);
}
.col-head {
display: flex; align-items: center; gap: 9px;
padding: 4px 4px 12px;
}
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.col[data-col="todo"] .dot { background: #8b95ab; }
.col[data-col="doing"] .dot { background: var(--me); }
.col[data-col="done"] .dot { background: var(--lo); }
.col-title { font-size: 14px; font-weight: 700; letter-spacing: .1px; }
.count {
font-size: 11.5px; font-weight: 700;
background: var(--panel);
border: 1px solid var(--line);
color: var(--muted);
border-radius: 999px;
padding: 2px 9px;
min-width: 24px; text-align: center;
}
.col.add-col { display: flex; align-items: center; justify-content: center; }
.cards { display: flex; flex-direction: column; gap: 10px; min-height: 46px; }
.card {
position: relative;
background: var(--panel);
border: 1px solid var(--line);
border-radius: 12px;
padding: 11px 12px 11px 14px;
box-shadow: var(--shadow);
cursor: grab;
transition: transform .14s ease, box-shadow .16s ease, opacity .16s;
user-select: none;
}
.card::before {
content: ""; position: absolute; left: 0; top: 10px; bottom: 10px;
width: 3px; border-radius: 0 3px 3px 0;
background: var(--pri, #8b95ab);
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.card.dragging { opacity: .38; cursor: grabbing; }
.card-title {
font-size: 13.8px; font-weight: 600; line-height: 1.35;
margin: 0 0 9px; padding-right: 24px;
word-break: break-word;
}
.card-foot { display: flex; align-items: center; gap: 8px; }
.badge {
font-size: 10.5px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase;
padding: 3px 8px; border-radius: 999px;
}
.badge.high { background: var(--hi-bg); color: var(--hi); }
.badge.medium { background: var(--me-bg); color: var(--me); }
.badge.low { background: var(--lo-bg); color: var(--lo); }
.meta { font-size: 11px; color: var(--muted); margin-left: auto; white-space: nowrap; }
.del {
position: absolute; top: 7px; right: 7px;
width: 24px; height: 24px; border-radius: 7px;
border: 0; background: transparent; color: var(--muted);
cursor: pointer; display: grid; place-items: center;
opacity: 0; transition: opacity .15s, background .15s, color .15s;
}
.card:hover .del, .del:focus-visible { opacity: 1; }
.del:hover { background: var(--hi-bg); color: var(--hi); }
.del svg { width: 14px; height: 14px; }
.empty {
border: 1.5px dashed var(--line);
border-radius: 12px;
padding: 18px 12px;
text-align: center;
color: var(--muted);
font-size: 12.5px;
}
/* Drop indicator */
.drop-line {
height: 3px; border-radius: 3px;
background: var(--drop);
box-shadow: 0 0 0 4px var(--accent-soft);
margin: -2px 0;
animation: pulse .9s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .45 } }
/* ---------- Modal ---------- */
.overlay {
position: fixed; inset: 0;
background: rgba(12, 16, 26, .48);
backdrop-filter: blur(3px);
display: grid; place-items: center;
padding: 20px;
z-index: 50;
opacity: 0; pointer-events: none;
transition: opacity .18s ease;
}
.overlay.open { opacity: 1; pointer-events: auto; }
.modal {
width: 100%; max-width: 420px;
background: var(--panel);
border: 1px solid var(--line);
border-radius: 18px;
box-shadow: var(--shadow-lg);
padding: 22px;
transform: translateY(10px) scale(.98);
transition: transform .2s cubic-bezier(.2,.8,.3,1);
}
.overlay.open .modal { transform: none; }
.modal h2 { margin: 0 0 4px; font-size: 18px; }
.modal .sub { margin: 0 0 18px; color: var(--muted); font-size: 13px; }
label { display: block; font-size: 12.5px; font-weight: 700; margin-bottom: 7px; }
input[type="text"], select {
width: 100%; padding: 11px 12px;
border-radius: 10px; border: 1px solid var(--line);
background: var(--panel-2); color: var(--text);
font-size: 14px; font-family: inherit; outline: none;
transition: border-color .16s, box-shadow .16s;
}
input[type="text"]:focus, select:focus {
border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.field { margin-bottom: 16px; }
.err { color: var(--hi); font-size: 12px; margin-top: 6px; display: none; }
.err.show { display: block; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.btn {
padding: 10px 18px; border-radius: 10px; border: 1px solid var(--line);
background: var(--panel-2); color: var(--text);
font-size: 13.5px; font-weight: 600; cursor: pointer; font-family: inherit;
transition: filter .15s, border-color .15s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
/* Toast */
.toast {
position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px);
background: var(--text); color: var(--bg);
padding: 10px 18px; border-radius: 999px; font-size: 13px; font-weight: 600;
box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none;
transition: opacity .2s, transform .2s; z-index: 60;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.hint {
margin-top: 20px; text-align: center; color: var(--muted); font-size: 12px;
}
.hint kbd {
background: var(--panel); border: 1px solid var(--line); border-bottom-width: 2px;
border-radius: 6px; padding: 1px 6px; font-size: 11px; font-family: inherit;
}
@media (max-width: 900px) {
.board { grid-template-columns: 1fr; }
.col { min-height: 120px; }
}
@media (max-width: 560px) {
.wrap { padding: 18px 14px 40px; }
header.top { gap: 10px; }
.search { max-width: none; order: 3; flex-basis: 100%; }
.brand h1 { font-size: 18px; }
.hide-sm { display: none; }
}
</style>
</head>
<body>
<div class="wrap">
<header class="top">
<div class="brand">
<div class="logo">
<svg viewBox="0 0 24 24" fill="none" stroke="#fff" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
<rect x="3" y="3" width="5.5" height="13" rx="1.6"/>
<rect x="9.5" y="3" width="5" height="18" rx="1.6" opacity=".8"/>
<rect x="16" y="3" width="5" height="9" rx="1.6" opacity=".6"/>
</svg>
</div>
<div>
<h1>Product Sprint Board</h1>
<p>Q3 launch · updated just now</p>
</div>
</div>
<div class="spacer"></div>
<div class="search" id="searchWrap">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round">
<circle cx="11" cy="11" r="7"/><path d="M20 20l-3.2-3.2"/>
</svg>
<input id="search" type="text" placeholder="Search cards by title…" aria-label="Search cards">
<button class="clear" id="searchClear" title="Clear" aria-label="Clear search">✕</button>
</div>
<button class="icon-btn" id="themeBtn" title="Toggle light / dark theme" aria-label="Toggle theme">
<svg id="themeIcon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round">
<circle cx="12" cy="12" r="4.2"/>
<path d="M12 2v2.5M12 19.5V22M2 12h2.5M19.5 12H22M4.9 4.9l1.8 1.8M17.3 17.3l1.8 1.8M19.1 4.9l-1.8 1.8M6.7 17.3l-1.8 1.8"/>
</svg>
<span class="hide-sm" id="themeLabel">Dark</span>
</button>
<button class="icon-btn primary" id="addBtn">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round">
<path d="M12 5v14M5 12h14"/>
</svg>
<span class="hide-sm">Add card</span>
</button>
</header>
<main class="board" id="board">
<section class="col" data-col="todo">
<div class="col-head">
<span class="dot"></span>
<span class="col-title">To do</span>
<span class="count" data-count="todo">0</span>
</div>
<div class="cards" data-list="todo"></div>
</section>
<section class="col" data-col="doing">
<div class="col-head">
<span class="dot"></span>
<span class="col-title">In progress</span>
<span class="count" data-count="doing">0</span>
</div>
<div class="cards" data-list="doing"></div>
</section>
<section class="col" data-col="done">
<div class="col-head">
<span class="dot"></span>
<span class="col-title">Done</span>
<span class="count" data-count="done">0</span>
</div>
<div class="cards" data-list="done"></div>
</section>
</main>
<p class="hint">Drag cards between columns · press <kbd>N</kbd> to add a card · press <kbd>/</kbd> to search</p>
</div>
<div class="overlay" id="overlay">
<div class="modal" role="dialog" aria-modal="true" aria-labelledby="modalTitle">
<h2 id="modalTitle">New card</h2>
<p class="sub">Add a task to the board.</p>
<form id="cardForm" novalidate>
<div class="field">
<label for="titleInput">Title <span style="color:var(--hi)">*</span></label>
<input type="text" id="titleInput" placeholder="e.g. Design onboarding flow" autocomplete="off">
<div class="err" id="titleErr">Please enter a title for the card.</div>
</div>
<div class="field">
<label for="priInput">Priority</label>
<select id="priInput">
<option value="high">High</option>
<option value="medium" selected>Medium</option>
<option value="low">Low</option>
</select>
</div>
<div class="field">
<label for="colInput">Column</label>
<select id="colInput">
<option value="todo">To do</option>
<option value="doing">In progress</option>
<option value="done">Done</option>
</select>
</div>
<div class="modal-actions">
<button type="button" class="btn" id="cancelBtn">Cancel</button>
<button type="submit" class="btn primary" id="submitBtn">Add card</button>
</div>
</form>
</div>
</div>
<div class="toast" id="toast"></div>
<script>
(function () {
"use strict";
var COLS = ["todo", "doing", "done"];
var PRI_COLORS = { high: "var(--hi)", medium: "var(--me)", low: "var(--lo)" };
var state = {
cards: [
{ id: 1, title: "Design onboarding flow for new teams", priority: "high", col: "todo", tag: "Design" },
{ id: 2, title: "Write API docs for the public endpoints", priority: "medium", col: "todo", tag: "Docs" },
{ id: 3, title: "Fix flaky checkout e2e test on CI", priority: "high", col: "doing", tag: "Bug" },
{ id: 4, title: "Migrate settings page to the new design system", priority: "medium", col: "doing", tag: "Frontend" },
{ id: 5, title: "Set up release pipeline for staging", priority: "low", col: "done", tag: "DevOps" },
{ id: 6, title: "Interview 5 beta users about the dashboard", priority: "medium", col: "done", tag: "Research" }
],
query: "",
nextId: 7
};
var board = document.getElementById("board");
var overlay = document.getElementById("overlay");
var form = document.getElementById("cardForm");
var titleInput = document.getElementById("titleInput");
var priInput = document.getElementById("priInput");
var colInput = document.getElementById("colInput");
var titleErr = document.getElementById("titleErr");
var searchInput = document.getElementById("search");
var searchWrap = document.getElementById("searchWrap");
var searchClear = document.getElementById("searchClear");
var themeBtn = document.getElementById("themeBtn");
var themeLabel = document.getElementById("themeLabel");
var toastEl = document.getElementById("toast");
/* ---------------- Rendering ---------------- */
function matches(card) {
var q = state.query.trim().toLowerCase();
if (!q) return true;
return card.title.toLowerCase().indexOf(q) !== -1;
}
function cardEl(card) {
var el = document.createElement("article");
el.className = "card";
el.setAttribute("draggable", "true");
el.dataset.id = card.id;
el.style.setProperty("--pri", PRI_COLORS[card.priority] || "var(--lo)");
var title = document.createElement("h3");
title.className = "card-title";
title.textContent = card.title;
el.appendChild(title);
var foot = document.createElement("div");
foot.className = "card-foot";
var badge = document.createElement("span");
badge.className = "badge " + card.priority;
badge.textContent = card.priority;
foot.appendChild(badge);
if (card.tag) {
var tag = document.createElement("span");
tag.className = "meta";
tag.style.marginLeft = "0";
tag.textContent = card.tag;
foot.appendChild(tag);
}
el.appendChild(foot);
var del = document.createElement("button");
del.className = "del";
del.type = "button";
del.title = "Delete card";
del.setAttribute("aria-label", "Delete card: " + card.title);
del.innerHTML = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"><path d="M4 7h16M9.5 7V5h5v2M6.5 7l1 13h9l1-13"/></svg>';
del.addEventListener("click", function (e) {
e.stopPropagation();
deleteCard(card.id);
});
el.appendChild(del);
return el;
}
function render() {
COLS.forEach(function (col) {
var list = board.querySelector('[data-list="' + col + '"]');
var visible = state.cards.filter(function (c) { return c.col === col && matches(c); });
var total = state.cards.filter(function (c) { return c.col === col; }).length;
// remove old nodes
while (list.firstChild) list.removeChild(list.firstChild);
if (!visible.length) {
var empty = document.createElement("div");
empty.className = "empty";
empty.textContent = state.query.trim()
? "No matching cards"
: (total ? "No cards here" : "Drop a card here");
list.appendChild(empty);
} else {
visible.forEach(function (c) { list.appendChild(cardEl(c)); });
}
var countEl = board.querySelector('[data-count="' + col + '"]');
countEl.textContent = total;
countEl.title = total + " card" + (total === 1 ? "" : "s");
});
}
function toast(msg) {
toastEl.textContent = msg;
toastEl.classList.add("show");
clearTimeout(toast._t);
toast._t = setTimeout(function () { toastEl.classList.remove("show"); }, 1800);
}
/* ---------------- Card actions ---------------- */
function addCard(title, priority, col) {
state.cards.push({
id: state.nextId++,
title: title,
priority: priority,
col: col,
tag: ""
});
render();
}
function deleteCard(id) {
var card = state.cards.find(function (c) { return c.id === id; });
if (!card) return;
state.cards = state.cards.filter(function (c) { return c.id !== id; });
render();
toast("Deleted \"" + card.title + "\"");
}
/* ---------------- Drag & drop ---------------- */
var dragId = null;
var dragEl = null;
var indicator = null;
var lastCol = null;
function makeIndicator() {
var ind = document.createElement("div");
ind.className = "drop-line";
return ind;
}
function clearIndicator() {
if (indicator && indicator.parentNode) indicator.parentNode.removeChild(indicator);
indicator = null;
lastCol = null;
}
function listFor(el) {
var node = el;
while (node && node !== board) {
if (node.classList && node.classList.contains("cards")) return node;
node = node.parentNode;
}
return null;
}
function colFor(node) {
var n = node;
while (n && n !== board) {
if (n.classList && n.classList.contains("col")) return n;
n = n.parentNode;
}
return null;
}
board.addEventListener("dragstart", function (e) {
var card = e.target.closest(".card");
if (!card) return;
dragId = Number(card.dataset.id);
dragEl = card;
card.classList.add("dragging");
if (e.dataTransfer) {
e.dataTransfer.effectAllowed = "move";
try { e.dataTransfer.setData("text/plain", String(dragId)); } catch (err) {}
}
});
board.addEventListener("dragend", function () {
if (dragEl) dragEl.classList.remove("dragging");
clearIndicator();
COLS.forEach(function (c) {
var col = board.querySelector('[data-col="' + c + '"]');
if (col) col.classList.remove("is-over");
});
dragId = null; dragEl = null;
});
board.addEventListener("dragover", function (e) {
if (dragId === null) return;
e.preventDefault();
if (e.dataTransfer) e.dataTransfer.dropEffect = "move";
var list = listFor(e.target);
if (!list) return;
var col = colFor(list);
if (!col) return;
COLS.forEach(function (c) {
var cc = board.querySelector('[data-col="' + c + '"]');
if (cc) cc.classList.toggle("is-over", cc === col);
});
// remove empty placeholder while dragging
var empty = list.querySelector(".empty");
if (empty) empty.remove();
var after = null;
var cards = Array.prototype.filter.call(list.querySelectorAll(".card:not(.dragging)"), function (c) {
return c !== dragEl;
});
for (var i = 0; i < cards.length; i++) {
var box = cards[i].getBoundingClientRect();
var offset = e.clientY - box.top - box.height / 2;
if (offset < 0) { after = cards[i]; break; }
}
if (!indicator) indicator = makeIndicator();
if (after) {
if (indicator.nextSibling !== after || indicator.parentNode !== list) {
list.insertBefore(indicator, after);
}
} else {
if (indicator.parentNode !== list || indicator.nextSibling) {
list.appendChild(indicator);
}
}
lastCol = list.dataset.list;
});
board.addEventListener("dragleave", function (e) {
var list = listFor(e.target);
if (!list) return;
var rect = list.getBoundingClientRect();
if (e.clientY < rect.top || e.clientY > rect.bottom) {
// leaving the list vertically
}
});
board.addEventListener("drop", function (e) {
if (dragId === null) return;
e.preventDefault();
var list = listFor(e.target);
if (!list) return;
var targetCol = list.dataset.list;
var card = state.cards.find(function (c) { return c.id === dragId; });
if (!card) return;
// determine index based on indicator position
var index = 0;
var kids = Array.prototype.slice.call(list.children);
var before = null;
if (indicator && indicator.parentNode === list) {
var idx = kids.indexOf(indicator);
before = idx;
} else {
before = kids.filter(function (k) { return k.classList && k.classList.contains("card") && k !== dragEl; }).length;
}
var sameCol = card.col === targetCol;
var colCards = state.cards.filter(function (c) { return c.col === targetCol && c.id !== card.id; });
colCards.splice(Math.min(before, colCards.length), 0, card);
// rebuild order globally for the affected columns
var order = [];
COLS.forEach(function (c) {
state.cards.forEach(function (card2) {
if (card2.col === c && card2.id !== card.id) order.push(card2);
});
});
// simpler: assign positions per column list
var newOrder = [];
COLS.forEach(function (c) {
if (c === targetCol) {
colCards.forEach(function (card2) { newOrder.push(card2); });
} else {
state.cards.forEach(function (card2) {
if (card2.col === c) newOrder.push(card2);
});
}
});
state.cards = newOrder;
card.col = targetCol;
clearIndicator();
COLS.forEach(function (c) {
var cc = board.querySelector('[data-col="' + c + '"]');
if (cc) cc.classList.remove("is-over");
});
dragId = null;
if (dragEl) dragEl.classList.remove("dragging");
dragEl = null;
render();
if (!sameCol) toast("Moved to " + colName(targetCol));
});
function colName(c) {
return c === "todo" ? "To do" : c === "doing" ? "In progress" : "Done";
}
/* ---------------- Search ---------------- */
searchInput.addEventListener("input", function () {
state.query = searchInput.value;
searchWrap.classList.toggle("has-value", searchInput.value.length > 0);
render();
});
searchClear.addEventListener("click", function () {
searchInput.value = "";
state.query = "";
searchWrap.classList.remove("has-value");
render();
searchInput.focus();
});
/* ---------------- Modal ---------------- */
function openModal() {
overlay.classList.add("open");
titleInput.value = "";
priInput.value = "medium";
colInput.value = "todo";
titleErr.classList.remove("show");
setTimeout(function () { titleInput.focus(); }, 60);
}
function closeModal() {
overlay.classList.remove("open");
}
document.getElementById("addBtn").addEventListener("click", openModal);
document.getElementById("cancelBtn").addEventListener("click", closeModal);
overlay.addEventListener("mousedown", function (e) {
if (e.target === overlay) closeModal();
});
form.addEventListener("submit", function (e) {
e.preventDefault();
var v = titleInput.value.trim();
if (!v) {
titleErr.classList.add("show");
titleInput.focus();
return;
}
addCard(v, priInput.value, colInput.value);
closeModal();
toast("Added \"" + v + "\"");
});
titleInput.addEventListener("input", function () {
if (titleInput.value.trim()) titleErr.classList.remove("show");
});
/* ---------------- Theme ---------------- */
function setTheme(t) {
document.documentElement.setAttribute("data-theme", t);
var dark = t === "dark";
themeLabel.textContent = dark ? "Light" : "Dark";
var icon = document.getElementById("themeIcon");
if (dark) {
icon.innerHTML = '<path d="M20.5 14.5A8.5 8.5 0 1 1 9.5 3.5a7 7 0 0 0 11 11z"/>';
} else {
icon.innerHTML = '<circle cx="12" cy="12" r="4.2"/><path d="M12 2v2.5M12 19.5V22M2 12h2.5M19.5 12H22M4.9 4.9l1.8 1.8M17.3 17.3l1.8 1.8M19.1 4.9l-1.8 1.8M6.7 17.3l-1.8 1.8"/>';
}
}
themeBtn.addEventListener("click", function () {
var next = document.documentElement.getAttribute("data-theme") === "dark" ? "light" : "dark";
setTheme(next);
});
/* ---------------- Keyboard ---------------- */
document.addEventListener("keydown", function (e) {
if (e.key === "Escape") {
closeModal();
return;
}
var tag = (e.target.tagName || "").toLowerCase();
var typing = tag === "input" || tag === "textarea" || tag === "select";
if (typing) return;
if (e.key === "/" ) { e.preventDefault(); searchInput.focus(); }
if (e.key === "n" || e.key === "N") { e.preventDefault(); openModal(); }
});
/* ---------------- Init ---------------- */
render();
setTheme("light");
})();
</script>
</body>
</html>