:root {
  color-scheme: light;
  --ink: #143431;
  --teal: #1f7c76;
  --cream: #f7f3ea;
  --line: #1c3f3b;
  --pad: rgba(247, 243, 234, 0.94);
  --down: #d7f3ef;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: "Avenir Next", "Segoe UI", "Trebuchet MS", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  position: fixed;
  inset: 0;
  width: 100%;
  background: #c5dbe3;
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#app {
  position: fixed;
  inset: 0;
  touch-action: none;
}

#view {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#hud {
  position: absolute;
  top: calc(8px + var(--safe-t));
  left: calc(10px + var(--safe-l));
  right: calc(10px + var(--safe-r));
  display: none;
  align-items: center;
  gap: 8px;
  z-index: 4;
  pointer-events: none;
}

body[data-mode="playing"] #hud,
body[data-mode="paused"] #hud,
body[data-mode="won"] #hud,
body[data-mode="failed"] #hud { display: flex; }

#hud button { pointer-events: auto; }

.hud-stat {
  background: var(--pad);
  color: var(--ink);
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 700;
  font-size: 15px;
}

#life-pips { display: inline-flex; gap: 4px; margin-left: 6px; vertical-align: middle; }
#life-pips i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #c9d4d2;
  display: block;
}
#life-pips i.on { background: #1f9a90; }

#btn-lang-hud { margin-left: auto; }

#level-title {
  position: absolute;
  top: calc(56px + var(--safe-t));
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  display: none;
  margin: 0;
  max-width: calc(100% - 24px - var(--safe-l) - var(--safe-r));
  padding: 8px 16px;
  pointer-events: none;
  color: var(--ink);
  background: var(--pad);
  border: 2px solid var(--line);
  border-radius: 999px;
  font-weight: 800;
  font-size: clamp(20px, 5.5vh, 28px);
  line-height: 1.2;
  letter-spacing: -0.02em;
  text-align: center;
  white-space: nowrap;
}

body[data-mode="playing"] #level-title.is-visible {
  display: block;
}

#pads {
  display: none;
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

body[data-mode="playing"] #pads { display: block; }
body[data-portrait="1"] #pads { display: none; }

#rotate-gate {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(20, 40, 44, 0.78);
  pointer-events: auto;
}
#rotate-gate[hidden] { display: none; }
#rotate-gate .card { text-align: center; }
#rotate-gate p { margin: 0 0 8px; font-size: 22px; font-weight: 800; }

.pad {
  position: absolute;
  bottom: calc(10px + var(--safe-b));
  display: flex;
  gap: 10px;
  pointer-events: auto;
}

.pad-left { left: calc(12px + var(--safe-l)); }
.pad-right { right: calc(12px + var(--safe-r)); }

button {
  font: inherit;
  color: var(--ink);
  background: var(--pad);
  border: 3px solid var(--line);
  border-radius: 16px;
  font-weight: 800;
}

button.act {
  min-width: 88px;
  min-height: 72px;
  width: clamp(88px, 12vw, 124px);
  height: clamp(72px, 18vh, 100px);
  font-size: clamp(16px, 2.4vh, 22px);
  letter-spacing: 0.01em;
  touch-action: none;
}

button.act.is-down,
button.act:active {
  background: var(--down);
  transform: translateY(2px);
}

button.tool {
  min-height: 40px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--pad);
  pointer-events: auto;
}

#overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 12px;
  z-index: 6;
  background: rgba(20, 40, 44, 0.28);
}

body[data-mode="playing"] #overlay { display: none; }

.card {
  width: min(760px, 100%);
  max-height: calc(100% - 8px);
  overflow: auto;
  background: var(--cream);
  color: var(--ink);
  border: 3px solid var(--line);
  border-radius: 22px;
  padding: 16px 18px 14px;
  box-shadow: 0 16px 40px rgba(20, 40, 40, 0.18);
}

h1 {
  font-size: clamp(32px, 6vh, 52px);
  line-height: 0.95;
  margin: 0 0 6px;
  letter-spacing: -0.03em;
}

.blurb { margin: 0 0 10px; font-size: 16px; }

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.pick, .primary, .ghost {
  min-height: 46px;
  padding: 8px 14px;
  font-size: 17px;
}

.pick[aria-pressed="true"] { background: var(--down); }

.primary { background: #1f8f86; color: white; border-color: #145e58; }

.help { margin: 10px 0 0; font-size: 13px; line-height: 1.35; }

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

button:focus-visible {
  outline: 3px solid #e0a122;
  outline-offset: 2px;
}

@media (max-width: 900px) and (max-height: 430px) {
  .card { padding: 10px 12px; }
  h1 { font-size: 30px; }
  .blurb, .help { font-size: 13px; }
  .pick, .primary, .ghost { min-height: 40px; }
  button.act { min-width: 80px; min-height: 64px; height: 66px; }
  #level-title { font-size: 20px; padding: 6px 14px; }
}

@media (prefers-reduced-motion: reduce) {
  button.act.is-down, button.act:active { transform: none; }
}
