#ecf-game-wrapper,
#ecf-game-wrapper * {
  box-sizing: border-box;
}

#ecf-game-wrapper {
  --ecf-navy: #071326;
  --ecf-night: #0b1b3f;
  --ecf-blue: #2563eb;
  --ecf-cyan: #7dd3fc;
  --ecf-star: #f8fafc;
  --ecf-violet: #8b5cf6;
  --ecf-deep-violet: #312e81;
  --ecf-pink: #f0abfc;
  --ecf-forest: #14532d;
  --ecf-leaf: #4ade80;
  --ecf-gold: #facc15;
  --ecf-black: #020617;
  width: min(100%, 980px);
  margin: 24px auto;
  padding: clamp(10px, 2.4vw, 18px);
  color: var(--ecf-star);
  font-family: "Trebuchet MS", "Courier New", monospace;
  image-rendering: pixelated;
  background:
    radial-gradient(circle at 50% 22%, rgba(125, 211, 252, .18), transparent 24%),
    radial-gradient(circle at 18% 14%, rgba(37, 99, 235, .28), transparent 28%),
    radial-gradient(circle at 86% 22%, rgba(240, 171, 252, .18), transparent 26%),
    linear-gradient(160deg, #020617 0%, #071326 48%, #0b1b3f 100%);
  border: 3px solid rgba(247, 251, 255, .26);
  border-radius: 8px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, .34), inset 0 0 0 2px rgba(45, 135, 255, .2);
  position: relative;
  overflow: hidden;
}

#ecf-game-wrapper [hidden] {
  display: none !important;
}

#ecf-game-wrapper::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(255,255,255,.035) 50%, rgba(0,0,0,.035) 50%),
    radial-gradient(circle at 50% 18%, rgba(255,255,255,.08), transparent 34%);
  background-size: 100% 4px, 100% 100%;
  mix-blend-mode: screen;
  opacity: .55;
}

#ecf-game-wrapper button {
  font: inherit;
}

.ecf-screen {
  display: none !important;
  min-height: 0;
  position: relative;
  z-index: 1;
}

.ecf-game-wrapper.ecf-is-start .ecf-start-screen,
.ecf-game-wrapper.ecf-is-final .ecf-final-screen {
  display: grid !important;
}

.ecf-game-wrapper.ecf-is-game .ecf-game-screen {
  display: grid !important;
}

.ecf-start-screen,
.ecf-final-screen {
  display: grid;
  place-items: center;
  text-align: center;
  position: relative;
  min-height: min(72vh, 620px);
  padding: clamp(22px, 5vw, 56px) 16px;
}

.ecf-start-screen::before {
  content: "";
  width: clamp(92px, 18vw, 164px);
  aspect-ratio: 1.28;
  margin-bottom: 18px;
  display: block;
  border: 4px solid var(--ecf-gold);
  border-radius: 8px 8px 4px 4px;
  background:
    linear-gradient(90deg, transparent 45%, rgba(250, 204, 21, .95) 45% 55%, transparent 55%),
    linear-gradient(180deg, #1e3a8a 0 45%, #0b1b3f 45% 100%);
  box-shadow: 0 0 34px rgba(125, 211, 252, .44), inset 0 -12px 0 rgba(2, 6, 23, .38);
  animation: ecfFloat 3.6s ease-in-out infinite;
}

.ecf-start-screen::after {
  content: "✦";
  position: absolute;
  right: 12%;
  bottom: 14%;
  color: var(--ecf-gold);
  font-size: clamp(2rem, 8vw, 4rem);
  text-shadow: 0 0 24px rgba(250, 204, 21, .72);
  animation: ecfPulse 2s ease-in-out infinite;
}

.ecf-start-screen h1,
.ecf-final-screen h2 {
  max-width: 820px;
  margin: 0 0 14px;
  font-size: clamp(2rem, 5.3vw, 4.2rem);
  line-height: 1;
  letter-spacing: 0;
  color: #ffffff;
  text-shadow: 0 4px 0 #14255d, 0 0 24px rgba(125, 211, 252, .76);
  animation: ecfTitleIn .8s ease both;
}

.ecf-final-screen h2 {
  max-width: min(100%, 680px);
  font-size: clamp(1.85rem, 5vw, 3.25rem);
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.ecf-start-screen p,
.ecf-final-screen p {
  max-width: 680px;
  margin: 0 0 20px;
  font-size: clamp(1rem, 2.8vw, 1.3rem);
  color: #dbe8ff;
}

.ecf-start-stars {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle, rgba(255,255,255,.9) 0 1px, transparent 2px),
    radial-gradient(circle, rgba(241,199,91,.9) 0 1px, transparent 2px);
  background-position: 16px 22px, 70px 82px;
  background-size: 92px 92px, 138px 138px;
  opacity: .55;
  animation: ecfStars 8s linear infinite;
}

.ecf-start-stars::before,
.ecf-start-stars::after {
  content: "";
  position: absolute;
  bottom: clamp(18px, 5vw, 42px);
  width: 42px;
  height: 28px;
  background: #020617;
  border-radius: 18px 18px 10px 10px;
  box-shadow: 0 0 18px rgba(125, 211, 252, .28);
}

.ecf-start-stars::before {
  left: clamp(18px, 8vw, 72px);
}

.ecf-start-stars::after {
  right: clamp(18px, 8vw, 72px);
}

@keyframes ecfStars {
  from { transform: translateY(0); }
  to { transform: translateY(18px); }
}

@keyframes ecfFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes ecfPulse {
  0%, 100% { opacity: .55; transform: scale(.96); }
  50% { opacity: 1; transform: scale(1.06); }
}

@keyframes ecfTitleIn {
  from { opacity: 0; transform: translateY(12px); filter: blur(4px); }
  to { opacity: 1; transform: translateY(0); filter: blur(0); }
}

.ecf-game-screen {
  position: relative;
  gap: 10px;
  grid-template-rows: auto auto auto auto;
}

.ecf-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.ecf-scene-name {
  min-height: 36px;
  display: flex;
  align-items: center;
  padding: 8px 12px;
  color: #ffffff;
  background: rgba(4, 16, 39, .72);
  border: 2px solid rgba(247, 251, 255, .2);
  border-radius: 6px;
  font-weight: 800;
  text-shadow: 0 2px 0 #07142e;
}

.ecf-actions {
  display: flex;
  gap: 8px;
}

#ecf-game-canvas {
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: min(62vh, 620px);
  display: block;
  border: 3px solid rgba(247, 251, 255, .9);
  border-radius: 8px;
  background: #07142e;
  box-shadow:
    inset 0 0 0 4px #14255d,
    inset 0 0 46px rgba(45, 135, 255, .16),
    0 16px 28px rgba(0, 0, 0, .3);
  touch-action: none;
}

.ecf-hud {
  position: absolute;
  top: 62px;
  right: 16px;
  z-index: 3;
  display: flex;
  gap: 8px;
  pointer-events: none;
}

.ecf-hud-item {
  width: 34px;
  height: 28px;
  min-height: 0;
  display: block;
  padding: 0;
  color: transparent;
  font-size: 0;
  background:
    linear-gradient(90deg, transparent 42%, #facc15 42% 58%, transparent 58%),
    linear-gradient(180deg, #1e3a8a 0 43%, #071326 43% 100%);
  border: 2px solid rgba(250, 204, 21, .52);
  border-radius: 4px;
  box-shadow: inset 0 -5px 0 rgba(2, 6, 23, .5), 0 0 0 2px rgba(2,6,23,.5);
  opacity: .42;
  filter: saturate(.7);
}

.ecf-hud-item.ecf-found {
  opacity: 1;
  filter: saturate(1.2);
  border-color: #fff7c8;
  box-shadow: inset 0 -5px 0 rgba(2, 6, 23, .35), 0 0 14px rgba(250,204,21,.86), 0 0 26px rgba(125,211,252,.3);
}

.ecf-dialog-box {
  min-height: 132px;
  padding: 14px;
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  background:
    linear-gradient(180deg, rgba(7, 19, 38, .98), rgba(2, 6, 23, .96)),
    radial-gradient(circle at 20% 0, rgba(125, 211, 252, .18), transparent 42%);
  border: 4px solid rgba(248, 250, 252, .92);
  border-radius: 8px;
  box-shadow: inset 0 0 0 4px #19337a, 0 -8px 24px rgba(37, 99, 235, .22), 0 0 32px rgba(125, 211, 252, .1);
  animation: ecfDialogIn .18s ease both;
}

.ecf-dialog-portrait {
  width: 76px;
  height: 76px;
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: linear-gradient(180deg, #14255d, #07142e);
  border: 3px solid rgba(247, 251, 255, .9);
  border-radius: 8px;
  box-shadow: inset 0 -8px 0 rgba(0,0,0,.22), 0 8px 18px rgba(0,0,0,.22);
}

.ecf-dialog-portrait span {
  width: 52px;
  height: 52px;
  position: relative;
  display: block;
  background-repeat: no-repeat;
}

.ecf-dialog-portrait span::before,
.ecf-dialog-portrait span::after {
  content: "";
  position: absolute;
  display: block;
}

.ecf-dialog-portrait.ecf-portrait-asset span {
  width: 64px;
  height: 64px;
  image-rendering: pixelated;
  background-color: transparent !important;
}

.ecf-dialog-portrait.ecf-portrait-asset span::before,
.ecf-dialog-portrait.ecf-portrait-asset span::after {
  display: none;
}

.ecf-dialog-portrait.ecf-portrait-marina span {
  background:
    linear-gradient(#111326 0 16px, transparent 16px),
    linear-gradient(90deg, #111326 0 10px, #f4c7b7 10px 42px, #111326 42px 52px);
  box-shadow: inset 15px 25px 0 #8fd3ff, inset -15px 25px 0 #8fd3ff, inset 0 36px 0 #2d87ff;
}

.ecf-dialog-portrait.ecf-portrait-marina span::before {
  left: 16px;
  top: 24px;
  width: 5px;
  height: 5px;
  background: #7dd3fc;
  box-shadow: 16px 0 0 #7dd3fc, -6px 10px 0 #f2a8d3, 22px 10px 0 #f2a8d3;
}

.ecf-dialog-portrait.ecf-portrait-marina span::after {
  right: -4px;
  top: 2px;
  width: 15px;
  height: 15px;
  background: #facc15;
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 56%, 79% 91%, 50% 70%, 21% 91%, 32% 56%, 2% 35%, 39% 35%);
}

.ecf-dialog-portrait.ecf-portrait-guide span,
.ecf-dialog-portrait.ecf-portrait-star span {
  width: 46px;
  height: 46px;
  background: #9fd0ff;
  clip-path: polygon(50% 0, 61% 33%, 96% 35%, 68% 56%, 78% 92%, 50% 72%, 22% 92%, 32% 56%, 4% 35%, 39% 33%);
  filter: drop-shadow(0 0 12px rgba(125,211,252,.9));
}

.ecf-dialog-portrait.ecf-portrait-pinky span {
  width: 54px;
  height: 36px;
  margin-top: 14px;
  background: #8a5a35;
  border-radius: 18px 18px 12px 12px;
  box-shadow: inset 14px 18px 0 #f0abfc;
}

.ecf-dialog-portrait.ecf-portrait-pinky span::before {
  left: 30px;
  top: -13px;
  width: 22px;
  height: 22px;
  background: #a66b3d;
  border-radius: 12px;
  box-shadow: -28px 6px 0 -5px #5d3825, 13px 6px 0 -5px #5d3825;
}

.ecf-dialog-portrait.ecf-portrait-pinky span::after {
  left: 38px;
  top: -5px;
  width: 4px;
  height: 4px;
  background: #07142e;
  box-shadow: 8px 0 0 #07142e, 4px 8px 0 #f2a8d3;
}

.ecf-dialog-portrait.ecf-portrait-narrator span {
  width: 44px;
  height: 50px;
  background:
    linear-gradient(90deg, transparent 0 8px, #facc15 8px 14px, transparent 14px 30px, #7dd3fc 30px 36px, transparent 36px),
    linear-gradient(180deg, #f8fafc 0 8px, #102a67 8px 100%);
  border: 2px solid #dbe8ff;
  border-radius: 4px;
}

.ecf-dialog-content {
  min-width: 0;
}

@keyframes ecfDialogIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.ecf-speaker {
  min-height: 24px;
  margin-bottom: 8px;
  color: var(--ecf-gold);
  font-weight: 900;
}

.ecf-dialog-text {
  min-height: 54px;
  color: #f7fbff;
  font-size: clamp(.96rem, 2.4vw, 1.1rem);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.ecf-pixel-button,
.ecf-icon-button,
.ecf-control-btn {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  color: #07142e;
  background: linear-gradient(180deg, #ffffff 0%, #9fd0ff 52%, #2d87ff 100%);
  box-shadow: inset 0 -4px 0 rgba(7, 20, 46, .28), 0 4px 0 #07142e;
  cursor: pointer;
  font-weight: 900;
  transition: transform .12s ease, filter .12s ease;
}

.ecf-pixel-button {
  padding: 12px 18px;
}

.ecf-small-button {
  margin-top: 12px;
  min-height: 36px;
  padding: 8px 14px;
}

.ecf-icon-button {
  width: 44px;
  height: 42px;
  font-size: 1.2rem;
}

.ecf-pixel-button:hover,
.ecf-icon-button:hover,
.ecf-control-btn:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.ecf-pixel-button:active,
.ecf-icon-button:active,
.ecf-control-btn:active {
  transform: translateY(3px);
  box-shadow: inset 0 -2px 0 rgba(7, 20, 46, .28), 0 1px 0 #07142e;
}

.ecf-mobile-controls {
  display: grid;
  grid-template-columns: 58px 58px 58px 18px 78px;
  grid-template-areas:
    ". up . . act"
    "left down right . act";
  gap: 10px;
  align-items: center;
  justify-content: center;
  width: 288px;
  max-width: 100%;
  margin: 4px auto 0;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

.ecf-control-btn {
  width: 58px !important;
  min-width: 0 !important;
  max-width: 58px !important;
  height: 50px !important;
  min-height: 0 !important;
  padding: 0 !important;
  display: grid !important;
  place-items: center;
  line-height: 1 !important;
  appearance: none;
  -webkit-appearance: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  color: #ffffff;
  font-size: 1.05rem;
  background: linear-gradient(180deg, #1f4da7, #102a67);
  border: 2px solid rgba(247, 251, 255, .35);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .24), 0 4px 0 #041027;
}

.ecf-control-btn[data-dir="up"] { grid-area: up; }
.ecf-control-btn[data-dir="left"] { grid-area: left; }
.ecf-control-btn[data-dir="down"] { grid-area: down; }
.ecf-control-btn[data-dir="right"] { grid-area: right; }
.ecf-action-btn {
  grid-area: act;
  width: 78px !important;
  max-width: 78px !important;
  height: 110px !important;
  color: #07142e;
  font-size: 1.15rem;
  background: linear-gradient(180deg, #fff4ba, #f1c75b);
}

.ecf-final-card {
  width: min(100%, 720px);
  padding: clamp(18px, 5vw, 34px);
  background: rgba(4, 16, 39, .72);
  border: 3px solid rgba(247, 251, 255, .28);
  border-radius: 8px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .35);
  overflow: hidden;
}

#ecf-final-photo {
  display: block;
  width: auto;
  max-width: min(100%, 540px);
  max-height: min(46vh, 420px);
  height: auto;
  margin: 0 auto 22px;
  border: 4px solid #f7fbff;
  border-radius: 8px;
  object-fit: contain;
  background: #07142e;
  box-shadow: 0 16px 34px rgba(0, 0, 0, .28);
}

.ecf-final-photo-placeholder {
  width: min(100%, 380px);
  aspect-ratio: 4 / 3;
  margin: 0 auto 20px;
  border: 4px solid #f7fbff;
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 34%, rgba(247,251,255,.28), transparent 18%),
    linear-gradient(135deg, #102a67, #07142e 55%, #221a53);
}

.ecf-final-photo-placeholder {
  display: grid;
  place-items: center;
  color: #dbe8ff;
  font-weight: 900;
}

.ecf-final-note {
  position: absolute;
  inset: clamp(10px, 4vw, 24px);
  z-index: 5;
  overflow: auto;
  padding: clamp(24px, 5vw, 46px);
  color: #34233a;
  background:
    radial-gradient(circle at 18% 12%, rgba(240,171,252,.22), transparent 28%),
    radial-gradient(circle at 86% 18%, rgba(250,204,21,.24), transparent 24%),
    linear-gradient(180deg, rgba(255,250,252,.98), rgba(255,239,224,.98)),
    repeating-linear-gradient(0deg, rgba(255,255,255,0) 0 27px, rgba(190,91,132,.06) 28px);
  border: 5px solid #fff6d7;
  border-radius: 14px;
  box-shadow:
    0 24px 70px rgba(0, 0, 0, .5),
    inset 0 0 0 3px rgba(255, 196, 224, .6),
    inset 0 0 42px rgba(250, 204, 21, .16);
  line-height: 1.72;
  white-space: pre-line;
  font-family: Georgia, "Times New Roman", serif;
}

.ecf-final-note::before {
  content: "♥";
  position: sticky;
  top: 0;
  float: right;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  margin: -8px -8px 10px 16px;
  color: #fff7c8;
  font-size: 1.25rem;
  background: radial-gradient(circle at 35% 28%, #f0abfc, #be5b84 72%);
  border: 3px solid #fff6d7;
  border-radius: 50%;
  box-shadow: 0 8px 22px rgba(190,91,132,.35), inset 0 -5px 0 rgba(80,20,40,.22);
}

.ecf-final-note h3 {
  margin: 0 0 18px;
  color: #7c2d52;
  font-family: "Trebuchet MS", Georgia, serif;
  font-size: clamp(1.75rem, 5vw, 2.7rem);
  line-height: 1;
  text-align: center;
  text-shadow: 0 2px 0 rgba(255,255,255,.75);
}

.ecf-final-note h3::after {
  content: "";
  display: block;
  width: min(220px, 70%);
  height: 3px;
  margin: 14px auto 0;
  background: linear-gradient(90deg, transparent, #be5b84, #facc15, #be5b84, transparent);
  border-radius: 999px;
}

.ecf-final-note div {
  max-width: 760px;
  margin: 0 auto;
  font-size: clamp(1rem, 2.4vw, 1.16rem);
}

.ecf-final-note .ecf-note-close {
  position: sticky;
  bottom: 0;
  display: block;
  margin: 24px auto 0;
  background: linear-gradient(180deg, #fff7c8, #f0abfc 48%, #be5b84);
  color: #2b1830;
}

@media (min-width: 850px) {
  .ecf-mobile-controls {
    display: none;
  }
}

@media (max-width: 640px) {
  #ecf-game-wrapper {
    margin: 8px auto;
    border-radius: 0;
  }

  .ecf-screen {
    min-height: 0;
  }

  .ecf-start-screen,
  .ecf-final-screen {
    min-height: 76vh;
  }

  .ecf-topbar {
    align-items: stretch;
  }

  .ecf-scene-name {
    font-size: .86rem;
  }

  #ecf-game-canvas {
    aspect-ratio: 4 / 3;
    max-height: 50vh;
  }

  .ecf-hud {
    grid-template-columns: 1fr;
  }

  .ecf-dialog-box {
    min-height: 148px;
    grid-template-columns: 62px minmax(0, 1fr);
    gap: 10px;
    padding: 10px;
  }

  .ecf-dialog-portrait {
    width: 60px;
    height: 60px;
  }

  .ecf-dialog-portrait span {
    transform: scale(.78);
  }

  .ecf-small-button {
    min-height: 34px;
    padding: 7px 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ecf-start-screen::before,
  .ecf-start-screen::after,
  .ecf-start-stars,
  .ecf-start-screen h1,
  .ecf-dialog-box {
    animation: none;
  }
}

@media (max-width: 430px) {
  .ecf-mobile-controls {
    grid-template-columns: 50px 50px 50px 10px 66px;
    gap: 6px;
    width: 244px;
  }

  .ecf-control-btn {
    width: 50px !important;
    max-width: 50px !important;
    height: 44px !important;
    font-size: .95rem;
  }

  .ecf-action-btn {
    width: 66px !important;
    max-width: 66px !important;
    height: 94px !important;
  }
}
