:root {
  color-scheme: light;
  --blue-900: #12336f;
  --blue-800: #1746a2;
  --blue-700: #205bc0;
  --blue-100: #dceaff;
  --blue-50: #eef6ff;
  --ink: #172033;
  --muted: #64708a;
  --line: #d7e0ed;
  --paper: #ffffff;
  --success: #12805c;
  --success-soft: #dff6eb;
  --error: #b63e45;
  --error-soft: #fde8e9;
  --shadow: 0 14px 38px rgba(25, 57, 103, .12);
}

* { box-sizing: border-box; }

html { min-height: 100%; background: #dcefff; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 13% 8%, rgba(255,255,255,.9) 0 7%, transparent 24%),
    linear-gradient(150deg, #dff3ff 0%, #eaf1ff 52%, #d7e8ff 100%);
}

button, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 24px auto;
  min-height: calc(100vh - 48px);
  background: rgba(255,255,255,.96);
  border: 1px solid rgba(255,255,255,.95);
  border-radius: 24px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.topbar {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 12px 24px;
  color: white;
  background: linear-gradient(110deg, var(--blue-900), var(--blue-700));
}

.brand { display: flex; align-items: center; gap: 12px; color: white; font-size: 1.08rem; font-weight: 750; }
.brand-button { padding: 0; border: 0; background: transparent; cursor: pointer; }
.brand-button:focus-visible { outline: 3px solid #ffdc78; outline-offset: 5px; border-radius: 8px; }
.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 12px;
  background: rgba(255,255,255,.14);
  font-family: "Noto Sans Hebrew", Arial, sans-serif;
  font-size: 1.55rem;
}

.top-actions { display: flex; gap: 8px; }
.icon-button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 10px;
  color: white;
  background: rgba(255,255,255,.1);
  cursor: pointer;
}
.icon-button:hover { background: rgba(255,255,255,.19); }
.icon-button:focus-visible { outline: 3px solid #ffdc78; outline-offset: 2px; }
.icon-button svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.game, .lesson-library { padding: 30px clamp(18px, 4vw, 48px) 48px; }
.is-hidden { display: none !important; }

.library-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
.library-help { margin: 8px 0 0; color: var(--muted); }
.add-lesson { display: inline-flex; align-items: center; gap: 7px; flex: 0 0 auto; }
.add-lesson span { font-size: 1.25rem; line-height: 1; }
.lesson-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.lesson-card { min-width: 0; overflow: hidden; border: 1px solid #cfd9e7; border-radius: 14px; background: white; box-shadow: 0 5px 15px rgba(28,63,108,.08); transition: transform .16s ease, box-shadow .16s ease; }
.lesson-card:hover { transform: translateY(-2px); box-shadow: 0 11px 24px rgba(28,63,108,.13); }
.lesson-preview { width: 100%; min-height: 154px; display: grid; grid-template-columns: repeat(4, 1fr); align-content: center; gap: 4px; padding: 18px; border: 0; border-bottom: 1px solid #dbe3ee; background: #f7faff; cursor: pointer; }
.lesson-preview:focus-visible { outline: 3px solid #ffcf4b; outline-offset: -3px; }
.lesson-preview span { min-width: 0; padding: 5px 3px; overflow: hidden; border-radius: 3px; color: white; font-family: "Noto Sans Hebrew", "Arial Hebrew", Arial, sans-serif; font-size: .79rem; font-weight: 650; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
.lesson-details { min-height: 84px; display: grid; grid-template-columns: 1fr auto; align-items: stretch; }
.lesson-launch { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 5px; padding: 13px 16px; border: 0; color: var(--ink); background: white; text-align: left; cursor: pointer; }
.lesson-launch strong { max-width: 100%; overflow: hidden; font-size: 1.06rem; text-overflow: ellipsis; white-space: nowrap; }
.lesson-launch span { color: var(--muted); font-size: .86rem; }
.lesson-launch:focus-visible, .lesson-menu:focus-visible { outline: 3px solid #ffcf4b; outline-offset: -3px; }
.lesson-menu { width: 48px; border: 0; border-left: 1px solid #e2e8f1; color: var(--blue-900); background: white; font-size: 1.55rem; font-weight: 800; cursor: pointer; }
.lesson-menu:hover { background: var(--blue-50); }
.back-button { display: inline-flex; align-items: center; gap: 5px; margin: 0 0 20px; padding: 6px 8px 6px 3px; border: 0; border-radius: 8px; color: var(--blue-700); background: transparent; font-weight: 750; cursor: pointer; }
.back-button:hover { background: var(--blue-50); }
.back-button:focus-visible { outline: 3px solid #ffcf4b; }
.back-button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.game-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 28px; }
.eyebrow { margin: 0 0 5px; color: var(--blue-700); font-size: .78rem; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }
h1, h2, p { text-wrap: pretty; }
h1 { margin: 0; font-size: clamp(1.55rem, 3.2vw, 2.3rem); line-height: 1.15; letter-spacing: -.025em; }

.scoreboard { display: grid; grid-template-columns: repeat(3, minmax(72px, 1fr)); gap: 10px; }
.stat {
  min-width: 82px;
  padding: 9px 12px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--blue-50);
}
.stat span { display: block; color: var(--muted); font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.stat strong { font-size: 1.15rem; font-variant-numeric: tabular-nums; }

.progress-track { height: 7px; margin: 22px 0 16px; border-radius: 999px; background: #e9edf4; overflow: hidden; }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #33a9e8, var(--blue-700)); transition: width .35s ease; }
.instruction { margin-bottom: 18px; color: var(--muted); font-size: .95rem; }

.board { display: grid; grid-template-columns: 1fr 1fr; gap: clamp(12px, 3vw, 34px); }
.card-column {
  min-width: 0;
  padding: clamp(12px, 2vw, 20px);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #f7faff;
}
.card-column h2 { margin: 0 0 13px; color: var(--muted); font-size: .8rem; letter-spacing: .08em; text-transform: uppercase; }
.cards { display: grid; gap: 11px; }

.word-card {
  width: 100%;
  min-height: 66px;
  display: grid;
  place-items: center;
  padding: 12px 16px;
  border: 1px solid #cad6e7;
  border-radius: 12px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 3px 9px rgba(28, 63, 108, .07);
  font-weight: 690;
  line-height: 1.3;
  cursor: pointer;
  transition: transform .14s ease, border-color .14s ease, box-shadow .14s ease, opacity .24s ease, background .14s ease;
}
.word-card:hover { transform: translateY(-1px); border-color: #8cabd4; box-shadow: 0 6px 14px rgba(28,63,108,.11); }
.word-card:focus-visible { outline: 3px solid #ffcf4b; outline-offset: 2px; }
.word-card.hebrew { direction: rtl; font-family: "Noto Sans Hebrew", "Arial Hebrew", Arial, sans-serif; font-size: clamp(1.35rem, 3vw, 1.75rem); font-weight: 650; }
.word-card.selected { color: white; border-color: var(--blue-700); background: var(--blue-700); box-shadow: 0 7px 18px rgba(32,91,192,.26); transform: translateY(-1px); }
.word-card.wrong { color: var(--error); border-color: #e28a8f; background: var(--error-soft); animation: shake .32s ease; }
.word-card.matched { color: var(--success); border-color: #8cccb2; background: var(--success-soft); opacity: 0; transform: scale(.94); pointer-events: none; }

@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-6px)} 75%{transform:translateX(6px)} }

.dialog { max-width: none; max-height: none; padding: 0; border: 0; background: transparent; }
.dialog::backdrop { background: rgba(9,22,48,.56); backdrop-filter: blur(3px); }
.dialog-card {
  width: min(680px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  overflow: auto;
  padding: clamp(20px, 4vw, 34px);
  border-radius: 20px;
  background: white;
  box-shadow: 0 24px 70px rgba(4,18,45,.3);
}
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.dialog-header h2, .result-card h2 { margin: 0; font-size: 1.65rem; }
.close-button { width: 42px; height: 42px; border: 0; border-radius: 50%; color: var(--muted); background: #edf2f9; font-size: 1.8rem; line-height: 1; cursor: pointer; }
.dialog-help { color: var(--muted); line-height: 1.55; }
textarea {
  width: 100%;
  min-height: 290px;
  resize: vertical;
  padding: 14px;
  border: 1px solid #bcc9dc;
  border-radius: 12px;
  color: var(--ink);
  background: #fbfdff;
  font-family: ui-monospace, "Noto Sans Hebrew", Consolas, monospace;
  font-size: 1rem;
  line-height: 1.65;
}
.field-label { display: block; margin: 20px 0 7px; font-size: .9rem; font-weight: 780; }
.text-input { width: 100%; min-height: 48px; padding: 10px 13px; border: 1px solid #bcc9dc; border-radius: 11px; color: var(--ink); background: #fbfdff; font-size: 1rem; }
.text-input:focus { outline: 3px solid var(--blue-100); border-color: var(--blue-700); }
textarea:focus { outline: 3px solid var(--blue-100); border-color: var(--blue-700); }
.editor-meta { display: flex; justify-content: space-between; gap: 16px; margin-top: 8px; color: var(--muted); font-size: .9rem; }
.text-button { padding: 0; border: 0; color: var(--blue-700); background: transparent; font-weight: 700; cursor: pointer; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }
.button { min-height: 46px; padding: 10px 18px; border: 0; border-radius: 11px; font-weight: 760; cursor: pointer; }
.button.primary { color: white; background: var(--blue-700); }
.button.primary:hover { background: var(--blue-800); }
.button.secondary { color: var(--ink); background: #e9eff7; }
.button:focus-visible, .close-button:focus-visible, .text-button:focus-visible { outline: 3px solid #ffcf4b; outline-offset: 2px; }

.result-card { width: min(480px, calc(100vw - 28px)); text-align: center; }
.result-symbol { width: 76px; height: 76px; display: grid; place-items: center; margin: 0 auto 20px; border-radius: 50%; color: white; background: var(--success); font-size: 2.3rem; font-weight: 800; }
.result-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 24px 0; }
.result-stats div { padding: 16px; border-radius: 13px; background: var(--blue-50); }
.result-stats span { display: block; color: var(--muted); font-size: .78rem; font-weight: 700; text-transform: uppercase; }
.result-stats strong { font-size: 1.45rem; }
.wide { width: 100%; }
.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.toast { position: fixed; left: 50%; bottom: 22px; z-index: 20; max-width: calc(100vw - 32px); padding: 11px 16px; border-radius: 999px; color: white; background: #172033; box-shadow: 0 8px 26px rgba(0,0,0,.22); opacity: 0; pointer-events: none; transform: translate(-50%, 12px); transition: opacity .2s ease, transform .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 720px) {
  .app-shell { width: 100%; min-height: 100vh; margin: 0; border-radius: 0; }
  .topbar { padding: 10px 14px; }
  .icon-button span { display: none; }
  .icon-button { width: 43px; justify-content: center; padding: 8px; }
  .game, .lesson-library { padding: 22px 12px 30px; }
  .library-heading { align-items: flex-start; flex-direction: column; gap: 16px; }
  .add-lesson { width: 100%; justify-content: center; }
  .lesson-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .lesson-preview { min-height: 118px; grid-template-columns: repeat(3, 1fr); padding: 10px; }
  .lesson-preview span { font-size: .7rem; }
  .lesson-details { min-height: 76px; }
  .lesson-launch { padding: 10px; }
  .lesson-launch strong { font-size: .94rem; }
  .lesson-menu { width: 39px; }
  .game-heading { align-items: flex-start; flex-direction: column; gap: 16px; }
  .scoreboard { width: 100%; }
  .stat { min-width: 0; padding: 8px; }
  .instruction { font-size: .88rem; }
  .board { gap: 8px; }
  .card-column { padding: 8px; border-radius: 13px; }
  .card-column h2 { margin: 4px 3px 9px; }
  .cards { gap: 8px; }
  .word-card { min-height: 62px; padding: 9px 7px; border-radius: 10px; font-size: .92rem; }
  .word-card.hebrew { font-size: 1.3rem; }
  .editor-meta { align-items: flex-start; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
