:root {
  --bg: #e9ebe6; --panel: rgba(255, 255, 255, 0.94); --text: #1f2421; --muted: #66706a; --line: #d6dbd4;
  --btn: #f4f6f2; --btnOn: #1f2421; --accent: #2b7bd6; --solid: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1b1e1c; --panel: rgba(32, 36, 33, 0.94); --text: #eef1ec; --muted: #a2aba4; --line: #3a403b;
    --btn: #2a2f2b; --btnOn: #eef1ec; --solid: #202421; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; }
#app { position: fixed; inset: 0; }
#app canvas { display: block; }

.panel { position: fixed; top: 16px; left: 16px; width: 300px; max-height: calc(100% - 32px); overflow: auto; padding: 14px 16px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 6px 24px rgba(0,0,0,0.12); z-index: 10; }
.panel.collapsed > :not(.head) { display: none; }
.panel .head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.panel h1 { font-size: 17px; margin: 0; } .panel .sub { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.panel h2 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 14px 0 6px; }
.row { display: flex; flex-wrap: wrap; gap: 6px; }
.btn { background: var(--btn); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 6px 11px;
  font: inherit; font-size: 13px; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn[aria-pressed="true"] { background: var(--btnOn); color: var(--bg); }
.help { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.chk { display: flex; align-items: center; gap: 6px; margin: 4px 0; }
input[type=range] { width: 100%; }
.info { margin-top: 14px; padding: 10px 12px; border-radius: 10px; background: rgba(127,127,127,0.08); }
.info p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.credits { color: var(--muted); font-size: 11px; margin: 12px 0 0; }

/* Room and piece labels */
.lbl { padding: 3px 8px; border-radius: 999px; background: rgba(255,255,255,0.92); color: #1f2421; font-size: 12px; font-weight: 600;
  box-shadow: 0 1px 4px rgba(0,0,0,0.18); white-space: nowrap; pointer-events: none; }
.lbl.piece { font-size: 11px; font-weight: 500; background: #fff7d6; }
.hideNames .lbl { display: none; }

#roomChip { position: fixed; left: 50%; top: 14px; transform: translateX(-50%); display: flex; align-items: center; gap: 8px;
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 999px; padding: 5px 6px 5px 14px;
  font-size: 13px; box-shadow: 0 4px 14px rgba(0,0,0,0.12); z-index: 5; max-width: calc(100% - 32px); }
#roomChip[hidden] { display: none; }
#roomChip .muted { color: var(--muted); font-size: 12px; }
#roomChip .btn { padding: 4px 12px; }

#hand { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); font-size: 26px; pointer-events: none; opacity: 0.75;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.6)); transition: transform 0.12s, opacity 0.12s; user-select: none; }
#hand.on { opacity: 1; transform: translate(-50%, -50%) scale(1.3); }
#walkHelp { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; font-size: 12px; pointer-events: none;
  max-width: calc(100% - 32px); text-align: center; }
body.walking .panel, body.walking .lbl { display: none; }

/* 2D plan */
#plan { position: fixed; inset: 0; z-index: 1000; display: flex; flex-direction: column; background: #fff; }
#plan[hidden] { display: none; }
.planBar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--panel); color: var(--text);
  border-bottom: 1px solid var(--line); font-size: 13px; }
.planBar .muted { flex: 1; color: var(--muted); font-size: 12px; }
#planSvg { flex: 1; width: 100%; min-height: 0; touch-action: none; cursor: grab; background: #fff; }
#planSvg:active { cursor: grabbing; }

@media (max-width: 640px) {
  .panel { width: calc(100% - 32px); } .planBar .muted, #roomChip .muted { display: none; }
}
@media print {
  body.inPlan > *:not(#plan) { display: none !important; }
  body.inPlan #plan { position: static; height: 100vh; }
  body.inPlan .planBar { display: none; }
}

/* Help */
.headBtns { display: flex; gap: 6px; }
#help { font-weight: 700; min-width: 34px; }
/* Language flags: the current one is framed, the other one faded until hovered */
#langs { display: flex; gap: 2px; align-items: center; }
.flag { display: grid; place-items: center; height: 19px; padding: 0 3px; background: none; border: 1.5px solid transparent; border-radius: 5px;
  cursor: pointer; opacity: 0.7; filter: grayscale(0.25); transition: opacity 0.12s, filter 0.12s; }
.flag svg { display: block; border-radius: 1px; box-shadow: 0 0 0 1px rgba(0,0,0,0.15); }
.flag:hover { opacity: 0.9; filter: none; }
.flag[aria-pressed="true"] { opacity: 1; filter: none; border-color: var(--accent); cursor: default; }
body.embedded #langs { display: none; }
#helpDialog { width: min(680px, calc(100% - 32px)); max-height: calc(100% - 48px); padding: 0; border: 1px solid var(--line); border-radius: 14px;
  background: var(--solid); color: var(--text); box-shadow: 0 12px 40px rgba(0,0,0,0.25); }
#helpDialog::backdrop { background: rgba(0,0,0,0.35); }
.dlgHead { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--solid); }
.dlgHead h2 { margin: 0; font-size: 16px; }
.dlgBody { padding: 4px 16px 14px; display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 0 20px; }
.dlgBody h3 { font-size: 13px; margin: 12px 0 4px; }
.dlgBody ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: 13px; }
.dlgBody li { margin: 3px 0; } .dlgBody b { color: var(--text); font-weight: 600; }
.dlgBody ul ul { margin-top: 2px; }
