:root {
  --bg:     #181820;
  --panel:  #1e1e2a;
  --border: #2e2e3e;
  --tbg:    #fdf6e3;   /* tile parchment */
  --tbord:  #c8b08a;   /* tile border */
  --ttext:  #1a1008;
  --female: #6b8fff;   /* u = unstressed = blue  */
  --male:   #f5a030;   /* S = stressed   = amber */
  --green:  #4ecba0;
  --red:    #e04060;
  --text:   #c8c8d8;
  --dim:    #50506a;
  --bumpW:  11px;      /* tab/notch depth        */
  --bumpH:  22px;      /* tab/notch height       */
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: Georgia, serif;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ─────────────────────────────────────────── */
header {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 9px 20px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-shrink: 0;
  user-select: none;
}
header h1 {
  font-size: 17px;
  letter-spacing: 3px;
  color: #fff;
  font-weight: normal;
  white-space: nowrap;
}
.legend {
  display: flex;
  gap: 14px;
  font-size: 12px;
  font-family: sans-serif;
  color: var(--dim);
}
.legend-item { display: flex; align-items: center; gap: 5px; }
.legend-dot  { width: 10px; height: 14px; border-radius: 2px; }

/* ── Layout ─────────────────────────────────────────── */
#layout { display: flex; flex: 1; overflow: hidden; }

/* ── Bag sidebar ────────────────────────────────────── */
#bag {
  width: 220px;
  min-width: 220px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#bag-header {
  padding: 11px 14px 9px;
  font-family: sans-serif;
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--dim);
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#bag-search {
  padding: 8px 12px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-family: sans-serif;
  font-size: 13px;
  outline: none;
  flex-shrink: 0;
}
#bag-search::placeholder { color: var(--dim); }
#bag-list {
  overflow-y: auto;
  flex: 1;
  padding: 8px 12px 8px 18px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.bag-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 3px 0;
}
.bag-row-left { display: flex; flex-direction: column; gap: 2px; }
.bag-count {
  font-family: sans-serif;
  font-size: 11px;
  color: var(--dim);
  min-width: 22px;
  text-align: right;
  flex-shrink: 0;
}
.tile-meter {
  font-family: monospace;
  font-size: 9px;
  color: var(--dim);
  padding-left: 2px;
}

/* ── Workspace / Canvas ─────────────────────────────── */
#workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

#canvas {
  flex: 1;
  position: relative;
  overflow: auto;
  min-height: 0;
}

/* hint when canvas is empty */
#canvas:not(:has(.line-group))::after {
  content: 'Drag words from the bag onto the canvas.\A Drag a word onto another word to form a line.';
  white-space: pre;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--dim);
  font-family: sans-serif;
  font-size: 13px;
  text-align: center;
  pointer-events: none;
  line-height: 2;
}

/* ── Line groups ────────────────────────────────────── */
.line-group {
  position: absolute;
  padding: 10px 14px 8px;
  border-radius: 10px;
  cursor: move;
  user-select: none;
  transition: background 0.12s;
}
.line-group:hover {
  background: rgba(80, 80, 110, 0.38);
}
.line-group.line-moving {
  background: rgba(80, 80, 110, 0.52);
  cursor: grabbing;
}

.line-sc {
  font-family: monospace;
  font-size: 10px;
  color: var(--dim);
  text-align: center;
  margin-top: 4px;
  pointer-events: none;
  letter-spacing: 1px;
}
.line-sc.done { color: var(--green); }

/* ── Poem lines ─────────────────────────────────────── */
.poem-line {
  min-height: 50px;
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 4px 6px;
  display: flex;
  align-items: center;
  gap: 0;
  overflow: visible;
  transition: border-color 0.15s, background 0.15s;
  position: relative;
}

.poem-line.complete  { border-color: var(--green); border-style: solid; }
.poem-line.drag-over { border-color: var(--green);
                        background: rgba(78,203,160,0.06); }

/* flash animation */
@keyframes flashRed {
  0%,100% { border-color: transparent; }
  30%     { border-color: var(--red); border-style: solid; }
}
.poem-line.flash { animation: flashRed 0.5s ease; }

/* ── Drop cursor ────────────────────────────────────── */
.drop-cursor {
  width: 2px;
  min-width: 2px;
  height: 38px;
  background: var(--green);
  border-radius: 1px;
  flex-shrink: 0;
  pointer-events: none;
  box-shadow: 0 0 6px var(--green);
}

/* ── Controls ───────────────────────────────────────── */
#bottom-bar {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
#bottom-bar button {
  font-family: sans-serif;
  font-size: 12px;
  padding: 6px 14px;
  border-radius: 5px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: none;
  color: var(--text);
  transition: all 0.15s;
}
#clear-btn:hover  { border-color: var(--red);   color: var(--red); }
#random-btn:hover { border-color: var(--green); color: var(--green); }

/* ══════════════════════════════════════════════════════
   TILE  ( .t-wrap > .t > .t-bd )
   Tabs (convex) = ::before/::after pseudo-elements
   Notches (concave) = clip-path on .t
   ══════════════════════════════════════════════════════ */

/* Outer wrapper: positioning context, draggable */
.t-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  cursor: grab;
  user-select: none;
  filter: drop-shadow(0 1px 4px rgba(0,0,0,0.35));
  transition: filter 0.1s;
}
.t-wrap:active { cursor: grabbing; }
.t-wrap.dragging { opacity: 0.3; }
.t-wrap.exhausted { opacity: 0.28; cursor: not-allowed; pointer-events: none; }
.t-wrap:not(.exhausted):not(.dragging):hover {
  filter: drop-shadow(0 3px 9px rgba(0,0,0,0.5));
}
.t-wrap:not(.exhausted):not(.dragging):hover .t {
  transform: translateY(-1px);
}

/* Inner tile */
.t {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  background: var(--tbg);
  transition: transform 0.1s;
}

/* Syllable markers row */
.t-marks {
  display: flex;
  justify-content: center;
  gap: 3px;
  padding: 3px 4px 0;
  line-height: 1;
}
.syl-u {
  font-family: sans-serif;
  font-size: 9px;
  color: var(--female);
  font-weight: bold;
}
.syl-s {
  font-family: sans-serif;
  font-size: 9px;
  color: var(--male);
  font-weight: bold;
}

/* Word body — horizontal padding keeps text clear of notch tips */
.t-bd {
  color: var(--ttext);
  padding: 2px calc(var(--bumpW) + 4px) 5px;
  font-size: 14px;
  font-family: Georgia, serif;
  white-space: nowrap;
  line-height: 1.45;
}

/* ── TABS (convexities) — same parchment, single triangle ── */
/* Only create pseudo-elements on tiles that actually have a tab */
.t-wrap[data-lconn="S"]::before {
  content: '';
  position: absolute;
  right: 100%;
  top: 50%;
  transform: translateY(-50%);
  width: var(--bumpW);
  height: var(--bumpH);
  background: var(--tbg);
  pointer-events: none;
  clip-path: polygon(100% 0, 100% 100%, 0 50%);  /* ◄ left-pointing */
}
.t-wrap[data-rconn="S"]::after {
  content: '';
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  width: var(--bumpW);
  height: var(--bumpH);
  background: var(--tbg);
  pointer-events: none;
  clip-path: polygon(0 0, 0 100%, 100% 50%);  /* ► right-pointing */
}

/* ── NOTCHES (concavities) — clip-path cuts into .t ─────── */
/* left notch, right tab */
.t-wrap[data-lconn="u"][data-rconn="S"] .t {
  clip-path: polygon(
    0% 0%, 100% 0%, 100% 100%, 0% 100%,
    0% calc(50% + var(--bumpH) / 2),
    var(--bumpW) 50%,
    0% calc(50% - var(--bumpH) / 2)
  );
}
/* left tab, right notch */
.t-wrap[data-lconn="S"][data-rconn="u"] .t {
  clip-path: polygon(
    0% 0%,
    100% 0%,
    100% calc(50% - var(--bumpH) / 2),
    calc(100% - var(--bumpW)) 50%,
    100% calc(50% + var(--bumpH) / 2),
    100% 100%,
    0% 100%
  );
}
/* both notches */
.t-wrap[data-lconn="u"][data-rconn="u"] .t {
  clip-path: polygon(
    0% 0%,
    100% 0%,
    100% calc(50% - var(--bumpH) / 2),
    calc(100% - var(--bumpW)) 50%,
    100% calc(50% + var(--bumpH) / 2),
    100% 100%,
    0% 100%,
    0% calc(50% + var(--bumpH) / 2),
    var(--bumpW) 50%,
    0% calc(50% - var(--bumpH) / 2)
  );
}
/* both tabs: no notches, no clip-path needed */
