:root {
  --bg: #f3f1ee;
  --paper: #ffffff;
  --line: #9a9a9a;
  --frame: #6b6b6b;
  --clue: #f1dfcc;
  --clue-line: #c9b29a;
  --clue-text: #3a3330;
  --letter: #1d1d1d;
  --revealed: #0b6e8a;
  --select: #ffd34d;
  --word: #fff3c4;
  --blocked: #e4e1dc;
  --arrow: #4d4d4d;
  --cols: 14;
  --side: 280px;            /* Breite der Seitenleiste (Desktop) */
  --side-bg: #ffffff;
  --accent: #b5713a;
  /* Zellgröße: max. 56 CSS-px, auf schmalen Bildschirmen an die Breite angepasst.
     Browser-Zoom vergrößert alles (reine CSS-/SVG-Darstellung, keine Pixelgrafik). */
  --cs: min(56px, calc((100vw - var(--side) - 40px) / var(--cols)));
}
@media (max-width: 900px) {
  :root { --side: 0px; }
}

/* ---------- Layout mit Seitenleiste ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--side); flex: 0 0 var(--side); background: var(--side-bg);
  border-right: 1px solid #ddd8d0; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 12px 10px 16px; border-bottom: 1px solid #eee9e2;
}
.side-head h2 { margin: 0; font-size: 1rem; font-weight: 600; letter-spacing: .02em; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px;
  border: 1px solid transparent; border-radius: 6px; background: transparent; cursor: pointer; color: #444; padding: 0;
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover { background: #f1ede7; border-color: #e2dcd3; }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.icon-btn.add { background: var(--clue); border-color: var(--clue-line); color: #5a4330; }
.icon-btn.add:hover { background: #ead2b9; }
.icon-btn.small { width: 28px; height: 28px; }
.icon-btn.small svg { width: 16px; height: 16px; }

.project-list { list-style: none; margin: 0; padding: 6px 0; }
.project {
  display: flex; align-items: center; gap: 6px; padding: 8px 8px 8px 16px; cursor: pointer;
  border-left: 3px solid transparent;
}
.project:hover { background: #faf7f3; }
.project:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.project.active { background: #f6ece1; border-left-color: var(--accent); }
.p-main { flex: 1 1 auto; min-width: 0; }
.p-title { font-size: .92rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-meta { font-size: .75rem; color: #777; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.project.st-error .p-meta { color: #a33; }
.project.st-running .p-meta { color: var(--accent); }
.p-actions { display: flex; gap: 2px; opacity: .55; }
.project:hover .p-actions, .project.active .p-actions, .project:focus-within .p-actions { opacity: 1; }
.list-msg { padding: 12px 16px; font-size: .85rem; color: #777; margin: 0; }

.topbar { display: flex; align-items: center; justify-content: center; gap: 8px; position: relative; width: 100%; }
.icon-btn.menu { display: none; position: absolute; left: 0; }
.project-desc { margin: -6px 0 12px; color: #666; font-size: .88rem; text-align: center; max-width: 46rem; white-space: pre-line; }
.board-msg {
  margin: 40px 0; padding: 24px 28px; max-width: 34rem; background: #fff; border: 1px dashed #c9b29a;
  border-radius: 8px; color: #555; white-space: pre-line; text-align: center; line-height: 1.5;
}
#stage { display: flex; flex-direction: column; align-items: center; }
#stage[hidden] { display: none; }
.wrap { flex: 1 1 auto; min-width: 0; }

@media (max-width: 900px) {
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 20; width: 300px; max-width: 85vw;
    transform: translateX(-105%); transition: transform .2s ease; box-shadow: 2px 0 16px rgba(0,0,0,.12);
  }
  body.side-open .sidebar { transform: none; }
  .icon-btn.menu { display: inline-flex; }
  .topbar h1 { padding: 0 40px; }
  .p-actions { opacity: 1; }
}

/* ---------- Dialoge ---------- */
.dlg {
  border: 0; border-radius: 10px; padding: 0; width: min(520px, calc(100vw - 32px));
  box-shadow: 0 12px 40px rgba(0,0,0,.25); color: #222;
}
.dlg::backdrop { background: rgba(40, 32, 25, .35); }
.dlg form { padding: 20px 22px 18px; }
.dlg h3 { margin: 0 0 14px; font-size: 1.1rem; }
.dlg .field { display: block; margin: 0 0 14px; font-size: .88rem; font-weight: 600; color: #444; border: 0; padding: 0; }
.dlg .field legend { padding: 0; margin-bottom: 6px; }
.dlg input[type=text], .dlg input[type=number], .dlg textarea {
  font: inherit; font-weight: 400; font-size: .95rem; border: 1px solid #c8c2ba; border-radius: 5px; padding: 7px 9px;
  background: #fff; color: #222;
}
.dlg .field > input, .dlg .field > textarea { display: block; width: 100%; margin-top: 5px; }
.dlg textarea { resize: vertical; min-height: 80px; }
.dlg input:focus, .dlg textarea:focus { outline: 2px solid #e2b98f; border-color: var(--accent); }
.size-row { display: flex; align-items: flex-end; gap: 10px; font-weight: 400; }
.size-row label { display: flex; flex-direction: column; gap: 4px; font-size: .82rem; }
.size-row input { width: 90px; }
.times { padding-bottom: 8px; color: #777; }
.radio { display: flex; align-items: center; gap: 8px; font-weight: 400; margin: 6px 0; flex-wrap: wrap; }
.radio input[type=number] { width: 80px; }
.radio input[type=text] { width: 180px; text-transform: uppercase; }
.radio input.inactive { background: #f3f1ee; color: #999; }
.dlg-error { color: #a00; font-size: .88rem; margin: 0 0 10px; }
.dlg-buttons { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.dlg-buttons button {
  font: inherit; font-size: .92rem; padding: 7px 16px; border-radius: 5px; border: 1px solid #bbb; background: #fff; cursor: pointer;
}
.dlg-buttons button:hover { background: #f5f5f5; }
.dlg-buttons .primary { background: var(--accent); border-color: #9a5c2c; color: #fff; }
.dlg-buttons .primary:hover { background: #a2622f; }
.dlg-buttons .primary:disabled { opacity: .6; cursor: wait; }
.dlg-buttons .danger { background: #b3362f; border-color: #922a24; color: #fff; }
.dlg-buttons .danger:hover { background: #9d2e28; }
.dlg-small p { margin: 0 0 16px; line-height: 1.45; }

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: #222;
  font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }

.wrap { max-width: 100%; padding: 12px 16px 24px; display: flex; flex-direction: column; align-items: center; }
h1 { font-size: 1.25rem; font-weight: 600; margin: 4px 0 12px; text-align: center; }

.board {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cs));
  grid-template-rows: repeat(var(--rows), var(--cs));
  border: 2px solid var(--frame);
  background: var(--paper);
  user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
}

.cell { position: relative; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); overflow: hidden; }
.cell.last-col { border-right: 0; }
.cell.last-row { border-bottom: 0; }

/* Buchstabenfelder */
.cell.letter { background: var(--paper); cursor: pointer; }
.cell.letter.in-word { background: var(--word); }
.cell.letter.selected { background: var(--select); }
.cell .ch {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--cs) * 0.56); font-weight: 600; color: var(--letter); line-height: 1;
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
}
.cell.revealed .ch { color: var(--revealed); }

.cell svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.arrow path { fill: none; stroke: var(--arrow); stroke-width: 3.2; stroke-linejoin: round; }
.arrow polygon { fill: var(--arrow); }
.circle-mark circle { fill: none; stroke: #555; stroke-width: 2.2; }
.circle-mark text { fill: #333; font-size: 19px; font-weight: 600; font-family: Arial, sans-serif; }

/* Fragezellen */
.cell.clue { background: var(--clue); display: flex; flex-direction: column; cursor: default; }
.clue-part {
  flex: 1 1 0; min-height: 0; display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 0 2px; color: var(--clue-text);
  font-family: "Arial Narrow", "Roboto Condensed", "Helvetica Neue", Arial, sans-serif;
  font-stretch: condensed; font-weight: 600; line-height: 1.02; letter-spacing: -0.01em;
  hyphens: manual; overflow-wrap: break-word;
}
.clue-part + .clue-part { border-top: 1px solid var(--clue-line); }
.clue-part span { display: block; }

/* gesperrt (nicht Teil des Rätsels) */
.cell.blocked { background: var(--blocked); }

.footer { display: flex; align-items: center; justify-content: center; gap: 24px; flex-wrap: wrap; margin-top: 14px; }
.solution { display: flex; gap: 4px; }
.sol-box {
  position: relative; width: calc(var(--cs) * 0.85); height: calc(var(--cs) * 0.85);
  min-width: 30px; min-height: 30px; background: var(--paper); border: 1px solid var(--frame);
  display: flex; align-items: center; justify-content: center; font-weight: 600;
  font-size: max(16px, calc(var(--cs) * 0.45));
}
.sol-box small { position: absolute; right: 3px; bottom: 1px; font-size: 10px; font-weight: 400; color: #666; }
.sol-box.revealed { color: var(--revealed); }

.tools button {
  font: inherit; font-size: 0.9rem; padding: 6px 14px; border: 1px solid #aaa; border-radius: 4px;
  background: #fff; cursor: pointer;
}
.tools button:hover { background: #f5f5f5; }
.hint { font-size: 0.82rem; color: #666; text-align: center; max-width: 46rem; margin: 12px 0 0; }
.error { color: #a00; }

.kbd { position: fixed; left: -1000px; top: 0; width: 1px; height: 1px; opacity: 0; }

@media print {
  body { background: #fff; }
  .hint, .tools, .sidebar, .icon-btn.menu { display: none; }
  .cell.letter.selected, .cell.letter.in-word { background: #fff; }
}
