:root {
  --bg: #000;
  --fg: #f4efe6;
  --muted: #b9b0a2;
  --accent: #d8b46a;
  --glass: rgba(28, 26, 24, 0.72);
  --glass-edge: rgba(255, 255, 255, 0.14);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden; overscroll-behavior: none; touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
}

#stage { position: fixed; inset: 0; }
#screen { width: 100%; height: 100%; display: block; }
/* With the touch pad, main.js places the stage (touch-hit.js stageArea). */

#overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 0.6rem; padding: 1.5rem; text-align: center;
  background: radial-gradient(circle at 50% 40%, #2a241c 0%, #000 70%);
}
#overlay[hidden] { display: none; }
#overlay h1 { font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif; font-weight: 400; font-size: clamp(1.8rem, 5vw, 3rem); margin: 0; letter-spacing: 0.02em; }
#overlay .progress { width: min(22rem, 80vw); height: 4px; border-radius: 2px; background: rgba(255,255,255,0.12); overflow: hidden; }
#progress-bar { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
#overlay .hint { color: var(--muted); font-size: 0.85rem; }
#overlay.error #status-text { color: #ff9b8a; }
#overlay.error .progress, #overlay.error .hint { display: none; }
#overlay #status-text { max-width: min(30rem, 86vw); text-align: center; }
#overlay-action { font: inherit; color: inherit; background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.25); border-radius: 999px; padding: 0.5rem 1.4rem; cursor: pointer; }
#overlay-action:hover, #overlay-action:focus-visible { background: rgba(255,255,255,0.2); }
#overlay-action[hidden] { display: none; }

/* Tester sign-in (tester edition only), in the overlay */
#signin { display: flex; flex-direction: column; align-items: stretch; gap: 0.55rem; width: min(20rem, 86vw); margin-top: 0.4rem; }
#signin[hidden] { display: none; }
#overlay.signin .progress, #overlay.signin .hint, #overlay.signin #status-text:empty { display: none; }
#signin .lead { margin: 0; color: var(--accent); font-size: 0.85rem; letter-spacing: 0.12em; text-transform: uppercase; }
#signin-msg { margin: 0; min-height: 1.4em; color: var(--fg); }
#signin-msg.bad { color: #ff9b8a; }
#signin input {
  font: 1.05rem ui-monospace, monospace; letter-spacing: 0.08em; text-align: center; color: var(--fg);
  padding: 0.65rem 0.9rem; border-radius: 12px; border: 1px solid var(--glass-edge); background: rgba(255,255,255,0.08);
  -webkit-user-select: text; user-select: text; touch-action: manipulation; outline: none;
}
#signin input:focus { border-color: var(--accent); background: rgba(255,255,255,0.12); }
#signin button {
  font: inherit; color: var(--fg); cursor: pointer; padding: 0.6rem 1.4rem; border-radius: 999px;
  background: rgba(216,180,106,0.22); border: 1px solid rgba(216,180,106,0.55);
}
#signin button:hover, #signin button:focus-visible { background: rgba(216,180,106,0.34); outline: none; }
#signin button[disabled] { opacity: 0.5; cursor: default; }
#signin .note { margin: 0; color: var(--muted); font-size: 0.8rem; }

#hud { position: fixed; top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right)); display: flex; gap: 8px; z-index: 5; opacity: 0.35; transition: opacity 0.2s; }
#hud:hover, body.menu-open #hud, body.touch #hud { opacity: 0.85; }
#hud button {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--glass-edge);
  background: var(--glass); color: var(--fg); display: grid; place-items: center; cursor: pointer;
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
#hud button[hidden] { display: none; }
#menu-button { display: flex !important; flex-direction: column; justify-content: center; gap: 4px; }
#menu-button span { display: block; width: 18px; height: 2px; background: currentColor; border-radius: 1px; margin: 0 auto; }

/* "Tap for sound": shown while the page wants sound and the browser has it
   off (main.js). Under the menu button, away from the thumbs. */
#sound-button {
  position: fixed; z-index: 6; top: calc(max(10px, env(safe-area-inset-top)) + 50px); right: max(10px, env(safe-area-inset-right));
  display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px 0 11px; border-radius: 12px;
  font: inherit; font-size: 0.95rem; color: var(--fg); background: var(--glass); border: 1px solid var(--accent); cursor: pointer;
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); box-shadow: 0 4px 18px rgba(0,0,0,0.4);
}
#sound-button[hidden] { display: none; }
#sound-button svg { color: var(--accent); flex: none; }
/* While the button shows, a toast at the top (touch pad) goes below it. */
body.touch.sound-off:not(.pad-hidden) #toast { bottom: auto; top: calc(max(10px, env(safe-area-inset-top)) + 104px); }

#stats { position: fixed; left: 10px; top: 10px; margin: 0; font: 12px ui-monospace, monospace; color: #9f9; z-index: 5; }
#toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20;
  padding: 0.55rem 1rem; border-radius: 999px; background: var(--glass); border: 1px solid var(--glass-edge);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); margin: 0;
}
/* A toast never takes a tap (the Start button may be under it). */
#toast { pointer-events: none; }
/* Over the start screen it goes to the top, clear of the Start button. */
body.info-open #toast { bottom: auto; top: max(12px, env(safe-area-inset-top)); width: max-content; max-width: calc(100vw - 32px); text-align: center; border-radius: 18px; }
/* With the touch pad the toast goes to the top, under the menu buttons. */
body.touch:not(.pad-hidden) #toast { bottom: auto; top: calc(max(10px, env(safe-area-inset-top)) + 52px); max-width: calc(100vw - 32px); text-align: center; border-radius: 18px; }

#menu { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; background: rgba(0,0,0,0.45); }
#menu[hidden] { display: none; }
#menu .sheet {
  width: min(24rem, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow: auto;
  padding: 1.1rem; border-radius: 20px; background: var(--glass); border: 1px solid var(--glass-edge);
  -webkit-backdrop-filter: blur(24px) saturate(1.4); backdrop-filter: blur(24px) saturate(1.4);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
#menu h2 { font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif; font-weight: 400; margin: 0.1rem 0.3rem 0.8rem; font-size: 1.4rem; }
#menu section { display: flex; flex-direction: column; gap: 6px; }
#menu section[hidden] { display: none; }
#menu button {
  font: inherit; color: var(--fg); text-align: left; padding: 0.7rem 0.9rem; border-radius: 12px; cursor: pointer;
  background: rgba(255,255,255,0.06); border: 1px solid transparent; display: flex; justify-content: space-between; align-items: center;
}
#menu button:hover, #menu button:focus-visible { background: rgba(255,255,255,0.14); outline: none; border-color: var(--glass-edge); }
#menu button[disabled] { opacity: 0.4; cursor: default; }
/* `hidden` must win over the display rules above (hidden menu entries,
   e.g. save states switched off by the game's "ui" settings, or Change Disc
   on a one-disc game). */
#menu [hidden] { display: none !important; }
#menu button.back { margin-top: 0.4rem; justify-content: center; }
#menu kbd { font: 12px ui-monospace, monospace; color: var(--muted); }
#menu small { color: var(--muted); }
#menu label { display: flex; gap: 0.6rem; align-items: center; padding: 0.45rem 0.4rem; }
#menu select { margin-left: auto; font: inherit; background: #222; color: var(--fg); border-radius: 8px; border: 1px solid var(--glass-edge); padding: 0.2rem 0.4rem; }
#menu .note { color: var(--muted); font-size: 0.9rem; margin: 0 0.3rem 0.4rem; }
#disc-list { display: flex; flex-direction: column; gap: 6px; }
#menu textarea {
  font: inherit; color: var(--fg); background: rgba(0,0,0,0.3); border: 1px solid var(--glass-edge); border-radius: 12px;
  padding: 0.6rem 0.75rem; resize: vertical; min-height: 6rem; -webkit-user-select: text; user-select: text; touch-action: manipulation;
}
#menu textarea:focus { outline: none; border-color: var(--accent); }
#menu button#bug-save { justify-content: center; background: rgba(216,180,106,0.22); border-color: rgba(216,180,106,0.55); }
#menu button#bug-save:hover, #menu button#bug-save:focus-visible { background: rgba(216,180,106,0.34); }
#menu button#bug-share { justify-content: center; }
#bug-result { -webkit-user-select: text; user-select: text; }
#menu table { border-collapse: collapse; margin: 0 0.3rem; }
#menu th { text-align: left; font-weight: 500; padding: 0.2rem 1rem 0.2rem 0; color: var(--muted); }
#menu td { padding: 0.2rem 0; }
#licences-text { white-space: pre-wrap; font: 12px/1.45 ui-monospace, monospace; max-height: 60vh; overflow: auto; margin: 0; padding: 0.5rem; background: rgba(0,0,0,0.3); border-radius: 10px; -webkit-user-select: text; user-select: text; }

/* Start screen and How to Play (main.js showInfo): the game's description
   and controls, above everything but the menu and toasts. One table per
   section; on narrow screens each row stacks (action, then the keys). */
#info {
  position: fixed; inset: 0; z-index: 7; display: grid; place-items: center;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: radial-gradient(circle at 50% 30%, #2a241c 0%, #000 75%);
  touch-action: pan-y;
}
#info[hidden] { display: none; }
#info .sheet {
  display: flex; flex-direction: column; width: min(46rem, 100%); max-height: 100%;
  border-radius: 20px; background: var(--glass); border: 1px solid var(--glass-edge);
  -webkit-backdrop-filter: blur(24px) saturate(1.4); backdrop-filter: blur(24px) saturate(1.4);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5); overflow: hidden;
}
#info .body { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 1.2rem 1.3rem 0.6rem; touch-action: pan-y; }
#info h1 { font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif; font-weight: 400; font-size: clamp(1.6rem, 4.5vw, 2.4rem); margin: 0 0 0.5rem; letter-spacing: 0.02em; text-align: center; }
#info-text p { margin: 0 auto 0.6rem; max-width: 38rem; line-height: 1.5; }
#info h2 { margin: 1rem 0 0.35rem; color: var(--accent); font-size: 0.8rem; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; }
#info table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
#info th { text-align: left; font-weight: 500; color: var(--muted); font-size: 0.75rem; padding: 0.15rem 0.6rem 0.25rem 0; border-bottom: 1px solid var(--glass-edge); }
#info td { padding: 0.32rem 0.6rem 0.32rem 0; vertical-align: top; border-bottom: 1px solid rgba(255,255,255,0.06); }
#info td.act { width: 40%; }
#info kbd {
  display: inline-block; min-width: 1.5em; padding: 0 0.35em; border-radius: 6px; text-align: center;
  font: 600 0.82rem/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; color: var(--fg);
  background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.22); white-space: nowrap;
}
#info td.pad kbd { border-color: rgba(216,180,106,0.6); background: rgba(216,180,106,0.16); }
#info .note { color: var(--muted); font-size: 0.8rem; margin: 0.8rem 0 0.2rem; }
#info .foot { display: flex; flex-direction: column; align-items: center; gap: 0.3rem; padding: 0.7rem 1rem 0.9rem; border-top: 1px solid var(--glass-edge); }
#info-start {
  font-family: inherit; font-size: 1.15rem; font-weight: 600; line-height: 1; color: var(--fg); cursor: pointer; min-width: 12rem; min-height: 48px; padding: 0.8rem 2.4rem; border-radius: 999px;
  background: rgba(216,180,106,0.3); border: 1px solid rgba(216,180,106,0.7); touch-action: manipulation;
}
#info-start:hover, #info-start:focus-visible { background: rgba(216,180,106,0.45); outline: 2px solid var(--accent); outline-offset: 2px; }
#info .foot .note { margin: 0; text-align: center; }
/* The game's links (about.links): quieter than Start; a "donate" link gets
   a touch of the accent. They open in a new tab. */
#info-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.4rem 0.6rem; }
#info-links[hidden], #menu-links[hidden] { display: none; }
#info-links a {
  color: var(--muted); font-size: 0.85rem; text-decoration: none; padding: 0.35rem 0.8rem; min-height: 32px; display: inline-flex; align-items: center;
  border-radius: 999px; border: 1px solid var(--glass-edge); background: rgba(255,255,255,0.04); touch-action: manipulation;
}
#info-links a:hover, #info-links a:focus-visible { color: var(--fg); background: rgba(255,255,255,0.1); outline: 2px solid var(--accent); outline-offset: 1px; }
#info-links a.kind-donate { color: var(--accent); border-color: rgba(216,180,106,0.45); }
#info-links a::after, #menu-links a::after { content: " \2197"; font-size: 0.8em; opacity: 0.7; }
#menu-links { display: flex; flex-direction: column; gap: 6px; }
#menu-links a {
  color: var(--fg); text-decoration: none; padding: 0.7rem 0.9rem; border-radius: 12px; background: rgba(255,255,255,0.06); border: 1px solid transparent;
}
#menu-links a:hover, #menu-links a:focus-visible { background: rgba(255,255,255,0.14); outline: none; border-color: var(--glass-edge); }
#menu-links a.kind-donate { color: var(--accent); }
@media (max-width: 599px) {
  #info .body { padding: 1rem 1rem 0.5rem; }
  #info thead { display: none; }
  #info tr { display: grid; grid-template-columns: repeat(3, auto); justify-content: start; column-gap: 0.9rem; row-gap: 0.15rem; padding: 0.4rem 0; border-bottom: 1px solid rgba(255,255,255,0.06); }
  #info td { display: block; padding: 0; border: 0; }
  #info td.act { grid-column: 1 / -1; width: auto; }
  #info td:not(.act)::before { content: attr(data-label); display: block; color: var(--muted); font-size: 0.68rem; letter-spacing: 0.04em; }
}
@media (max-height: 500px) {
  #info .body { padding-top: 0.8rem; }
  #info h1 { font-size: 1.5rem; margin-bottom: 0.3rem; }
  #info .foot { flex-direction: row; flex-wrap: wrap; justify-content: center; align-items: center; gap: 0.4rem 1rem; padding: 0.5rem 1rem; }
  #info-start { min-height: 44px; padding: 0.6rem 2rem; }
}

/* Touch pad: placed by main.js (touch-hit.js layoutPad), sized in millimetres. */
#touch { display: none; }
body.touch #touch { display: block; position: fixed; inset: 0; z-index: 4; pointer-events: none; }
body.touch.pad-hidden #touch { display: none; }
#touch > * {
  position: absolute; display: grid; place-items: center; box-sizing: border-box;
  font-weight: 600; color: rgba(255,255,255,0.85); line-height: 1;
  background: rgba(255,255,255,0.10); border: 1.5px solid rgba(255,255,255,0.45);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
#touch .btn { border-radius: 50%; }
#touch .pill { border-radius: 999px; font-weight: 500; letter-spacing: 0.02em; }
#touch .on { background: rgba(255,255,255,0.45); }
#touch .dpad { border-radius: 50%; }
#touch .dpad i { position: absolute; background: rgba(255,255,255,0.10); border: 1px solid rgba(255,255,255,0.45); border-radius: 4px; }
#touch .dpad i.on { background: rgba(255,255,255,0.45); }
#safe-probe {
  position: fixed; visibility: hidden; pointer-events: none; inset: 0 auto auto 0; width: 0; height: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
