:root {
  --ef-green: #39ff6a;
  --ef-green-dim: #168c38;
  --ef-bg: #050505;
  --ef-panel: #101010;
  --ef-line: #263a2a;
  --ef-text: #e8ffe8;
  --ef-muted: #9bb79b;
  --ef-header-h: clamp(76px, 22.9vw, 100px);
  --ef-character-h: clamp(196px, 59.7vw, 278px);
  --ef-inventory-bottom: clamp(54px, 16vw, 72px);
  --ef-character-inventory-gap: 30px;
  --ef-ad-h: clamp(50px, 13.3vw, 64px);
  --ef-game-bottom: calc(var(--ef-character-h) + var(--ef-inventory-bottom) + var(--ef-ad-h) + var(--ef-character-inventory-gap));
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  overflow-x: hidden;
  overflow-y: auto;
  padding-top: 0;
  background: #000;
  color: var(--ef-text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  touch-action: manipulation;
}

.ef-page {
  width: 100%;
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  align-items: start;
  justify-items: center;
  overflow: visible;
  background: #111;
}

.ef-shell {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  min-height: max(100svh, 812px);
  height: auto;
  overflow: visible;
  padding-top: 0;
  background: var(--ef-bg);
  border: 1px solid #1d3e25;
  box-shadow: 0 0 28px rgba(57, 255, 106, 0.12);
}

.ef-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--ef-header-h);
  min-height: var(--ef-header-h);
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: clamp(8px, 2.7vw, 12px);
  padding: clamp(8px, 2.7vw, 12px) clamp(10px, 3vw, 14px);
  background: #1a1a1a;
  border-bottom: 1px solid #16351b;
}

.ef-header-heading {
  min-width: 0;
  display: grid;
  align-content: center;
  gap: clamp(5px, 1.9vw, 8px);
  overflow: hidden;
}

.ef-brand,
.ef-header-stage {
  min-width: 0;
  overflow: hidden;
  color: var(--ef-green);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  line-height: 1.25;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-shadow: 0 0 8px rgba(57, 255, 106, 0.5);
}

.ef-brand {
  font-size: clamp(17px, 5.1vw, 22px);
}

.ef-header-stage {
  font-size: clamp(12px, 3.7vw, 16px);
}

.ef-header-controls {
  width: clamp(74px, 20.8vw, 94px);
  flex: 0 0 clamp(74px, 20.8vw, 94px);
  display: grid;
  align-content: center;
  justify-items: end;
  gap: clamp(5px, 1.6vw, 8px);
}

.ef-header-actions {
  display: flex;
  gap: clamp(7px, 2.1vw, 10px);
  flex: 0 0 auto;
}

.ef-icon-button,
.ef-stage-select {
  height: clamp(27px, 7.2vw, 34px);
  border: 1px solid #24502c;
  border-radius: 8px;
  background: #091109;
  color: var(--ef-text);
  font: clamp(12px, 3.2vw, 14px)/1 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

.ef-icon-button {
  width: clamp(31px, 9.1vw, 40px);
  display: inline-grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
}

.ef-stage-select {
  width: clamp(56px, 15.5vw, 70px);
  padding: 0 clamp(5px, 1.6vw, 8px);
  cursor: pointer;
}

.ef-icon-button:hover,
.ef-stage-select:hover,
.ef-icon-button:focus-visible,
.ef-stage-select:focus-visible {
  outline: none;
  border-color: var(--ef-green);
  box-shadow: 0 0 0 2px rgba(57, 255, 106, 0.18);
}

.ef-game-area {
  position: absolute;
  inset: var(--ef-header-h) 0 var(--ef-game-bottom);
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #000;
  color: var(--ef-green);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

.ef-stage-title {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: clamp(18px, 6.4vw, 30px);
  color: #d8ffe0;
  background: rgba(0, 0, 0, 0.82);
  font-size: clamp(18px, 5.9vw, 26px);
  text-align: center;
  text-shadow: 0 0 12px rgba(57, 255, 106, 0.75);
  opacity: 1;
  transition: opacity 700ms ease;
  pointer-events: none;
}

.ef-stage-title.is-fading {
  opacity: 0;
}

.ef-log {
  width: calc(100% - clamp(24px, 8.5vw, 40px));
  height: 100%;
  max-height: 100%;
  overflow: hidden;
  align-self: start;
  justify-self: start;
  margin: 0 clamp(12px, 4.3vw, 20px);
  padding: clamp(8px, 2.7vw, 12px) 0 clamp(12px, 4.3vw, 18px);
  color: var(--ef-green);
  font-size: clamp(12px, 3.5vw, 16px);
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ef-log-line {
  margin: 0 0 4px;
}

.ef-clear-screen {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: clamp(20px, 7.5vw, 34px);
  background: rgba(0, 0, 0, 0.88);
  text-align: center;
}

.ef-clear-inner {
  display: grid;
  gap: clamp(14px, 4.8vw, 22px);
  justify-items: center;
}

.ef-clear-title {
  color: #fff;
  font-size: clamp(40px, 14.4vw, 64px);
  font-weight: 800;
  letter-spacing: 0;
  text-shadow: 0 0 16px rgba(57, 255, 106, 0.9);
}

.ef-next-link {
  color: var(--ef-green);
  font: clamp(15px, 4.8vw, 20px)/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  text-decoration: none;
  border-bottom: 1px solid currentColor;
}

.ef-inventory {
  position: absolute;
  left: 50%;
  bottom: var(--ef-inventory-bottom);
  width: min(69.3%, calc(100% - clamp(48px, 17.1vw, 78px)));
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(6px, 2.1vw, 10px);
  padding: 0;
  background: #171717;
  border: 0;
}

.ef-inventory-slot {
  aspect-ratio: 1;
  min-width: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid #555;
  border-radius: 8px;
  background: #2d2d2d;
  color: #ddd;
  font-size: clamp(11px, 3.2vw, 14px);
  text-align: center;
}

.ef-character-area,
.ef-chars {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--ef-inventory-bottom) + var(--ef-ad-h));
  height: var(--ef-character-h);
  min-height: var(--ef-character-h);
  margin-bottom: var(--ef-character-inventory-gap);
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: clamp(5px, 1.6vw, 8px);
  padding: clamp(28px, 18.7vw, 28px) clamp(10px, 3.2vw, 16px) var(--ef-character-inventory-gap);
  overflow: visible;
  background: #2a2a2a;
  border-top: 1px solid #444;
  border-bottom: 1px solid #444;
  pointer-events: none;
}

.ef-actor {
  position: relative;
  width: 45.3%;
  height: 75%;
  min-width: 0;
  display: flex;
  align-items: end;
  gap: clamp(6px, 2.1vw, 10px);
}

.ef-actor-ai {
  flex-direction: row-reverse;
}

.ef-sprite-wrap {
  width: min(70.6%, 120px);
  height: min(71.4%, 120px);
  flex: 0 0 min(70.6%, 120px);
  position: relative;
  overflow: visible;
  image-rendering: pixelated;
  -webkit-image-rendering: crisp-edges;
}

.ef-sprite {
  position: absolute;
  left: 0;
  top: 0;
  zoom: 2;
  image-rendering: pixelated;
  -webkit-image-rendering: crisp-edges;
}

.ef-help-character-sprite {
  image-rendering: pixelated;
  -webkit-image-rendering: crisp-edges;
}

.ef-help-character-sprite .ef-sprite {
  zoom: 2;
}

.ef-speech,
.ef-bubble {
  position: absolute;
  top: clamp(-50px, -6.7vw, -18px);
  bottom: auto;
  left: 0;
  min-width: min(96px, 56%);
  max-width: 100%;
  min-height: clamp(40px, 11.7vw, 54px);
  display: flex;
  align-items: center;
  padding: clamp(7px, 2.1vw, 10px) clamp(8px, 2.7vw, 12px);
  border-radius: 8px;
  background: #f3f3f3;
  color: #111;
  font-size: clamp(12px, 3.7vw, 16px);
  line-height: 1.25;
  overflow-wrap: anywhere;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.24);
}

.ef-speech::after,
.ef-bubble::after {
  content: "";
  position: absolute;
  left: clamp(22px, 7.5vw, 32px);
  bottom: -8px;
  width: 0;
  height: 0;
  border: 10px solid transparent;
  border-top-color: #f3f3f3;
  border-bottom: 0;
}

.ef-actor-ai .ef-speech,
.ef-actor-ai .ef-bubble {
  right: 0;
  left: auto;
  margin-top: 28px;
}

.ef-ad {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: min(85.3%, 380px);
  min-height: var(--ef-ad-h);
  padding-bottom: max(env(safe-area-inset-bottom, 20px), 20px);
  transform: translateX(-50%);
  display: grid;
  place-items: center;
  background: #707070;
  color: #d8d8d8;
  font: 700 clamp(12px, 3.5vw, 15px)/1 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  letter-spacing: 0;
}

.ef-modal-backdrop {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: none;
  place-items: center;
  padding: clamp(14px, 4.8vw, 22px);
  background: rgba(0, 0, 0, 0.68);
}

.ef-modal-backdrop.is-open {
  display: grid;
}

.ef-modal {
  width: 100%;
  max-width: min(88%, 380px);
  max-height: calc(100svh - clamp(28px, 9.6vw, 44px));
  overflow: auto;
  padding: clamp(14px, 4.8vw, 22px);
  border: 1px solid #315f39;
  border-radius: 8px;
  background: #101410;
  color: var(--ef-text);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.48);
}

.ef-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: clamp(10px, 3.2vw, 14px);
  margin-bottom: clamp(10px, 3.2vw, 14px);
}

.ef-modal-title {
  margin: 0;
  color: var(--ef-green);
  font-size: clamp(16px, 4.8vw, 20px);
}

.ef-modal-close {
  width: clamp(30px, 8.5vw, 38px);
  height: clamp(30px, 8.5vw, 38px);
  border: 1px solid #315f39;
  border-radius: 8px;
  background: #050805;
  color: var(--ef-text);
  cursor: pointer;
}

.ef-help-section {
  margin: clamp(12px, 3.7vw, 16px) 0;
}

.ef-help-section h3 {
  margin: 0 0 clamp(7px, 2.1vw, 10px);
  color: #d8ffe0;
  font-size: clamp(13px, 3.7vw, 16px);
}

.ef-help-section p,
.ef-help-section li {
  color: #d7e6d7;
  font-size: clamp(12px, 3.5vw, 15px);
  line-height: 1.55;
}

.ef-help-section ul {
  margin: 0;
  padding-left: clamp(16px, 4.8vw, 22px);
}

.ef-link-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(7px, 2.1vw, 10px);
}

.ef-help-link,
.ef-tip-link {
  min-height: clamp(34px, 9.6vw, 42px);
  display: grid;
  place-items: center;
  padding: clamp(7px, 2.1vw, 10px) clamp(8px, 2.7vw, 12px);
  border: 1px solid #315f39;
  border-radius: 8px;
  color: var(--ef-green);
  background: #071007;
  font-size: clamp(12px, 3.5vw, 15px);
  text-align: center;
  text-decoration: none;
}

.ef-tip-link {
  margin-top: 10px;
  border-color: #6d5e2a;
  color: #ffe28a;
  background: #171407;
}

@media (max-width: 360px) {
  .ef-brand {
    font-size: 17px;
  }

  .ef-header-stage {
    font-size: 12px;
    padding-top: 4px;
  }

  .ef-header-controls {
    width: 76px;
    flex-basis: 76px;
  }

  .ef-stage-select {
    width: 56px;
    font-size: 12px;
  }

  .ef-icon-button {
    width: 30px;
  }
}

@media (max-width: 480px) {
  body,
  .ef-shell {
    padding-top: 0;
  }
}
