:root {
  --paper: #f2efe7;
  --ink: #231e16;
  --accent: #f4b829;
  --mint: #93d3b0;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1b1712;
  color: var(--ink);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

#stage, #stage canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

#crosshair {
  position: fixed; left: 50%; top: 50%; width: 8px; height: 8px; margin: -4px 0 0 -4px;
  border-radius: 50%; border: 1.5px solid rgba(255, 255, 255, .9); box-shadow: 0 0 0 1px rgba(0, 0, 0, .35);
  pointer-events: none; transition: transform .15s ease, background .15s ease;
}
#crosshair.hot { transform: scale(1.8); background: var(--accent); }
body.free-cursor #crosshair { display: none; }

#hover-tag {
  position: fixed; left: 50%; top: calc(50% + 22px); transform: translateX(-50%);
  padding: 5px 12px; border-radius: 999px; background: var(--paper); border: 1.5px solid var(--ink);
  font: 700 12px/1.3 ui-monospace, Menlo, monospace; letter-spacing: .04em; text-transform: uppercase;
  pointer-events: none; white-space: nowrap; box-shadow: 0 3px 0 var(--ink);
}
body.free-cursor #hover-tag { left: var(--tag-x, 50%); top: calc(var(--tag-y, 50%) + 22px); }

.overlay {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 16px;
  background: rgba(27, 23, 18, .55); backdrop-filter: blur(3px);
}
.overlay[hidden] { display: none; }

.card {
  width: min(440px, 100%); padding: 28px 28px 24px; border-radius: 14px;
  background: var(--paper); border: 2px solid var(--ink); box-shadow: 0 6px 0 var(--ink);
}
.card h1 { margin: 0 0 6px; font: 800 30px/1.1 ui-serif, Georgia, serif; }
.card p { margin: 0 0 14px; }
.keys { margin: 0 0 18px; padding: 0; list-style: none; display: grid; gap: 6px; font-size: 14px; }
kbd {
  display: inline-block; min-width: 22px; margin-right: 3px; padding: 1px 5px; border-radius: 5px; text-align: center;
  border: 1.5px solid var(--ink); background: #fff; font: 700 11px/1.5 ui-monospace, Menlo, monospace;
}

.btn {
  all: unset; cursor: pointer; display: inline-block; padding: 10px 22px; border-radius: 999px;
  background: var(--accent); border: 2px solid var(--ink); box-shadow: 0 3px 0 var(--ink);
  font: 800 14px/1 ui-monospace, Menlo, monospace; letter-spacing: .04em; text-transform: uppercase;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.btn:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }

.sheet {
  width: min(1040px, 100%); height: min(860px, 100%); display: flex; flex-direction: column; overflow: hidden;
  background: var(--paper); border: 2px solid var(--ink); border-radius: 14px; box-shadow: 0 8px 0 var(--ink);
  animation: pop .22s cubic-bezier(.2, 1.4, .4, 1);
}
@keyframes pop { from { transform: scale(.94); opacity: 0; } }
.sheet header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 12px 10px 20px; border-bottom: 2px solid var(--ink);
}
.sheet h2 { margin: 0; font: 800 18px/1.2 ui-monospace, Menlo, monospace; letter-spacing: .04em; text-transform: uppercase; }
.close {
  all: unset; cursor: pointer; width: 34px; height: 34px; border-radius: 50%; text-align: center;
  font: 700 24px/32px ui-sans-serif, system-ui, sans-serif; border: 2px solid var(--ink); background: #fff;
}
.close:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.sheet-body { flex: 1; min-height: 0; display: flex; }
.frame-wrap { position: relative; flex: 1; min-width: 0; }
.frame-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: var(--paper); }
.missing { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; }
.missing[hidden] { display: none; }
.missing code { font: 13px ui-monospace, Menlo, monospace; background: #fff; padding: 1px 5px; border-radius: 4px; }

/* reading levels: five tabs and the text for the chosen one, beside the figure */
.levels { width: 340px; flex: none; display: flex; flex-direction: column; min-height: 0; border-left: 2px solid var(--ink); background: #fbf9f3; }
.levels[hidden] { display: none; }
.level-tabs { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; padding: 10px; border-bottom: 2px solid var(--ink); }
.level-tab {
  all: unset; cursor: pointer; display: grid; justify-items: center; gap: 2px; padding: 6px 2px 5px; border-radius: 8px;
  border: 1.5px solid var(--ink); background: #fff; text-align: center;
}
.level-tab[aria-selected="true"] { background: var(--accent); box-shadow: 0 2px 0 var(--ink); }
.level-tab:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.level-num { font: 800 15px/1 ui-monospace, Menlo, monospace; }
.level-name { font: 700 9px/1.1 ui-monospace, Menlo, monospace; letter-spacing: .02em; text-transform: uppercase; }
.level-text { flex: 1; overflow-y: auto; padding: 4px 18px 18px; font-size: 14.5px; line-height: 1.55; -webkit-user-select: text; user-select: text; }
.level-text:focus-visible { outline: 3px solid var(--ink); outline-offset: -3px; }
.level-text p { margin: 12px 0 0; }
.level-text .level-who { font: 700 11px/1.3 ui-monospace, Menlo, monospace; letter-spacing: .05em; text-transform: uppercase; color: #6b6253; }
.level-text .level-try { padding: 8px 10px; border-radius: 8px; background: #fff; border: 1.5px dashed var(--ink); }
.level-text .level-try b { margin-right: 6px; font: 800 11px/1 ui-monospace, Menlo, monospace; text-transform: uppercase; letter-spacing: .05em; }
@media (max-width: 820px) {
  .sheet-body { flex-direction: column; }
  .levels { width: auto; height: 42%; border-left: 0; border-top: 2px solid var(--ink); }
}

#pad {
  display: none; position: fixed; left: 16px; bottom: calc(16px + env(safe-area-inset-bottom));
  grid-template: repeat(3, 48px) / repeat(3, 48px); gap: 4px;
}
#pad button {
  all: unset; display: grid; place-items: center; border-radius: 10px; color: var(--ink);
  background: rgba(242, 239, 231, .85); border: 2px solid var(--ink); font-size: 16px; touch-action: none;
}
#pad button.down { background: var(--accent); }
#pad [data-move="fwd"] { grid-area: 1 / 2; }
#pad [data-move="left"] { grid-area: 2 / 1; }
#pad [data-move="back"] { grid-area: 3 / 2; }
#pad [data-move="right"] { grid-area: 2 / 3; }

.touch-only { display: none; }
@media (pointer: coarse) {
  .touch-only { display: block; }
  #pad { display: grid; }
  #crosshair { display: none; }
}
@media (max-width: 560px) {
  .overlay { padding: 0; }
  .sheet { border-radius: 0; border-width: 0; box-shadow: none; height: 100%; }
}
