/* Algebra tiles: the area model, the live term, the tiles and their controls.
   Builds on the shared .explorer, .btn and .math styles in styles.css. */
.term-tiles { --tt-u: 28px; /* a 1 tile is 28 px square; an x tile is 28 × 60 and x² is 60 × 60 */ --tt-x: 60px; min-width: 0; }

.tt-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Area model: wider columns and taller rows for x than for a constant, so a cell looks like its tile. */
.tt-area-wrap { margin-bottom: 1rem; }
.tt-area { border-collapse: separate; border-spacing: 3px; max-width: 100%; margin: 0 0 0.5rem; }
.tt-area caption { text-align: left; font-weight: 700; padding-bottom: 0.4rem; overflow-wrap: anywhere; }
.tt-nowrap { white-space: nowrap; }
.tt-head { font-weight: 700; color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; }
.tt-corner { width: min(3rem, 48px); min-width: min(3rem, 48px); } /* the area model's columns and rows stop growing with the text: its cells hold a short term, and the model has to stay inside the card */
.tt-corner-mark { font-size: 1.1rem; }
.tt-cell { box-sizing: border-box; padding: 0.2rem; text-align: center; vertical-align: middle; font-size: 1.1rem; font-weight: 800; font-variant-numeric: tabular-nums; border: 2px solid var(--line); border-radius: 8px; background: color-mix(in srgb, var(--line) 24%, var(--surface)); overflow-wrap: anywhere; }
.tt-cell--negative { border-color: var(--user-line); background: repeating-linear-gradient(135deg, transparent 0 6px, color-mix(in srgb, var(--user-line) 28%, transparent) 6px 8px), color-mix(in srgb, var(--user-line) 22%, var(--surface)); }
.tt-w-x { width: min(6.5rem, 104px); min-width: min(6.5rem, 104px); }
.tt-w-unit { width: min(4.5rem, 72px); min-width: min(4.5rem, 72px); }
.tt-h-x { height: min(4.2rem, 67.2px); }
.tt-h-unit { height: min(3rem, 48px); }
.tt-sum { margin: 0 0 0.7rem; overflow-wrap: anywhere; }
.tt-sum-text { font-weight: 700; white-space: normal; /* .math is nowrap; a long sum wraps at its spaces */ overflow-wrap: anywhere; }
.tt-fill { width: 100%; text-align: center; }

/* The live term. */
.tt-termbox { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.2rem 0.9rem; margin: 0 0 0.5rem; padding: 0.6rem 0.8rem; border-radius: 10px; background: var(--surface-2); }
.tt-term-label { font-size: 0.85rem; font-weight: 700; color: var(--muted); }
.tt-term { font-size: 1.6rem; font-weight: 800; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.tt-match { font-weight: 700; }
.tt-match:not(:empty)::before { content: '✓ '; }

/* The announcement is also on screen: it is the readout of the last action. */
.tt-readout { margin: 0 0 0.8rem; min-height: 1.5em; padding: 0.5rem 0.7rem; border-radius: 10px; background: var(--accent-soft); font-weight: 600; overflow-wrap: anywhere; }

/* Tiles. A positive tile is solid with a plus; a negative one is hatched with a minus; a zero pair has a dashed outline. */
.tt-tile { box-sizing: border-box; flex: none; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; line-height: 1; color: var(--text); border: 2px solid var(--line); border-radius: 4px; background: color-mix(in srgb, var(--line) 28%, var(--surface)); }
.tt-pair { flex: none; display: inline-flex; gap: 2px; /* a positive tile and its negative partner never split across lines */ }
.tt-tile--x2 { width: var(--tt-x); height: var(--tt-x); }
.tt-tile--x { width: var(--tt-x); height: var(--tt-u); }
.tt-tile--unit { width: var(--tt-u); height: var(--tt-u); }
.tt-tile.is-negative { border-color: var(--user-line); background: repeating-linear-gradient(135deg, transparent 0 5px, color-mix(in srgb, var(--user-line) 30%, transparent) 5px 7px), color-mix(in srgb, var(--user-line) 22%, var(--surface)); }
.tt-tile.is-zero { border: 3px dashed var(--text); }
@media (prefers-reduced-motion: no-preference) {
  .tt-tile.is-new { animation: tt-pop 0.18s ease-out; }
}
@keyframes tt-pop { from { transform: scale(0.7); opacity: 0.5; } to { transform: none; opacity: 1; } }

.tt-board { display: flex; flex-direction: column; gap: 0.9rem; margin-bottom: 0.6rem; }
.tt-kind { display: grid; gap: 0.4rem; }
.tt-tiles { display: flex; flex-wrap: wrap; align-items: flex-start; align-content: flex-start; gap: 4px; padding: 6px; border: 1px dashed var(--border); border-radius: 10px; background: var(--surface-2); min-height: calc(var(--tt-u) + 14px); }
.tt-kind--x2 .tt-tiles { min-height: calc(var(--tt-x) + 14px); }

/* Each pile has its own Add and Remove. */
.tt-pile { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 6.5rem), 1fr)); /* Add and Remove side by side, or one above the other when large text leaves no room */ align-items: center; gap: 0.3rem 0.5rem; padding-left: 0.6rem; border-left: 6px solid var(--line); }
.tt-pile--negative { border-left-color: var(--user-line); }
.tt-pile-name { grid-column: 1 / -1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.term-tiles .tt-add, .term-tiles .tt-remove { min-height: 44px; min-width: 44px; padding: 0.4rem 0.5rem; text-align: center; overflow-wrap: normal; } /* never split "Hinzufügen" to fit a column a pixel too narrow: the pile stacks the two buttons when they do not fit side by side */
@media (min-width: 640px) {
  .tt-kind { grid-template-columns: 1fr 1fr; }
  .tt-tiles { grid-column: 1 / -1; }
}

.tt-pairs { margin: 0 0 0.6rem; color: var(--muted); font-size: 0.9rem; }
.tt-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.8rem; }
.tt-cancel, .tt-reset { min-height: 44px; }

/* The key says the same as the colours: a plus, a hatch and a dashed outline. */
.tt-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.88rem; color: var(--muted); }
.tt-legend li { display: flex; align-items: center; gap: 0.5rem; overflow-wrap: anywhere; }
