:root {
  --ink: #1b1f5e;
  --ink-soft: #545a86;
  --paper: #e9ecf1;
  --card: rgba(255, 255, 255, .78);
  --line: rgba(27, 31, 94, .14);
  --accent: #2f5fd0;
  --accent-ink: #fff;
  --bar-w: 212px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--paper) url(../img/bg.jpg) center / cover fixed;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; cursor: pointer; }

#app { position: fixed; inset: 0; display: flex; }

/* ---------- Leiste: Querformat rechts (wie das Original), Hochformat oben + unten ---------- */
#bar { display: flex; flex-direction: column; gap: 14px; }
#title { font-size: 22px; font-weight: 700; letter-spacing: .01em; }
.stats { display: grid; gap: 8px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 6px 12px; display: flex; justify-content: space-between; align-items: baseline;
}
.stat .lbl { font-size: 13px; color: var(--ink-soft); }
.stat b { font-size: 19px; font-variant-numeric: tabular-nums; }
#tools { display: grid; gap: 8px; }
.tool {
  display: flex; align-items: center; gap: 10px; min-height: 44px;
  padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); font-weight: 600; text-align: left;
  transition: background .15s, transform .1s;
}
.tool:active { transform: scale(.97); }
.tool:disabled { opacity: .4; }
.tool svg { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
@media (hover: hover) { .tool:hover:not(:disabled) { background: #fff; } }

#board-wrap { position: relative; flex: 1; min-width: 0; min-height: 0; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

@media (orientation: landscape) {
  #app { flex-direction: row-reverse; }
  #bar {
    width: calc(var(--bar-w) + var(--safe-r)); flex: none;
    padding: calc(18px + var(--safe-t)) calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) 16px;
    background: rgba(255, 255, 255, .38); border-left: 1px solid var(--line);
    overflow-y: auto;
  }
  #board-wrap { margin: var(--safe-t) 0 var(--safe-b) var(--safe-l); }
}
@media (orientation: landscape) and (max-height: 500px) {
  /* iPhone quer: kompakter */
  :root { --bar-w: 178px; }
  #bar { gap: 8px; padding-top: calc(10px + var(--safe-t)); }
  #title { font-size: 18px; }
  .stats, #tools { gap: 5px; }
  .stat { padding: 3px 10px; }
  .stat b { font-size: 16px; }
  .tool { min-height: 38px; padding: 5px 10px; }
}
@media (orientation: portrait) {
  #app { flex-direction: column; }
  #bar { display: contents; }
  #title {
    order: 0; text-align: center; font-size: 19px;
    padding: calc(8px + var(--safe-t)) 16px 4px;
  }
  .stats { order: 1; grid-template-columns: repeat(3, 1fr); padding: 0 12px 6px; gap: 6px; }
  .stat { padding: 4px 10px; flex-direction: column; align-items: center; }
  .stat .lbl { font-size: 11px; }
  .stat b { font-size: 17px; }
  #board-wrap { order: 2; }
  #tools {
    order: 3; grid-template-columns: repeat(4, 1fr); gap: 6px;
    padding: 6px 10px calc(8px + var(--safe-b));
    background: rgba(255, 255, 255, .45); border-top: 1px solid var(--line);
  }
  .tool { flex-direction: column; gap: 2px; font-size: 12px; min-height: 52px; justify-content: center; text-align: center; padding: 6px 4px; }
}

/* ---------- Dialoge ---------- */
#overlay { position: fixed; inset: 0; background: rgba(20, 24, 60, .35); backdrop-filter: blur(2px); z-index: 10; }
.dlg {
  position: fixed; z-index: 11; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(460px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow-y: auto;
  background: #fbfbfd; border-radius: 16px; padding: 22px 20px 18px;
  box-shadow: 0 20px 60px rgba(20, 24, 60, .3);
}
.dlg h2 { font-size: 18px; margin: 0 0 12px; }
.dlg h2 + .choice-row { margin-bottom: 18px; }
.dlg p { margin: 0 0 10px; color: var(--ink); }
.dlg .big { font-size: 34px; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; margin: 4px 0 6px; }
.dlg .hint { font-size: 13px; color: var(--ink-soft); }
.dlg .links a { color: var(--accent); }
.dlg-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.btn {
  min-height: 44px; padding: 10px 18px; border-radius: 10px; border: 0;
  background: var(--accent); color: var(--accent-ink); font-weight: 600;
}
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.choice-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
#tilesets { grid-template-columns: repeat(3, 1fr); }
.choice {
  border: 2px solid var(--line); border-radius: 12px; background: #fff; padding: 8px 4px 6px;
  display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 13px; font-weight: 600;
}
.choice[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47, 95, 208, .15); }
.choice img { height: 40px; width: auto; }
.choice .sample { display: flex; height: 48px; }
.choice .sample span { width: 30px; height: 44px; background-size: auto 88px; background-repeat: no-repeat; margin-left: -4px; }
.choice .sample span:first-child { margin-left: 0; }
.lang-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.lang {
  min-height: 44px; border: 2px solid var(--line); border-radius: 12px; background: #fff;
  font-weight: 600; padding: 8px 12px;
}
.lang[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47, 95, 208, .15); color: var(--accent); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
