/* Königreich - Figuren-Werkstatt im Look «Tusche auf Papier» (wie reich-tusche-probe.html): Papierkarten mit Tuschrand,
   Rot nur für die eine Hauptaktion («Übernehmen») und die Hinweis-Punkte; Auswahl zeigt das Bild mit dem roten Ring wie im Spiel. */
:root { --papier: #f2e9d4; --karte: #f8f2e3; --karte-tief: #ece2c9; --tinte: #241e19; --tinte-2: #5a5047; --rot: #b22e1c; --rot-tief: #86200f;
  --serif: Georgia, "Noto Serif", "Droid Serif", "Times New Roman", serif; --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --haar: rgba(36,30,25,.5);
  --schatten: 0 1.5px 0 rgba(36,30,25,.22), 0 7px 16px -6px rgba(60,40,20,.38);
  --vorschau-h: 100px; --wz: 44px; --karte-w: 78px; --karte-h: 86px; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
/* Papier mit feiner Faser (Rauschen als SVG, kein Bild vom Server) */
body { background-color: var(--papier); color: var(--tinte); font: 500 16px/1.4 var(--sans);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .36 0 0 0 0 .27 0 0 0 0 .16 0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--tinte-2); outline-offset: 2px; }

.blatt { background: var(--karte); border: 2px solid var(--tinte); box-shadow: inset 0 0 0 2px var(--karte), inset 0 0 0 3px var(--haar), var(--schatten); }
.siegel { background: var(--rot); color: var(--karte); border-color: var(--rot-tief);
  box-shadow: inset 0 0 0 2px var(--rot), inset 0 0 0 3px rgba(248,242,227,.42), 0 1.5px 0 var(--rot-tief), 0 6px 14px -6px rgba(90,25,10,.5); }

/* ---------- Raster: hochkant ---------- */
.werkstatt { position: fixed; inset: 0; display: grid; gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto auto minmax(0, 1fr) var(--vorschau-h) auto auto;
  grid-template-areas: "kopf kopf" "arten arten" "feld werkzeuge" "vorschau vorschau" "vorlagen vorlagen" "fuss fuss"; }
.kopf { grid-area: kopf; }
.arten { grid-area: arten; }
.feld { grid-area: feld; }
.werkzeuge { grid-area: werkzeuge; }
.vorschau { grid-area: vorschau; }
.vorlagen { grid-area: vorlagen; }
.fuss { grid-area: fuss; }

/* ---------- Kopf ---------- */
.kopf { display: flex; align-items: center; gap: 10px; min-width: 0; }
.rund { width: 46px; height: 46px; flex: 0 0 auto; border-radius: 50%; display: grid; place-items: center; color: var(--tinte); text-decoration: none;
  cursor: pointer; padding: 0; appearance: none; }
.rund svg { display: block; }
.rund:active { transform: translateY(1px); }
.titel { min-width: 0; flex: 1; }
.titel h1 { margin: 0; font: 700 1.28rem/1.15 var(--serif); letter-spacing: .005em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.titel p { margin: 1px 0 0; font: italic 400 .86rem/1.2 var(--serif); color: var(--tinte-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Reiter der Arten ---------- */
.arten { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.art { position: relative; appearance: none; min-height: 56px; padding: 3px 2px 4px; cursor: pointer; display: flex; flex-direction: column; align-items: center;
  justify-content: flex-end; gap: 1px; border-radius: 14px 11px 13px 10px / 11px 14px 10px 13px; background: transparent; border: 1.5px solid rgba(36,30,25,.32);
  box-shadow: none; font: 600 .74rem/1.1 var(--sans); color: var(--tinte-2); }
.art canvas { display: block; flex: 0 0 auto; }
.art span { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.art[aria-selected="true"] { background: var(--karte); border: 2px solid var(--tinte); color: var(--tinte); font-weight: 800;
  box-shadow: inset 0 0 0 2px var(--karte), inset 0 0 0 3px var(--haar), var(--schatten); }
.art:active { transform: translateY(1px); }
/* roter Hinweis-Punkt: hier ist etwas noch nicht übernommen */
.art .punkt { position: absolute; top: -4px; right: -3px; width: 14px; height: 14px; border-radius: 50%; background: var(--rot);
  box-shadow: 0 0 0 2px var(--karte), 0 0 0 3px var(--rot-tief); display: none; }
.art.offen .punkt { display: block; }

/* ---------- Zeichenblatt ---------- */
.feld { position: relative; min-height: 0; min-width: 0; border-radius: 16px 13px 15px 12px / 13px 16px 12px 15px; overflow: hidden; padding: 0; }
.feld canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
.feld.vorlage canvas { cursor: default; }
.wahl-leiste { position: absolute; left: 8px; right: 8px; bottom: 10px; display: flex; justify-content: center; pointer-events: none; animation: rein .25s ease-out; }
.wahl-leiste > * { pointer-events: auto; }
@keyframes rein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.feld.ruck .wahl-leiste { animation: ruck .38s ease-out; }
@keyframes ruck { 0%, 100% { transform: none; } 25% { transform: translateX(-6px); } 60% { transform: translateX(5px); } }
.tinte-knopf { appearance: none; min-height: 46px; max-width: 100%; padding: 0 16px 0 12px; display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  border-radius: 13px 11px 12px 10px; font: 700 1rem/1.1 var(--serif); color: var(--tinte); white-space: nowrap; }
.tinte-knopf:active { transform: translateY(1px); background: var(--karte-tief); }
.tinte-knopf:disabled { opacity: .45; cursor: default; }

/* ---------- Werkzeuge ---------- */
.werkzeuge { display: grid; grid-template-columns: var(--wz); grid-auto-rows: min-content; gap: 3px; align-content: start; min-height: 0; }
.werkzeuge .trenn { height: 4px; }
.wz { position: relative; appearance: none; width: var(--wz); height: var(--wz); padding: 0; display: grid; place-items: center; cursor: pointer;
  border-radius: 13px 10px 12px 9px / 10px 13px 9px 12px; color: var(--tinte); }
.wz svg { display: block; pointer-events: none; }
.wz:active { transform: translateY(1px); }
.wz[aria-pressed="true"] { background: var(--tinte); color: var(--karte); box-shadow: inset 0 0 0 2px var(--tinte), inset 0 0 0 3px rgba(248,242,227,.35), var(--schatten); }
.wz:disabled { opacity: .38; cursor: default; }
.wz .fleck { fill: var(--tinte); }
.wz .fleck.rot { fill: var(--rot); }
.wz[aria-pressed="true"] .fleck { stroke: var(--karte); stroke-width: 1.6; }
.wz .dicke-text { position: absolute; bottom: 3px; left: 0; right: 0; text-align: center; font: 700 .56rem/1 var(--sans); letter-spacing: .02em; }
#dicke svg { margin-top: -10px; }
.werkzeuge.zwei { grid-template-columns: repeat(2, var(--wz)); }
.werkzeuge.zwei .trenn { display: none; }

/* ---------- Vorschau ---------- */
.vorschau { position: relative; border-radius: 15px 12px 14px 11px / 12px 15px 11px 14px; overflow: hidden; min-height: 0; padding: 0; }
.vorschau canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------- Vorlagen-Leiste ---------- */
.vorlagen { min-width: 0; }
.vorlagen-reihe { display: flex; gap: 7px; overflow-x: auto; overflow-y: hidden; padding: 9px 2px 3px; scroll-snap-type: x proximity; scrollbar-width: none;
  overscroll-behavior-x: contain; }
.vorlagen-reihe::-webkit-scrollbar { display: none; }
@media (hover: hover) and (pointer: fine) {
  .vorlagen-reihe { scrollbar-width: thin; scrollbar-color: rgba(36,30,25,.35) transparent; }
  .vorlagen-reihe::-webkit-scrollbar { display: block; height: 6px; }
  .vorlagen-reihe::-webkit-scrollbar-thumb { background: rgba(36,30,25,.3); border-radius: 3px; }
}
.karte { position: relative; flex: 0 0 auto; width: var(--karte-w); height: var(--karte-h); appearance: none; padding: 3px 3px 4px; cursor: pointer; scroll-snap-align: start;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between; border-radius: 14px 11px 13px 10px / 11px 14px 10px 13px;
  font: 600 .68rem/1.05 var(--sans); color: var(--tinte-2); text-align: center; }
.karte canvas { display: block; flex: 0 0 auto; }
.karte span { display: block; max-width: 100%; overflow-wrap: anywhere; hyphens: manual; }
.karte[aria-pressed="true"] { border-width: 3px; color: var(--tinte); font-weight: 800; padding: 2px 2px 3px; }
.karte:active { transform: translateY(1px); background: var(--karte-tief); }
/* «im Spiel»: ein Zettel, der oben auf dem Kartenrand klebt, damit er das Bildchen nicht verdeckt */
.karte .marke { position: absolute; top: -8px; left: 50%; transform: translateX(-50%) rotate(-2.5deg); white-space: nowrap; pointer-events: none;
  font: italic 700 .58rem/1 var(--serif); color: var(--tinte); background: var(--karte);
  border: 1px solid var(--tinte); border-radius: 7px 6px 7px 5px; padding: 2px 5px 1px; box-shadow: 0 1px 0 rgba(36,30,25,.18); }
.karte.eigen-leer canvas { opacity: .9; }

/* ---------- Fuss: Stand und Hauptaktion ---------- */
.fuss { display: flex; align-items: center; gap: 10px; min-width: 0; }
.stand { flex: 1; min-width: 0; margin: 0; font: 400 .84rem/1.25 var(--serif); color: var(--tinte-2);
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3; overflow: hidden; overflow-wrap: anywhere; }
.stand b { font-weight: 700; color: var(--tinte); }
.knopf { appearance: none; border: 2px solid var(--rot-tief); border-radius: 14px 12px 13px 11px; min-height: 50px; padding: 0 20px 0 16px;
  display: inline-flex; align-items: center; gap: 8px; font: 700 1.08rem/1 var(--serif); cursor: pointer; flex: 0 0 auto; }
.knopf:active { transform: translateY(1px); }
.knopf:disabled { cursor: default; }
/* gesperrt: keine blasse Siegel-Taste, sondern eine Papier-Taste mit grauem Tuschrand und gedämpfter Schrift; Rot heisst «jetzt» */
.knopf.siegel:disabled { background: var(--karte-tief); color: rgba(36,30,25,.42); border: 2px solid rgba(36,30,25,.34);
  box-shadow: inset 0 0 0 2px var(--karte-tief), inset 0 0 0 3px rgba(36,30,25,.12); transform: none; }
.knopf.siegel:disabled svg { opacity: .7; }

/* Hinweis oben auf dem Blatt (Lage setzt das Skript nach dem Blatt), damit er weder Vorschau noch Vorlagen verdeckt */
.hinweis { position: fixed; z-index: 10; left: var(--hinweis-x, 50%); top: var(--hinweis-y, 12px); transform: translateX(-50%);
  width: max-content; max-width: var(--hinweis-b, min(88vw, 520px)); padding: 8px 14px; font-size: .92rem; border-radius: 15px 12px 14px 11px / 12px 15px 11px 14px;
  border: 2px solid var(--tinte); box-shadow: inset 0 0 0 2px var(--karte), inset 0 0 0 3.2px var(--tinte-2), var(--schatten);
  color: var(--tinte); font-weight: 700; text-align: center; line-height: 1.3; text-wrap: balance; pointer-events: none; animation: erscheint .3s ease-out; }
/* hochkant: über dem Titel im Kopf, knapp gesetzt, damit er das Blatt nicht verdeckt */
.hinweis.im-kopf { width: var(--hinweis-b); max-width: var(--hinweis-b); padding: 5px 10px; font-size: .84rem; line-height: 1.22; }
@keyframes erscheint { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- Quer und Schreibtisch: links Wahl und Vorschau, Mitte das Blatt, rechts die Werkzeuge ---------- */
@media (orientation: landscape) and (min-width: 640px) {
  .werkstatt { grid-template-columns: clamp(296px, 33vw, 400px) minmax(0, 1fr) auto; column-gap: 10px;
    grid-template-rows: auto auto auto minmax(96px, 1fr) auto;
    grid-template-areas: "kopf feld werkzeuge" "arten feld werkzeuge" "vorlagen feld werkzeuge" "vorschau feld werkzeuge" "fuss feld werkzeuge"; }
}
/* hoch genug: alle Vorlagen auf einen Blick, zwei Reihen statt einer Wischleiste (gleich hoch für jede Art, damit die
   Vorschau darunter nicht springt); ist die Vorschau hoch, zeigt sie oben die Figur nah und unten in Spielgrösse */
@media (orientation: landscape) and (min-width: 640px) and (min-height: 560px) {
  .vorlagen-reihe { flex-wrap: wrap; align-content: flex-start; overflow-x: hidden; overflow-y: auto; scroll-snap-type: none; row-gap: 12px;
    height: calc(2 * var(--karte-h) + 24px); }
  .vorschau { max-height: 440px; align-self: end; height: 100%; }
}
@media (orientation: landscape) and (max-height: 500px) and (min-width: 640px) {
  .werkstatt { row-gap: 6px; padding-top: max(6px, env(safe-area-inset-top)); padding-bottom: max(6px, env(safe-area-inset-bottom)); }
  .rund { width: 44px; height: 44px; }
  .titel h1 { font-size: 1.08rem; }
  .titel p { font-size: .76rem; }
  .art { min-height: 50px; padding: 3px 1px 4px; font-size: .66rem; }
  :root { --karte-w: 74px; --karte-h: 80px; }
  .karte { font-size: .64rem; }
  .knopf { min-height: 46px; }
  .werkzeuge { grid-template-columns: repeat(2, var(--wz)); }
  .werkzeuge .trenn { display: none; }
}
@media (min-width: 1000px) and (min-height: 600px) {
  :root { --wz: 50px; --karte-w: 88px; --karte-h: 96px; }
  .titel h1 { font-size: 1.45rem; }
  .art { min-height: 64px; font-size: .8rem; }
}
@media (max-width: 359px) {
  .titel p { display: none; }
  .art { font-size: .66rem; }
}
