:root {
  --ink: #18354d;
  --blue: #71d2eb;
  --blue-dark: #168fb4;
  --panel: rgba(255,255,255,.94);
  --yellow: #ffd84f;
  --green: #40b96d;
  --red: #e74d4d;
  --shadow: 0 14px 35px rgba(24,53,77,.2);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body {
  font-family: Arial, "Noto Sans Hebrew", sans-serif;
  color: var(--ink);
  background: #a8e7f5 url("assets/ui/background.png") center/cover fixed;
}
button { font: inherit; }
button:focus-visible { outline: 4px solid #1c75bc; outline-offset: 3px; }

.app {
  width: 100%;
  height: 100%;
  padding: 18px;
  display: grid;
  place-items: center;
}

.screen {
  position: relative;
  width: min(1180px, 100%);
  height: min(700px, calc(100vh - 36px));
  min-height: 560px;
  background: var(--panel);
  border: 5px solid rgba(255,255,255,.8);
  border-radius: 32px;
  box-shadow: var(--shadow);
  overflow: hidden;
  padding: 82px 38px 26px;
}

.topbar {
  position: absolute;
  inset: 14px 18px auto 18px;
  display: grid;
  grid-template-columns: 230px minmax(180px, 1fr) 230px;
  align-items: center;
  gap: 16px;
  z-index: 10;
  direction: ltr;
}

.topbar__controls {
  display: flex;
  align-items: center;
  gap: 8px;
  direction: ltr;
}
.topbar__spacer {
  width: 100%;
  height: 1px;
  pointer-events: none;
}

.home-button,
.book-button,
.fullscreen-button,
.final-home-button {
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 0;
  display: grid;
  place-items: center;
}

.home-button {
  width: 58px;
  height: 54px;
}
.home-button img,
.final-home-button img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.book-button,
.fullscreen-button {
  width: 48px;
  height: 48px;
  border-radius: 15px;
  background: white;
  box-shadow: 0 5px 14px rgba(24,53,77,.17);
  color: var(--ink);
}
.fullscreen-button { font-size: 28px; }
.book-button svg {
  width: 34px;
  height: 34px;
  overflow: visible;
}
.book-button svg path {
  fill: #58c1dc;
  stroke: #174b66;
  stroke-width: 2.6;
  stroke-linejoin: round;
}
.book-button svg .book-line {
  fill: none;
  stroke-width: 2.2;
}
.book-button.is-open {
  background: #fff1a8;
  box-shadow: 0 0 0 3px #f0b72e, 0 5px 14px rgba(24,53,77,.17);
}

.progress {
  position: relative;
  height: 15px;
  border-radius: 99px;
  background: #d9edf2;
  overflow: hidden;
  border: 2px solid white;
  box-shadow: 0 4px 12px rgba(24,53,77,.1);
}
.progress--hidden {
  visibility: hidden;
}
.progress__fill {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  height: 100%;
  background: linear-gradient(270deg, #43b8dc, #52d17e);
  transform-origin: right center;
  transition: width .3s ease;
}

.reward-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  direction: ltr;
}
.reward-meter {
  position: relative;
  width: 190px;
  height: 48px;
}
.reward-meter-bg {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
}
.reward-meter-value {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding-left: 34px;
  font-size: 26px;
  line-height: 1;
  font-weight: 950;
  color: #4a2e0e;
  text-shadow: 0 1px 0 rgba(255,255,255,.9);
}

.hero {
  height: 100%;
  display: grid;
  place-items: center;
  text-align: center;
}
.hero-card {
  width: min(760px, 94%);
  max-height: 100%;
  padding: 36px 42px;
  border-radius: 34px;
  background: rgba(255,255,255,.84);
  box-shadow: var(--shadow);
  border: 3px solid #d9f5fb;
}
.hero h1 {
  margin: 0 0 12px;
  font-size: clamp(38px, 5.5vw, 68px);
  color: #177fa3;
}
.hero p {
  margin: 0 0 28px;
  font-size: clamp(20px, 2.2vw, 28px);
  font-weight: 700;
}

.primary,
.secondary {
  border: 0;
  cursor: pointer;
  border-radius: 22px;
  padding: 15px 28px;
  font-weight: 900;
  font-size: clamp(20px, 2vw, 27px);
  box-shadow: 0 7px 0 rgba(0,0,0,.13);
  transition: transform .15s ease, box-shadow .15s ease;
}
.primary { background: var(--yellow); color: #543d00; }
.secondary { background: #dff6fc; color: var(--ink); }
.primary:hover,
.secondary:hover { transform: translateY(-2px); box-shadow: 0 9px 0 rgba(0,0,0,.12); }
.primary:active,
.secondary:active { transform: translateY(3px); box-shadow: 0 3px 0 rgba(0,0,0,.12); }

.stage-title {
  text-align: center;
  margin: 2px 0 18px;
  font-size: clamp(24px, 3vw, 38px);
}
.question-header {
  max-width: 1020px;
  min-height: 94px;
  margin: -2px auto 10px;
  display: grid;
  place-items: center;
  gap: 5px;
}
.question-instruction-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: 100%;
}
.question-instructions {
  white-space: pre-line;
  text-align: center;
  font-size: clamp(22px, 2.25vw, 31px);
  font-weight: 900;
  line-height: 1.35;
}
.question-counter {
  padding: 2px 14px;
  border-radius: 99px;
  background: #e5f7fb;
  border: 2px solid #bce8f2;
  font-size: clamp(16px, 1.45vw, 20px);
  font-weight: 850;
}
.question-wrap {
  max-width: 980px;
  height: calc(100% - 104px);
  margin: 0 auto;
  display: grid;
  grid-template-rows: minmax(110px, .9fr) minmax(115px, 1fr);
  gap: 16px;
}

.speaker-button {
  flex: 0 0 auto;
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 50%;
  padding: 9px;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: #176f9a;
  background: #fff;
  box-shadow: 0 5px 14px rgba(24,53,77,.2), inset 0 0 0 3px #bdebf5;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.speaker-button:hover { transform: scale(1.06); box-shadow: 0 7px 17px rgba(24,53,77,.24), inset 0 0 0 3px #7bd4e8; }
.speaker-button:active { transform: scale(.96); }
.speaker-button.is-playing { background: #fff4b5; animation: speaker-pulse .75s ease-in-out infinite alternate; }
.speaker-button svg { width: 100%; height: 100%; overflow: visible; }
.speaker-shape { fill: currentColor; }
.sound-wave { fill: none; stroke: currentColor; stroke-width: 5; stroke-linecap: round; }
.sound-wave--outer { stroke-width: 4; }
@keyframes speaker-pulse { from { transform: scale(1); } to { transform: scale(1.08); } }
.question-card {
  min-height: 0;
  padding: 14px 22px;
  background: white;
  border-radius: 25px;
  border: 3px solid #bdebf5;
  box-shadow: 0 9px 20px rgba(24,53,77,.1);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.content-image {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.question-card .content-image { width: min(900px, 100%); }
.content-text {
  font-size: clamp(28px, 4vw, 48px);
  font-weight: 800;
  text-align: center;
  line-height: 1.55;
}
.answers {
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
}
.answer-card {
  min-height: 0;
  border: 4px solid transparent;
  border-radius: 24px;
  background: #fff;
  box-shadow: 0 8px 22px rgba(24,53,77,.14);
  padding: 16px;
  cursor: pointer;
  display: grid;
  place-items: center;
  overflow: hidden;
  transition: transform .15s ease, border-color .15s ease;
}
.answer-card:hover { transform: translateY(-4px) scale(1.01); border-color: #75d2e8; }
.answer-card:disabled { cursor: default; opacity: .78; transform: none; }
.answer-card .content-image { width: 100%; max-height: 90px; }
.answer-card .content-text { font-size: clamp(23px, 3vw, 38px); }

.level-choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(190px, 300px));
  justify-content: center;
  gap: 24px;
  margin-top: 22px;
}
.level-card {
  min-height: 120px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 6px;
}
.level-card strong { font-size: 34px; }
.level-card span { font-size: 20px; }

.stage-complete-card { padding-top: 20px; }
.stage-complete-card h1 { font-size: clamp(38px, 5vw, 62px); margin-bottom: 10px; }
.treasure {
  width: min(210px, 34vw);
  max-height: 155px;
  object-fit: contain;
  filter: drop-shadow(0 12px 12px rgba(0,0,0,.2));
}
.stage-rewards {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin: 6px 0 10px;
  direction: ltr;
}
.stage-rewards span {
  min-width: 126px;
  height: 58px;
  border-radius: 18px;
  background: rgba(255, 246, 205, .95);
  box-shadow: inset 0 0 0 3px rgba(82,50,13,.88);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 28px;
  font-weight: 950;
  color: #4a2e0e;
}
.stage-rewards img { width: 44px; height: 44px; object-fit: contain; }
.finish-actions { display: flex; align-items: center; justify-content: center; gap: 22px; margin-top: 20px; }
.final-home-button { width: 76px; height: 72px; }

/* Exact feedback graphics and sounds copied from the reference activity. */
.reference-feedback-overlay,
.hint-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(14, 33, 49, .14);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  isolation: isolate;
  animation: overlay-in .2s ease both;
}
.reference-feedback-overlay.leaving,
.hint-overlay.leaving { animation: overlay-out .25s ease both; }
.reference-feedback-image {
  width: min(720px, 90vw);
  max-height: 76vh;
  object-fit: contain;
  filter: drop-shadow(0 18px 24px rgba(0,0,0,.22));
  animation: feedback-in .42s cubic-bezier(.2,.8,.2,1) both;
}
.reference-feedback-overlay.leaving .reference-feedback-image {
  animation: feedback-out .25s ease both;
}
@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes overlay-out { to { opacity: 0; } }
@keyframes feedback-in { from { transform: translateX(105%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes feedback-out { to { transform: translateX(-105%); opacity: 0; } }

.large-hint-panel {
  position: relative;
  width: min(760px, 78vw);
  height: min(520px, 72vh);
  padding: 18px 20px 12px;
  border-radius: 30px;
  background: rgba(255,255,255,.98);
  box-shadow: 0 20px 60px rgba(0,0,0,.28);
  border: 4px solid #9edfed;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  place-items: center;
  gap: 8px;
}
.hint-media-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  display: grid;
  place-items: center;
}
.large-hint-panel .large-hint-media {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.hint-speaker {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 68px;
  height: 68px;
  z-index: 3;
}
.hint-close-button {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 5;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: #ffffff;
  color: #18354d;
  box-shadow: 0 5px 16px rgba(24,53,77,.24);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 34px;
  font-weight: 900;
  line-height: 1;
}
.hint-close-button:hover { transform: scale(1.06); }
.hint-close-button:active { transform: scale(.96); }
.asset-continue-button {
  width: min(220px, 38vw);
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
}
.asset-continue-button img { width: 100%; display: block; }

.reward-burst {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: reward-float 1.15s ease-out forwards;
}
.reward-burst-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 34px;
  font-weight: 950;
  color: #5a3404;
  text-shadow: 0 2px 0 white;
}
.reward-burst-item img {
  width: 72px;
  height: 72px;
  object-fit: contain;
  filter: drop-shadow(0 6px 5px rgba(0,0,0,.18));
}
@keyframes reward-float {
  0% { opacity: 0; transform: translate(-50%, -20%) scale(.45); }
  18% { opacity: 1; transform: translate(-50%, -55%) scale(1.08); }
  100% { opacity: 0; transform: translate(-50%, -175%) scale(.86); }
}

/* Compact word-search screen: no extra title or redundant texts. */
.word-search-screen {
  padding: 76px 24px 16px;
}
.word-layout {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: minmax(250px, 340px) minmax(0, 580px);
  justify-content: center;
  align-items: center;
  gap: 18px;
  overflow: hidden;
}
.words-panel,
.grid-panel {
  min-height: 0;
  background: rgba(255,255,255,.9);
  border-radius: 24px;
  box-shadow: 0 8px 22px rgba(24,53,77,.1);
}
.words-panel {
  max-height: 100%;
  padding: 10px 12px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
  overflow: hidden;
}
.word-search-counter {
  width: fit-content;
  min-width: 74px;
  margin: 0 auto;
  padding: 5px 14px;
  border-radius: 14px;
  background: #dff6fc;
  border: 2px solid #93d9e9;
  font-size: 24px;
  font-weight: 950;
  direction: ltr;
}
.word-list {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: center;
  gap: 10px;
  overflow: hidden;
}
.word-list[data-count="5"],
.word-list[data-count="6"] {
  grid-template-columns: 1fr;
}
.word-list[data-count="10"],
.word-list[data-count="12"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.word-chip {
  min-width: 0;
  min-height: 54px;
  background: var(--word-background, #eef9fc);
  border: 3px solid var(--word-border, #c7eaf2);
  color: var(--word-text, var(--ink));
  border-radius: 14px;
  padding: 10px 8px;
  font-weight: 900;
  font-size: clamp(22px, 1.95vw, 28px);
  text-align: center;
  line-height: 1.2;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 -3px 0 rgba(24,53,77,.12);
}
.word-chip.found {
  background: var(--word-background, #d8f5df);
  border-color: var(--word-border, #267a42);
  color: var(--word-text, #267a42);
  text-decoration: line-through;
  opacity: .72;
}
.grid-panel {
  padding: 12px;
  display: grid;
  place-items: center;
  overflow: hidden;
}
.word-grid {
  width: min(70vh, 525px);
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1;
  display: grid;
  direction: ltr;
  gap: 4px;
  user-select: none;
  touch-action: manipulation;
}
.letter-cell {
  min-width: 0;
  min-height: 0;
  border: 3px solid transparent;
  border-radius: 9px;
  background: #cfd0ff;
  box-shadow: inset 0 -3px 0 rgba(38,55,95,.18);
  cursor: pointer;
  color: #101c35;
  font-weight: 950;
  font-size: clamp(18px, 2vw, 28px);
  display: grid;
  place-items: center;
  line-height: 1;
  transition: transform .1s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.letter-cell:hover { transform: scale(1.04); }
.letter-cell:disabled { cursor: default; }
.letter-cell.selected {
  position: relative;
  z-index: 2;
  background: #ffcf2f !important;
  border-color: #f07f16;
  color: #382100;
  box-shadow: 0 0 0 2px #fff, 0 0 0 5px #f07f16, inset 0 -3px 0 rgba(121,62,0,.22);
  transform: scale(1.07);
}
.letter-cell.found {
  background: var(--word-background, #62d78d);
  border-color: var(--word-border, #249a55);
  color: var(--word-text, #08351b);
  box-shadow: 0 0 0 1px white, inset 0 -3px 0 rgba(8,53,27,.18);
}


/* חלון הסיפור שנפתח מצדו השמאלי של המשחק. */
.story-reader-layer {
  position: absolute;
  inset: 0;
  z-index: 80;
  pointer-events: none;
}
.story-reader-scrim {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  padding: 0;
  background: rgba(14, 33, 49, .14);
  cursor: default;
  pointer-events: auto;
}
.story-reader-panel {
  position: absolute;
  top: 76px;
  bottom: 18px;
  left: 18px;
  width: min(535px, 47%);
  min-width: 420px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  padding: 18px 22px 16px;
  border: 4px solid #92d9e9;
  border-radius: 26px;
  background: rgba(255, 255, 255, .985);
  box-shadow: 0 18px 42px rgba(24,53,77,.28);
  direction: rtl;
  pointer-events: auto;
  animation: story-reader-in .24s ease-out both;
}
@keyframes story-reader-in {
  from { transform: translateX(-105%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
.story-reader-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 2px solid #d9edf2;
  padding-bottom: 10px;
}
.story-reader-header h2 {
  margin: 0;
  font-size: 30px;
  color: #177fa3;
}
.story-reader-close {
  width: 43px;
  height: 43px;
  border: 0;
  border-radius: 13px;
  background: #edf8fb;
  color: #18354d;
  font-size: 34px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}
.story-reader-text {
  min-height: 0;
  margin: 0;
  padding: 2px 6px;
  overflow-y: auto;
  white-space: pre-line;
  font-size: clamp(21px, 2vw, 27px);
  font-weight: 700;
  line-height: 1.7;
  text-align: right;
}
.story-reader-media-wrap {
  min-height: 0;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 16px;
  background: white;
}
.story-reader-media {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.story-reader-navigation {
  position: relative;
  display: grid;
  grid-template-columns: 58px 1fr 58px;
  align-items: center;
  gap: 12px;
  direction: ltr;
  padding-top: 4px;
}
.story-arrow {
  width: 58px;
  height: 48px;
  border: 0;
  border-radius: 16px;
  background: #dff6fc;
  color: #17637e;
  box-shadow: 0 5px 0 rgba(24,53,77,.14);
  font-size: 34px;
  font-weight: 950;
  cursor: pointer;
  line-height: 1;
}
.story-arrow:disabled {
  opacity: .28;
  cursor: default;
  box-shadow: none;
}
.story-prev { grid-column: 3; grid-row: 1; }
.story-next { grid-column: 1; grid-row: 1; }
.story-page-indicator {
  grid-column: 2;
  grid-row: 1;
  justify-self: center;
  min-width: 76px;
  padding: 7px 14px;
  border-radius: 14px;
  background: #eef9fc;
  font-size: 22px;
  font-weight: 900;
  direction: ltr;
  text-align: center;
}

@media (max-width: 1000px) {
  .topbar { grid-template-columns: 190px minmax(130px, 1fr) 150px; }
  .story-reader-panel { width: min(500px, 53%); min-width: 380px; }
  .word-layout { grid-template-columns: minmax(220px, 280px) minmax(0, 500px); gap: 14px; }
  .word-grid { width: min(68vh, 500px); }
  .word-chip { font-size: clamp(20px, 2.2vw, 24px); }
}

@media (max-width: 760px) {
  html, body { overflow: auto; }
  .app { height: auto; min-height: 100%; padding: 0; }
  .screen {
    width: 100%;
    height: auto;
    min-height: 100vh;
    border: 0;
    border-radius: 0;
    padding: 76px 16px 22px;
    overflow: visible;
  }
  .topbar {
    inset: 10px 10px auto;
    grid-template-columns: auto 1fr auto;
    gap: 8px;
  }
  .home-button { width: 50px; height: 46px; }
  .book-button,
  .fullscreen-button { width: 42px; height: 42px; }
  .book-button svg { width: 30px; height: 30px; }
  .story-reader-panel {
    top: 68px;
    right: 10px;
    bottom: 10px;
    left: 10px;
    width: auto;
    min-width: 0;
    padding: 15px 16px 13px;
  }
  .story-reader-text { font-size: clamp(20px, 5vw, 25px); line-height: 1.62; }
  .topbar__controls { gap: 3px; }
  .answers { grid-template-columns: 1fr; }
  .question-header { min-height: 112px; margin-bottom: 8px; }
  .question-instruction-row { gap: 8px; }
  .question-instructions { font-size: clamp(19px, 5vw, 25px); }
  .speaker-button { width: 50px; height: 50px; padding: 8px; }
  .question-wrap { height: auto; grid-template-rows: auto auto; }
  .question-card { min-height: 125px; }
  .answer-card { min-height: 105px; }
  .word-search-screen { padding-top: 72px; overflow: hidden; }
  .word-layout {
    height: calc(100vh - 96px);
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 8px;
  }
  .words-panel { padding: 8px; gap: 6px; }
  .word-list { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
  .word-chip { font-size: 15px; padding: 4px; }
  .word-search-counter { font-size: 18px; padding: 3px 10px; }
  .grid-panel { padding: 7px; }
  .word-grid { width: min(82vw, 58vh, 500px); }
  .letter-cell { border-radius: 6px; font-size: clamp(17px, 4vw, 25px); }
  .large-hint-panel {
    width: min(720px, 92vw);
    height: min(500px, 76vh);
    padding: 12px;
  }
  .hint-close-button { width: 44px; height: 44px; font-size: 30px; }
}

@media (max-width: 500px) {
  .progress { display: none; }
  .topbar { grid-template-columns: auto 1fr; }
  .hero-card { padding: 28px 18px; }
  .level-choices { grid-template-columns: 1fr 1fr; gap: 10px; }
  .level-card { min-width: 0; min-height: 100px; padding: 10px; }
  .word-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .finish-actions { flex-direction: column; }
}

/* שמירה לפני יציאה מכפתור הבית */
body.is-saving-before-close .home-button,
body.is-saving-before-close .final-home-button {
  pointer-events: none;
  opacity: 0.72;
  filter: saturate(0.75);
}

body.activity-closed {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background: #f8e4dc;
}
