:root { font-family: system-ui, sans-serif; color: #192d3d; background: #f1f5f9; line-height: 1.5; }
* { box-sizing: border-box; }
body { margin: 0; padding: .75rem; }
.card { width: 100%; min-height: calc(100dvh - 1.5rem); margin: auto; background: white; border: 1px solid #c3cbd2; border-radius: 1rem; display: grid; grid-template-columns: 200px minmax(0, 1fr); grid-template-rows: auto 1fr auto; }
header, footer { grid-column: 1 / -1; }
header { display: grid; grid-template-columns: 1fr auto 1fr; gap: .5rem; align-items: center; padding: .85rem 1rem; background: #bfe8d5; border-bottom: 1px solid #69a58b; border-radius: 1rem 1rem 0 0; }
h1 { margin: 0; font-size: 1.6rem; grid-column: 2; grid-row: 1; text-align: center; }
.difficulty-control { grid-column: 3; grid-row: 1; justify-self: end; display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: .5rem .75rem; }
.level { color: #405c70; font-weight: 650; font-size: 1rem; text-align: right; }
button { font: inherit; cursor: pointer; border-radius: .45rem; min-height: 44px; padding: .4rem .6rem; border: 2px solid #526879; overflow-wrap: anywhere; }
button:focus-visible, input:focus-visible, .diagram-scroll:focus-visible { outline: 3px solid #111827; outline-offset: 3px; box-shadow: 0 0 0 3px white; }
#difficulty { background: transparent; border-color: #527865; color: #243e50; font-size: 1rem; }
#difficulty:hover { background: #a9dac3; }
.token.node, .slot.node { background: var(--node-background, #e2edff); border-color: var(--node-border, #42669b); color: var(--node-text, #173f78); }
.token.leaf, .slot.leaf { background: var(--leaf-background, #fff0d5); border-color: var(--leaf-border, #906218); color: var(--leaf-text, #694000); }
.card[data-difficulty="mittel"] {
  --node-background: #f0f2f4;
  --leaf-background: #f0f2f4;
  --node-border: #526879;
  --leaf-border: #526879;
  --node-text: #192d3d;
  --leaf-text: #192d3d;
}
.bank { display: flex; flex-direction: column; justify-content: center; align-content: center; gap: .5rem; align-self: stretch; padding: 1rem; margin: 0; background: #eef0f2; }
.bank:empty::after { content: 'Alle Begriffe sind im Baum. Zum Ändern einen belegten Begriff auswählen.'; color: #405c70; }
.token { touch-action: manipulation; font-size: 1rem; min-height: 44px; }
.token[aria-pressed="true"], .slot[aria-pressed="true"] { outline: 3px solid #1e40af; outline-offset: 2px; }
.diagram-scroll { overflow-x: auto; padding: 1.25rem clamp(1.5rem, 3vw, 3.5rem); background: white; }
.tree { min-width: 600px; text-align: center; position: relative; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: auto 44px 44px auto; gap: 2rem 1rem; padding: 0 .25rem; }
.connectors { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; fill: none; stroke: #526879; stroke-width: 2; }
.tree .root, .tree .slot { position: relative; }
.root { display: inline-block; padding: .4rem 2rem; border: 1px solid #6b8192; border-radius: .45rem; background: #edf2f6; font-weight: 700; }
.root { grid-column: 1 / 4; justify-self: center; }
.branches, .branch { display: contents; }
.branch > .slot { justify-self: center; }
[data-group="flektierbar"] > .slot { grid-column: 1 / 3; grid-row: 2; }
[data-group="nicht-flektierbar"] > .slot { grid-column: 3; grid-row: 2; }
[data-group="deklinierbar"] > .slot { grid-column: 1; grid-row: 3; }
[data-group="konjugierbar"] > .slot { grid-column: 2; grid-row: 3; }
[data-group="deklinierbar"] > .leaves { grid-column: 1; }
[data-group="konjugierbar"] > .leaves { grid-column: 2; }
[data-group="nicht-flektierbar"] > .leaves { grid-column: 3; }
.slot { width: 100%; max-width: var(--item-width, 190px); min-height: 44px; height: var(--item-height, 44px); border: 2px dashed; font-size: 1rem; }
.slot.filled { border-style: solid; font-weight: 600; }
.leaves { grid-row: 4; align-self: start; justify-self: center; width: 100%; max-width: var(--item-width, 190px); list-style: none; margin: 0; padding: 0; }
.leaves li + li { margin-top: .25rem; }
.slot.dragover { outline: 3px solid #1e40af; }
.slot.correct { border: 3px solid #257341; }
.slot.incorrect { border: 3px solid #b42318; }
input.slot { font-family: inherit; text-align: center; border-radius: .45rem; padding: .4rem .6rem; }
input.slot.correct { border-style: double; border-width: 4px; }
input.slot.incorrect { border-style: dashed; }
.card[data-difficulty="schwer"] { grid-template-columns: minmax(0, 1fr); }
.card[data-difficulty="schwer"] .bank { display: none; }
.card[data-difficulty="schwer"] .tree { --item-width: clamp(190px, 20vw, 320px); }
footer { background: #f0f0ed; border-top: 1px solid #c4c7c5; border-radius: 0 0 1rem 1rem; padding: .85rem 1rem; display: flex; justify-content: flex-end; align-items: center; flex-wrap: wrap; gap: .5rem; }
footer button { background: #dce5eb; color: #243e50; border-color: #637989; font-weight: 600; }
footer button:hover { background: #cbd8e1; }
footer .secondary { background: #fafbf9; color: #354957; border-color: #73828c; font-weight: 400; }
footer .secondary:hover { background: #e3e7e7; }
#reset { margin-right: auto; display: inline-flex; align-items: center; gap: .45em; }
.button-icon { width: 1.2em; height: 1.2em; flex: none; }
#status { margin: 0; flex: 1 1 240px; font-size: 1rem; }
#status:empty { display: none; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.hover-hint:not(.visually-hidden) { position: fixed; z-index: 10; bottom: 1rem; left: 50%; transform: translateX(-50%); width: min(34rem, calc(100vw - 2rem)); margin: 0; padding: .65rem .9rem; font-size: clamp(1rem, 1.3vw, 1.15rem); line-height: 1.5; background: #192d3d; color: white; border: 2px solid white; border-radius: .6rem; box-shadow: 0 .25rem 1rem #192d3d44; }
@media (forced-colors: active) {
  .connectors { stroke: CanvasText; }
  .token[aria-pressed="true"], .slot[aria-pressed="true"] { outline: 3px solid Highlight; }
  .slot.correct, .slot.incorrect { border-color: CanvasText; }
}
@media (min-width: 1100px) {
  .card {
    --exercise-font: clamp(1rem, min(1.65vw, 2.7dvh), 1.8rem);
    --box-height: clamp(44px, 6dvh, 76px);
    --leaf-gap: clamp(.25rem, .6dvh, .5rem);
    grid-template-columns: minmax(360px, 34%) minmax(0, 1fr);
    font-size: var(--exercise-font);
  }
  h1 { font-size: clamp(1.6rem, 3dvh, 2.5rem); }
  .level, #status { font-size: max(1rem, .75em); }
  .bank { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bank:empty::after { grid-column: 1 / -1; }
  .token { font-size: inherit; min-height: var(--box-height); }
  .diagram-scroll { min-height: 0; }
  .tree {
    height: 100%;
    grid-template-rows: repeat(3, max(var(--box-height), var(--item-height, 44px))) auto;
    align-content: space-between;
    row-gap: clamp(1.5rem, 3dvh, 3rem);
  }
  .root { display: flex; align-items: center; }
  .slot { font-size: inherit; }
  .leaves { display: grid; grid-template-rows: repeat(5, var(--item-height, var(--box-height))); gap: var(--leaf-gap); }
  .leaves li + li { margin-top: 0; }
}
@media (max-width: 850px) {
  .card { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto 1fr auto; }
  .bank { flex-direction: row; flex-wrap: wrap; }
  .card[data-difficulty="schwer"] { grid-template-rows: auto 1fr auto; }
}
@media (max-width: 520px) {
  body { padding: .35rem; }
  .card { min-height: calc(100dvh - .7rem); }
  header { padding: .75rem; }
  .level { font-size: .75rem; }
}

/* Use phone-sized viewports in both browsers and device previews. */
@media (max-width: 600px),
       (max-width: 950px) and (max-height: 500px) and (pointer: coarse) {
  header { grid-template-columns: 1fr; }
  h1 { grid-column: 1; }
  .difficulty-control { grid-column: 1; grid-row: 2; justify-self: center; }
  .diagram-scroll { padding: 1rem .25rem; }
  .tree {
    min-width: 0;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: auto 80px 80px auto;
    gap: 1.25rem .25rem;
    padding: 0;
  }
  .tree .slot, .tree .leaves { max-width: 100%; min-width: 0; }
  .tree .slot { height: 80px; padding: .3rem .2rem; overflow-wrap: anywhere; }
  .bank { padding: .75rem; gap: .35rem; }
}
