GPT-6.1 Terra
by OpenAIReasoningClean
Running live in a sandboxed frame. Click inside it before using the keyboard.
How it went
- Total time
- 1 min 35 s
- Cost
- $0.043
- Output tokens
- 8,482
- Spent thinking
- 0 tokens
- Speed
- 90.7 tok/s
- Console errors
- 0
- First token after
- 1.2 s
- First visible text after
- 1.2 s
- Prompt tokens
- 493
- Code size
- 26.5 KB
- Finish reason
- stop
- Served by
- OpenAI
- Model id
openai/gpt-6.1-terra- Reasoning sent
{"effort":"none"}- Max output
- 128,000 tokens
- Generated
- Nov 12, 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 · 418 lines
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flowboard — Team Kanban</title>
<style>
:root {
color-scheme: light;
--bg: #f6f7fb;
--surface: #ffffff;
--surface-soft: #f1f3f8;
--column: #eef0f5;
--text: #20243a;
--muted: #8c92a5;
--muted-strong: #6d7489;
--border: #e7e9f0;
--shadow: 0 2px 5px rgba(32, 36, 58, .025), 0 8px 22px rgba(32, 36, 58, .035);
--purple: #7065e9;
--purple-soft: #eeecff;
--input: #fff;
}
* { box-sizing: border-box; }
body {
margin: 0;
min-width: 0;
background: var(--bg);
color: var(--text);
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
font-size: 14px;
transition: background .2s, color .2s;
}
body.dark {
color-scheme: dark;
--bg: #171925;
--surface: #222533;
--surface-soft: #2c3040;
--column: #1d202d;
--text: #f0f1f8;
--muted: #858b9f;
--muted-strong: #a9afc0;
--border: #343849;
--shadow: 0 6px 18px rgba(0,0,0,.12);
--purple: #9b92ff;
--purple-soft: #393454;
--input: #292d3c;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, [draggable]:focus-visible {
outline: 3px solid #aaa4ff;
outline-offset: 3px;
}
.app { min-height: 100vh; display: flex; }
.sidebar {
width: 224px;
flex-shrink: 0;
background: var(--surface);
border-right: 1px solid var(--border);
display: flex;
flex-direction: column;
padding: 30px 17px 18px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 7px; font-size: 19px; font-weight: 750; letter-spacing: -.7px; }
.brand-mark { width: 32px; height: 32px; border-radius: 10px; background: #7065e9; display: grid; place-items: center; color: #fff; }
.workspace-label { margin: 45px 10px 14px; color: var(--muted); font-size: 10px; font-weight: 750; letter-spacing: 1.35px; }
.nav-item { height: 43px; display: flex; align-items: center; gap: 11px; padding: 0 12px; border-radius: 8px; color: var(--muted-strong); font-weight: 600; }
.nav-item.active { color: var(--purple); background: var(--purple-soft); }
.nav-item svg { flex: none; }
.nav-spacer { flex: 1; }
.sidebar-bottom { border-top: 1px solid var(--border); padding: 20px 5px 0; }
.profile { display: flex; gap: 10px; align-items: center; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; color: #775f55; background: #f0d7ca; font-size: 12px; font-weight: 750; flex: none; }
.profile strong { display: block; font-size: 12px; }
.profile small { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.profile-chevron { margin-left: auto; color: var(--muted); }
main { min-width: 0; flex: 1; }
.topbar {
height: 78px;
border-bottom: 1px solid var(--border);
background: var(--surface);
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 39px;
gap: 20px;
}
.breadcrumbs { display: flex; gap: 12px; align-items: center; white-space: nowrap; font-size: 12px; color: var(--muted); }
.breadcrumbs strong { color: var(--text); font-weight: 650; }
.slash { color: #d0d3de; }
.top-actions { display: flex; gap: 17px; align-items: center; }
.search-wrap { width: 224px; height: 38px; position: relative; color: var(--muted); }
.search-wrap svg { position: absolute; left: 12px; top: 11px; pointer-events: none; }
.search-wrap input { width: 100%; height: 100%; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); padding: 0 12px 0 36px; outline: 0; font-size: 12px; }
.search-wrap input:focus { border-color: #a39bf4; box-shadow: 0 0 0 3px rgba(112,101,233,.1); }
.search-wrap input::placeholder { color: var(--muted); }
.icon-button { border: 0; color: var(--muted-strong); background: transparent; width: 36px; height: 36px; border-radius: 8px; display: inline-grid; place-items: center; }
.icon-button:hover { background: var(--surface-soft); color: var(--text); }
.top-divider { width: 1px; height: 26px; background: var(--border); }
.top-avatar { width: 32px; height: 32px; font-size: 11px; }
.content { max-width: 1450px; margin: 0 auto; padding: 39px 39px 60px; }
.eyebrow { color: var(--purple); font-size: 10px; font-weight: 800; letter-spacing: 1.3px; text-transform: uppercase; }
.heading-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-top: 9px; }
h1 { margin: 0; font-size: 28px; line-height: 1.2; letter-spacing: -.9px; font-weight: 750; }
.subtitle { margin: 9px 0 0; color: var(--muted-strong); font-size: 13px; line-height: 1.5; }
.primary { background: #7065e9; border: 1px solid #7065e9; color: #fff; border-radius: 8px; height: 40px; padding: 0 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-size: 12px; font-weight: 700; box-shadow: 0 3px 7px rgba(112,101,233,.18); white-space: nowrap; }
.primary:hover { background: #6055d4; }
.board-toolbar { display: flex; align-items: center; justify-content: space-between; margin: 36px 0 20px; gap: 15px; border-bottom: 1px solid var(--border); }
.tabs { display: flex; gap: 25px; align-self: stretch; }
.tab { position: relative; padding: 0 1px 15px; color: var(--muted); font-size: 12px; font-weight: 650; white-space: nowrap; }
.tab.active { color: var(--purple); }
.tab.active:after { content: ""; height: 2px; background: var(--purple); position: absolute; left: 0; right: 0; bottom: -1px; border-radius: 2px; }
.toolbar-note { color: var(--muted); font-size: 11px; display: flex; gap: 7px; align-items: center; padding-bottom: 14px; white-space: nowrap; }
.board { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; align-items: start; }
.column { background: var(--column); border: 1px solid transparent; border-radius: 11px; padding: 15px 13px 13px; min-height: 465px; transition: border-color .15s, background .2s; }
.column.drag-over { border-color: #a59df5; background: var(--purple-soft); }
.column-head { display: flex; align-items: center; gap: 8px; margin: 1px 3px 15px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.todo .status-dot { background: #a1a8bc; }
.progress .status-dot { background: #e9b55f; }
.done .status-dot { background: #61bf9c; }
.column-head h2 { font-size: 13px; margin: 0; font-weight: 750; letter-spacing: -.1px; }
.count { font-size: 10px; font-weight: 750; color: var(--muted-strong); background: var(--surface); border-radius: 5px; min-width: 19px; height: 19px; display: grid; place-items: center; }
.column-add { margin-left: auto; color: var(--muted); border: 0; background: transparent; padding: 2px; display: grid; place-items: center; border-radius: 5px; }
.column-add:hover { color: var(--purple); background: var(--surface); }
.card-list { display: flex; flex-direction: column; gap: 10px; min-height: 50px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 15px 15px 13px; box-shadow: var(--shadow); cursor: grab; transition: transform .15s, box-shadow .15s, opacity .15s; }
.card:hover { transform: translateY(-2px); box-shadow: 0 7px 20px rgba(32,36,58,.09); }
.card.dragging { opacity: .35; transform: none; }
.card-top { display: flex; align-items: flex-start; gap: 8px; }
.card-title { font-size: 13px; line-height: 1.4; letter-spacing: -.1px; font-weight: 700; margin: 0; flex: 1; overflow-wrap: anywhere; }
.delete { border: 0; background: transparent; color: var(--muted); padding: 1px; margin: -1px -2px 0 0; border-radius: 4px; display: grid; place-items: center; }
.delete:hover { color: #dc6069; background: #fff0f0; }
.card-description { color: var(--muted-strong); font-size: 11px; line-height: 1.55; margin: 8px 0 0; }
.card-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 20px; }
.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 5px; padding: 5px 7px; font-size: 10px; font-weight: 700; line-height: 1; text-transform: capitalize; }
.badge:before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge.high { color: #d87974; background: #fff0ee; }
.badge.medium { color: #c49a4d; background: #fff6e4; }
.badge.low { color: #5eaa8d; background: #e8f7ef; }
body.dark .badge.high { background: #4b343a; color: #f1a29d; }
body.dark .badge.medium { background: #493f30; color: #e7c480; }
body.dark .badge.low { background: #2c453d; color: #8bd7b3; }
.card-person { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 10px; }
.mini-avatar { width: 23px; height: 23px; border-radius: 50%; display: grid; place-items: center; font-size: 8px; font-weight: 750; color: #83685c; background: #f2dbce; }
.mini-avatar.blue { background: #dbe9f3; color: #65849a; }
.mini-avatar.purple { background: #e8def6; color: #8c73a9; }
.mini-avatar.green { background: #dbefe4; color: #69917b; }
.add-card { margin-top: 12px; width: 100%; height: 36px; display: flex; align-items: center; gap: 7px; padding: 0 4px; color: var(--muted-strong); background: transparent; border: 0; font-size: 11px; font-weight: 650; border-radius: 6px; }
.add-card:hover { color: var(--purple); background: var(--surface); padding-left: 8px; }
.drop-indicator { height: 4px; margin: 1px 2px; border-radius: 5px; background: #8b80f1; box-shadow: 0 0 0 2px rgba(139,128,241,.16); flex: none; }
.empty { color: var(--muted); font-size: 11px; text-align: center; padding: 22px 5px; line-height: 1.5; }
.board-footer { color: var(--muted); font-size: 11px; margin-top: 19px; display: flex; align-items: center; gap: 7px; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(21, 23, 39, .48); display: flex; justify-content: center; align-items: center; padding: 20px; z-index: 5; }
.modal-backdrop[hidden] { display: none; }
.modal { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 13px; box-shadow: 0 22px 65px rgba(0,0,0,.22); padding: 24px; }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 15px; }
.modal h2 { font-size: 19px; letter-spacing: -.4px; margin: 0; }
.modal-subtitle { color: var(--muted-strong); font-size: 12px; margin: 7px 0 23px; }
.field { margin-bottom: 17px; }
.field label { display: block; font-size: 12px; font-weight: 700; margin-bottom: 8px; }
.required { color: #d87974; }
.field input, .field select { width: 100%; height: 42px; border: 1px solid var(--border); border-radius: 7px; padding: 0 11px; background: var(--input); color: var(--text); outline: 0; }
.field input:focus, .field select:focus { border-color: #9a91ef; box-shadow: 0 0 0 3px rgba(112,101,233,.1); }
.field input::placeholder { color: var(--muted); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 25px; }
.secondary { border: 1px solid var(--border); color: var(--text); background: var(--surface); border-radius: 8px; padding: 0 16px; height: 40px; font-weight: 650; font-size: 12px; }
.secondary:hover { background: var(--surface-soft); }
@media (max-width: 900px) {
.sidebar { width: 68px; padding: 25px 12px 18px; align-items: center; }
.brand { padding: 0; }
.brand-name, .workspace-label, .nav-item span, .profile-details, .profile-chevron { display: none; }
.nav-list { margin-top: 46px; width: 100%; }
.nav-item { justify-content: center; padding: 0; }
.sidebar-bottom { width: 100%; display: flex; justify-content: center; padding: 18px 0 0; }
.topbar { padding: 0 24px; }
.content { padding-left: 24px; padding-right: 24px; }
.board { gap: 10px; }
.column { padding-left: 10px; padding-right: 10px; }
.card { padding: 13px 11px; }
}
@media (max-width: 650px) {
.sidebar { display: none; }
.topbar { height: 66px; padding: 0 18px; }
.breadcrumbs { font-size: 11px; gap: 8px; }
.breadcrumbs .workspace-crumb, .breadcrumbs .slash:first-of-type { display: none; }
.top-actions { gap: 5px; }
.search-wrap { width: min(41vw, 190px); }
.top-divider, .top-avatar { display: none; }
.content { padding: 30px 18px 45px; }
h1 { font-size: 25px; }
.heading-row { align-items: flex-start; }
.subtitle { max-width: 230px; }
.primary { padding: 0 11px; }
.board-toolbar { margin-top: 29px; }
.toolbar-note { display: none; }
.board { grid-template-columns: 1fr; gap: 12px; }
.column { min-height: 0; padding: 14px; }
.card-list { min-height: 15px; }
.card { padding: 14px; }
.card-meta { margin-top: 14px; }
}
</style>
</head>
<body>
<div class="app">
<aside class="sidebar" aria-label="Workspace navigation">
<div class="brand">
<div class="brand-mark"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><rect x="3" y="4" width="7" height="16" rx="2" fill="currentColor"/><rect x="14" y="4" width="7" height="10" rx="2" fill="currentColor" opacity=".7"/></svg></div>
<span class="brand-name">flowboard.</span>
</div>
<div class="workspace-label">WORKSPACE</div>
<div class="nav-list">
<div class="nav-item active"><svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" aria-hidden="true"><rect x="3" y="3" width="7" height="7" rx="1.5"/><rect x="14" y="3" width="7" height="7" rx="1.5"/><rect x="3" y="14" width="7" height="7" rx="1.5"/><rect x="14" y="14" width="7" height="7" rx="1.5"/></svg><span>Board</span></div>
</div>
<div class="nav-spacer"></div>
<div class="sidebar-bottom">
<div class="profile"><div class="avatar">JD</div><div class="profile-details"><strong>Jordan Davis</strong><small>Personal workspace</small></div><span class="profile-chevron">⌄</span></div>
</div>
</aside>
<main>
<header class="topbar">
<div class="breadcrumbs"><span class="workspace-crumb">Workspace</span><span class="slash">/</span><strong>Board</strong></div>
<div class="top-actions">
<div class="search-wrap">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" aria-hidden="true"><circle cx="10.8" cy="10.8" r="6.7"/><path d="m16 16 4 4" stroke-linecap="round"/></svg>
<input id="search" type="search" placeholder="Search tasks..." aria-label="Search tasks by title">
</div>
<button class="icon-button" id="themeToggle" type="button" aria-label="Switch to dark theme" title="Switch theme">
<svg id="themeIcon" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M20.5 14.3A8.5 8.5 0 0 1 9.7 3.5 8.5 8.5 0 1 0 20.5 14.3Z"/></svg>
</button>
<div class="top-divider"></div><div class="avatar top-avatar">JD</div>
</div>
</header>
<div class="content">
<div class="eyebrow">YOUR WORKSPACE</div>
<div class="heading-row">
<div><h1>Project board</h1><p class="subtitle">A little progress every day adds up to big results.</p></div>
<button class="primary" id="openModal" type="button"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M12 5v14M5 12h14"/></svg> Add task</button>
</div>
<div class="board-toolbar">
<div class="tabs"><div class="tab active">Board view</div></div>
<div class="toolbar-note"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" aria-hidden="true"><rect x="3" y="4" width="18" height="17" rx="2"/><path d="M8 2v4M16 2v4M3 9h18"/></svg> Your tasks at a glance</div>
</div>
<section class="board" id="board" aria-label="Kanban board"></section>
<div class="board-footer"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" aria-hidden="true"><path d="M12 18V6m-4 4 4-4 4 4M5 14v5a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-5" stroke-linecap="round" stroke-linejoin="round"/></svg> Drag and drop tasks to move them between columns</div>
</div>
</main>
</div>
<div class="modal-backdrop" id="modalBackdrop" hidden>
<div class="modal" role="dialog" aria-modal="true" aria-labelledby="modalTitle">
<div class="modal-head"><div><h2 id="modalTitle">Add a new task</h2><p class="modal-subtitle">Add something to your team's board.</p></div><button class="icon-button" type="button" id="closeModal" aria-label="Close dialog"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6 6 18"/></svg></button></div>
<form id="taskForm">
<div class="field"><label for="taskTitle">Task title <span class="required">*</span></label><input id="taskTitle" name="title" required maxlength="100" placeholder="What needs to be done?" autocomplete="off"></div>
<div class="form-grid">
<div class="field"><label for="taskPriority">Priority</label><select id="taskPriority"><option value="low">Low</option><option value="medium" selected>Medium</option><option value="high">High</option></select></div>
<div class="field"><label for="taskStatus">Status</label><select id="taskStatus"><option value="todo">To do</option><option value="progress">In progress</option><option value="done">Done</option></select></div>
</div>
<div class="modal-actions"><button class="secondary" id="cancelModal" type="button">Cancel</button><button class="primary" type="submit">Add task</button></div>
</form>
</div>
</div>
<script>
(() => {
const columns = [
{ id: 'todo', label: 'To do' },
{ id: 'progress', label: 'In progress' },
{ id: 'done', label: 'Done' }
];
let cards = [
{ id: 1, title: 'Plan the project kickoff', description: 'Outline goals, milestones, and next steps.', priority: 'high', status: 'todo', initials: 'JD', person: 'Jordan', color: '' },
{ id: 2, title: 'Research user needs', description: 'Gather insights and review feedback.', priority: 'medium', status: 'todo', initials: 'AM', person: 'Alex', color: 'blue' },
{ id: 3, title: 'Design the dashboard', description: 'Create the first round of dashboard screens.', priority: 'high', status: 'progress', initials: 'SK', person: 'Sam', color: 'purple' },
{ id: 4, title: 'Update the style guide', description: 'Bring our visual components up to date.', priority: 'medium', status: 'progress', initials: 'JD', person: 'Jordan', color: '' },
{ id: 5, title: 'Set up project workspace', description: 'Get everything ready for the team.', priority: 'low', status: 'done', initials: 'AM', person: 'Alex', color: 'blue' },
{ id: 6, title: 'Define project scope', description: 'Align on deliverables and priorities.', priority: 'medium', status: 'done', initials: 'SK', person: 'Sam', color: 'green' }
];
let nextId = 7;
let draggingId = null;
let lastFocus = null;
const board = document.getElementById('board');
const search = document.getElementById('search');
const modal = document.getElementById('modalBackdrop');
const form = document.getElementById('taskForm');
const titleInput = document.getElementById('taskTitle');
const statusInput = document.getElementById('taskStatus');
const priorityInput = document.getElementById('taskPriority');
const indicator = document.createElement('div');
indicator.className = 'drop-indicator';
const escapeHtml = value => String(value).replace(/[&<>"']/g, char => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[char]);
const plusIcon = '<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" aria-hidden="true"><path d="M12 5v14M5 12h14"/></svg>';
const trashIcon = '<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 7h16M10 11v6M14 11v6M5.5 7l1 13h11l1-13M9 7V4h6v3"/></svg>';
function render() {
const query = search.value.trim().toLowerCase();
board.innerHTML = columns.map(column => {
const allInColumn = cards.filter(card => card.status === column.id);
const visible = allInColumn.filter(card => card.title.toLowerCase().includes(query));
return `<section class="column ${column.id}" data-column="${column.id}" aria-label="${column.label}">
<div class="column-head"><span class="status-dot"></span><h2>${column.label}</h2><span class="count" title="${allInColumn.length} total tasks">${allInColumn.length}</span><button type="button" class="column-add" data-add="${column.id}" aria-label="Add task to ${column.label}">${plusIcon}</button></div>
<div class="card-list" data-list="${column.id}">
${visible.map(card => `<article class="card" draggable="true" data-id="${card.id}" aria-label="${escapeHtml(card.title)}, ${card.priority} priority">
<div class="card-top"><h3 class="card-title">${escapeHtml(card.title)}</h3><button type="button" class="delete" data-delete="${card.id}" aria-label="Delete ${escapeHtml(card.title)}" title="Delete task">${trashIcon}</button></div>
${card.description ? `<p class="card-description">${escapeHtml(card.description)}</p>` : ''}
<div class="card-meta"><span class="badge ${card.priority}">${card.priority}</span><span class="card-person"><span class="mini-avatar ${card.color}">${escapeHtml(card.initials)}</span>${escapeHtml(card.person)}</span></div>
</article>`).join('')}
${visible.length === 0 ? `<div class="empty">${query && allInColumn.length ? 'No matching tasks' : 'No tasks here yet'}</div>` : ''}
</div>
<button type="button" class="add-card" data-add="${column.id}">${plusIcon} Add task</button>
</section>`;
}).join('');
}
function openModal(status = 'todo') {
lastFocus = document.activeElement;
form.reset();
statusInput.value = status;
modal.hidden = false;
titleInput.focus();
}
function closeModal() {
modal.hidden = true;
if (lastFocus && document.contains(lastFocus)) lastFocus.focus();
}
document.getElementById('openModal').addEventListener('click', () => openModal());
document.getElementById('closeModal').addEventListener('click', closeModal);
document.getElementById('cancelModal').addEventListener('click', closeModal);
modal.addEventListener('click', event => { if (event.target === modal) closeModal(); });
document.addEventListener('keydown', event => { if (event.key === 'Escape' && !modal.hidden) closeModal(); });
form.addEventListener('submit', event => {
event.preventDefault();
const title = titleInput.value.trim();
if (!title) { titleInput.value = ''; titleInput.focus(); titleInput.reportValidity(); return; }
cards.push({ id: nextId++, title, description: '', priority: priorityInput.value, status: statusInput.value, initials: 'JD', person: 'Jordan', color: '' });
search.value = '';
render();
closeModal();
});
search.addEventListener('input', render);
board.addEventListener('click', event => {
const add = event.target.closest('[data-add]');
const remove = event.target.closest('[data-delete]');
if (add) openModal(add.dataset.add);
if (remove) {
cards = cards.filter(card => card.id !== Number(remove.dataset.delete));
render();
}
});
board.addEventListener('dragstart', event => {
const card = event.target.closest('.card');
if (!card) return;
draggingId = Number(card.dataset.id);
event.dataTransfer.effectAllowed = 'move';
event.dataTransfer.setData('text/plain', String(draggingId));
requestAnimationFrame(() => card.classList.add('dragging'));
});
board.addEventListener('dragover', event => {
if (draggingId === null) return;
const column = event.target.closest('.column');
if (!column) return;
event.preventDefault();
event.dataTransfer.dropEffect = 'move';
board.querySelectorAll('.column.drag-over').forEach(el => { if (el !== column) el.classList.remove('drag-over'); });
column.classList.add('drag-over');
const list = column.querySelector('.card-list');
const candidates = [...list.querySelectorAll('.card:not(.dragging)')];
const next = candidates.find(card => event.clientY < card.getBoundingClientRect().top + card.getBoundingClientRect().height / 2);
if (next) list.insertBefore(indicator, next);
else list.appendChild(indicator);
});
board.addEventListener('dragleave', event => {
const column = event.target.closest('.column');
if (column && !column.contains(event.relatedTarget)) column.classList.remove('drag-over');
});
board.addEventListener('drop', event => {
const column = event.target.closest('.column');
if (!column || draggingId === null) return;
event.preventDefault();
const moved = cards.find(card => card.id === draggingId);
const nextElement = indicator.parentElement === column.querySelector('.card-list') ? indicator.nextElementSibling : null;
const nextCard = nextElement && nextElement.matches('.card') ? Number(nextElement.dataset.id) : null;
if (moved) {
cards = cards.filter(card => card.id !== draggingId);
moved.status = column.dataset.column;
const index = nextCard === null ? -1 : cards.findIndex(card => card.id === nextCard);
if (index >= 0) cards.splice(index, 0, moved); else cards.push(moved);
}
draggingId = null;
indicator.remove();
render();
});
board.addEventListener('dragend', () => {
draggingId = null;
indicator.remove();
board.querySelectorAll('.dragging').forEach(el => el.classList.remove('dragging'));
board.querySelectorAll('.drag-over').forEach(el => el.classList.remove('drag-over'));
});
const themeToggle = document.getElementById('themeToggle');
const themeIcon = document.getElementById('themeIcon');
themeToggle.addEventListener('click', () => {
const dark = document.body.classList.toggle('dark');
themeToggle.setAttribute('aria-label', dark ? 'Switch to light theme' : 'Switch to dark theme');
themeIcon.innerHTML = dark
? '<circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.93 4.93l1.42 1.42M17.65 17.65l1.42 1.42M2 12h2M20 12h2M4.93 19.07l1.42-1.42M17.65 6.35l1.42-1.42"/>'
: '<path d="M20.5 14.3A8.5 8.5 0 0 1 9.7 3.5 8.5 8.5 0 1 0 20.5 14.3Z"/>';
});
render();
})();
</script>
</body>
</html>