:root {
  --bg: #f5f5f7;
  --panel: #ffffff;
  --ink: #1d1d1f;
  --ink-mute: #6e6e73;
  --border: #e5e5ea;
  --accent: #0071e3;
  --accent-hover: #005bb5;
  --ok-bg: #d4f4dd;
  --ok-ink: #0a6b1e;
  --warn-bg: #fef3c7;
  --warn-ink: #92400e;
  --err-bg: #fee2e2;
  --err-ink: #991b1b;
  --err-border: #f87171;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  /* Full-viewport frame: header / main / footer stack with no page scroll */
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
  overflow: hidden;
}
.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  background: var(--panel);
}
.app-header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-left: auto;
  flex-wrap: wrap;
}
h1 { font-size: 18px; font-weight: 600; margin: 0; }
.app-main {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  padding: 16px 24px;
  overflow: hidden;
  transition: grid-template-columns 0.25s ease;
}
.app-main.detail-open {
  grid-template-columns: minmax(0, 1fr) 320px;
}
.detail { display: none; }
.app-main.detail-open .detail { display: block; }
.board-column {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}
.app-footer {
  padding: 8px 24px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}
.app-footer .hint { margin: 0; font-size: 11px; }

/* ---- Confirmation / alert modal (native <dialog>) ---- */
.confirm-dialog {
  border: 0;
  border-radius: 12px;
  padding: 24px;
  max-width: 420px;
  width: min(92vw, 420px);
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.22);
  font-family: inherit;
}
.confirm-dialog::backdrop {
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(2px);
}
.confirm-title {
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
}
.confirm-message {
  margin: 0 0 20px;
  color: var(--ink-mute);
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
}
.confirm-message:empty { display: none; }
.confirm-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
button.danger {
  background: #dc2626;
  color: white;
}
button.danger:hover:not(:disabled) { background: #b91c1c; }
button.danger:focus-visible {
  outline: 2px solid #dc2626;
  outline-offset: 2px;
}

/* ---- API unavailable dialog (persistent, non-dismissible) ---- */
.api-unavailable-dialog {
  border: 0;
  border-top: 4px solid var(--err-border);
  border-radius: 12px;
  padding: 28px 28px 24px;
  max-width: 560px;
  width: min(92vw, 560px);
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
  font-family: inherit;
}
.api-unavailable-dialog::backdrop {
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(3px);
}
.api-unavailable-title {
  margin: 0 0 12px;
  font-size: 17px;
  font-weight: 600;
  color: var(--err-ink);
}
.api-unavailable-lede {
  margin: 0 0 16px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
}
.api-unavailable-lede strong { font-weight: 600; }
.api-unavailable-diag {
  margin: 0 0 16px;
  padding: 8px 12px;
  background: var(--err-bg);
  border-radius: 6px;
  font-size: 12px;
  color: var(--err-ink);
}
.api-unavailable-diag code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  background: transparent;
  padding: 0;
}
.api-unavailable-hint {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--ink);
  font-weight: 500;
}
.api-unavailable-list {
  margin: 0 0 16px;
  padding-left: 22px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-mute);
}
.api-unavailable-list li { margin-bottom: 6px; }
.api-unavailable-list code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--ink);
}
.api-unavailable-footnote {
  margin: 0;
  font-size: 12px;
  color: var(--ink-mute);
}
.api-unavailable-footnote a {
  color: var(--accent);
  text-decoration: none;
}
.api-unavailable-footnote a:hover { text-decoration: underline; }
.section-title {
  font-size: 13px;
  margin: 0 0 12px;
  color: var(--ink-mute);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.mode-badge {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--border);
  color: var(--ink-mute);
  font-weight: 500;
}
.mode-badge.real { background: var(--ok-bg); color: var(--ok-ink); }
.mode-badge.demo { background: var(--warn-bg); color: var(--warn-ink); }
.mode-badge.unavailable { background: var(--err-bg); color: var(--err-ink); }
.panel {
  background: var(--panel);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  border: 1px solid var(--border);
}
.board-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0; /* nested tab-bar/toolbar/board handle their own spacing */
  overflow: hidden;
}
.composer { flex: none; }
.detail {
  overflow-x: hidden;
  overflow-y: auto;
  min-height: 0;
  min-width: 0;
}
.panel h2 { font-size: 14px; margin: 0 0 12px; color: var(--ink-mute); font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
button {
  background: var(--accent);
  color: white;
  border: 0;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease;
}
button:hover:not(:disabled) { background: var(--accent-hover); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
pre {
  background: var(--bg);
  padding: 14px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.6;
  overflow-x: auto;
  margin: 12px 0 0;
  border: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-word;
}
.hint { font-size: 12px; color: var(--ink-mute); margin-top: 8px; }
code { background: var(--bg); padding: 1px 6px; border-radius: 4px; font-size: 12px; }
button.secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--border);
}
button.secondary:hover:not(:disabled) { background: var(--bg); }
input[type="text"] {
  font: inherit;
  font-size: 14px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  min-width: 220px;
  transition: border-color 0.15s ease;
}
input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
}

/* ---- Step 2: keyword board ---- */
.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  flex: none;
  padding: 8px 12px;
}
.board {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  touch-action: none;
  background-image:
    radial-gradient(circle at 1px 1px, rgba(0,0,0,0.08) 1px, transparent 0);
  background-size: 24px 24px;
}
.keyword {
  position: absolute;
  left: 0;
  top: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px 8px 16px;
  background: var(--kw-color, #64748b);
  color: white;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  cursor: grab;
  user-select: none;
  touch-action: none;
  white-space: nowrap;
  transition: box-shadow 0.15s ease, transform 0.05s ease-out;
  will-change: transform;
}
.keyword:hover { box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2); }
.keyword.dragging {
  cursor: grabbing;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
  z-index: 10;
}
.keyword .kw-label { outline: none; }
.keyword .kw-label[contenteditable="true"] {
  background: rgba(255, 255, 255, 0.95);
  color: var(--ink);
  padding: 1px 4px;
  margin: -1px -4px;
  border-radius: 4px;
  box-shadow: 0 0 0 2px var(--accent);
  cursor: text;
  user-select: text;
  -webkit-user-select: text;
}
.kw-close {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: 0;
  width: 20px;
  height: 20px;
  padding: 0;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.kw-close:hover { background: rgba(255, 255, 255, 0.35); }
.kw-close:focus-visible {
  outline: 2px solid white;
  outline-offset: 1px;
}
/* ---- Phase 8: Multi-board tab bar ---- */
.tab-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  padding: 8px 12px 0;
  background: linear-gradient(to bottom, transparent, rgba(0,0,0,0.02));
  border-radius: 12px 12px 0 0;
  flex: none;
}
.tab-list {
  display: flex;
  gap: 2px;
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden; /* explicit — otherwise it implicit-promotes to auto and shows a vertical scrollbar for the 1px overhang */
  scrollbar-width: thin;
  padding-top: 2px;   /* small breathing room so the top of tab pills doesn't clip */
}
.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 6px 8px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  font-size: 13px;
  color: var(--ink-mute);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  position: relative;
  bottom: -1px;
  user-select: none;
  white-space: nowrap;
  max-width: 240px;
}
.tab:hover { background: rgba(255,255,255,0.7); color: var(--ink); }
.tab.active {
  background: white;
  color: var(--ink);
  font-weight: 600;
  border-bottom: 1px solid white;
}
.tab-title {
  outline: none;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}
.tab-title[contenteditable="true"] {
  background: white;
  padding: 1px 6px;
  border-radius: 4px;
  box-shadow: 0 0 0 2px var(--accent);
  max-width: none;
}
.tab-close {
  background: transparent;
  border: 0;
  color: var(--ink-mute);
  width: 20px;
  height: 20px;
  padding: 0;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
}
.tab:hover .tab-close,
.tab.active .tab-close,
.tab-close:focus-visible { opacity: 1; }
.tab-close:hover { background: rgba(0,0,0,0.08); color: var(--ink); }
.new-board-btn {
  padding: 6px 12px;
  font-size: 13px;
  background: transparent;
  color: var(--accent);
  border: 1px dashed var(--border);
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 4px;
  flex-shrink: 0;
}
.new-board-btn:hover { background: rgba(0, 113, 227, 0.08); border-style: solid; }
.sample-board-btn { color: var(--ink-mute); }
.sample-board-btn:hover { background: rgba(0, 0, 0, 0.04); color: var(--ink); border-color: var(--border); border-style: solid; }

/* ---- Step 7-A: focus visibility ---- */
.keyword:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
.note:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button.secondary:focus-visible {
  outline-color: var(--ink);
}

/* ---- Step 3: sticky notes ---- */
.composer {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.composer textarea {
  font: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  resize: vertical;
  min-height: 52px;
  line-height: 1.4;
}
.composer textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
}
.composer-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}
.note {
  position: absolute;
  left: 0;
  top: 0;
  max-width: 160px;
  padding: 8px 12px;
  border-radius: 8px;
  background: color-mix(in oklch, var(--note-color, #64748b) 22%, white);
  border: 2px solid var(--note-color, #64748b);
  color: var(--ink);
  font-size: 12px;
  line-height: 1.4;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  word-break: break-word;
  white-space: pre-wrap;
  user-select: none;
  will-change: transform;
}
.note::before {
  content: "";
  position: absolute;
  top: -4px;
  left: 50%;
  width: 12px;
  height: 12px;
  background: color-mix(in oklch, var(--note-color, #64748b) 60%, white);
  border: 1px solid var(--note-color, #64748b);
  border-radius: 50%;
  transform: translateX(-50%);
  pointer-events: none;
}
.note-text {
  display: block;
  outline: none;
}
.note-text[contenteditable="true"] {
  background: rgba(255, 255, 255, 0.95);
  color: var(--ink);
  padding: 2px 4px;
  margin: -2px -4px;
  border-radius: 4px;
  box-shadow: 0 0 0 2px var(--accent);
  cursor: text;
  user-select: text;
  -webkit-user-select: text;
}
.note-close,
.note-info {
  position: absolute;
  top: -8px;
  width: 20px;
  height: 20px;
  padding: 0;
  border-radius: 50%;
  color: white;
  border: 2px solid white;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.note-close {
  right: -8px;
  background: var(--note-color, #64748b);
}
.note-info {
  right: 16px;
  background: color-mix(in oklch, var(--note-color, #64748b) 75%, black);
  font-size: 13px;
  font-weight: 500;
}
.note:hover .note-close,
.note:focus-within .note-close,
.note-close:focus-visible,
.note:hover .note-info,
.note:focus-within .note-info,
.note-info:focus-visible { opacity: 1; }
.note-close:hover,
.note-info:hover { filter: brightness(0.85); }
.note-close:focus-visible,
.note-info:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
/* Ambiguous notes: dashed border, no pin — but keep nearest color at centroid */
.note.ambiguous {
  border-style: dashed;
  opacity: 0.9;
}
.note.ambiguous::before { display: none; }
/* Unclassified notes: also muted grey, in bottom zone */
.note.unclassified {
  background: rgba(148, 163, 184, 0.15);
  border-style: dashed;
  opacity: 0.85;
}
.note.unclassified::before { display: none; }
/* "Unclassified" label, appears only when the board has an unclassified note */
.board::after {
  content: "Unclassified";
  position: absolute;
  bottom: 8px;
  left: 12px;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-mute);
  padding: 3px 10px;
  background: rgba(255, 255, 255, 0.85);
  border: 1px dashed var(--border);
  border-radius: 999px;
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}
.board.has-unclassified::after { opacity: 1; }

/* ---- Step 6-B: detail (explainable) panel ---- */
.note.selected {
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.5), 0 6px 16px rgba(0, 0, 0, 0.22);
  z-index: 5;
  cursor: pointer;
}
.note { cursor: pointer; }
.detail-empty strong { color: var(--ink); font-weight: 600; }
.detail-header {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 14px;
  padding: 12px;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
}
.detail-note-swatch {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--detail-color, #64748b);
  background: color-mix(in oklch, var(--detail-color, #64748b) 30%, white);
  flex-shrink: 0;
  margin-top: 2px;
}
.detail-note-body { flex: 1; min-width: 0; }
.detail-note-text {
  font-size: 14px;
  line-height: 1.45;
  word-break: break-word;
  margin-bottom: 4px;
}
.detail-nearest strong { color: var(--ink); font-weight: 600; }
.detail-close {
  padding: 4px 10px;
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
}
.detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  table-layout: fixed;
}
.detail-table th,
.detail-table td {
  padding: 8px 6px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  overflow-wrap: anywhere;
  word-break: break-word;
}
.detail-table th:nth-child(2),
.detail-table td:nth-child(2) { width: 60px; }
.detail-table th:nth-child(3),
.detail-table td:nth-child(3) { width: 110px; }
.detail-table thead th {
  color: var(--ink-mute);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
}
.detail-table td.num,
.detail-table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.detail-table tr.dominant td { font-weight: 600; }
.detail-weight-cell {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
}
.detail-weight-bar {
  display: inline-block;
  height: 6px;
  background: var(--bar-color, var(--ink-mute));
  border-radius: 3px;
  min-width: 2px;
  max-width: 60px;
  flex-shrink: 1;
}
