:root {
  color-scheme: light;
  --iris: #6557d9;
  --iris-deep: #493cae;
  --lavender: #f3f1ff;
  --lavender-strong: #e5e0ff;
  --ink: #251f3f;
  --ink-soft: #6d6682;
  --paper: #fffefe;
  --line: #d9d4e8;
  --exact: #6557d9;
  --present: #ec7a65;
  --absent: #8b8798;
  --mint: #2f9b83;
  --topbar: rgba(255, 254, 254, 0.78);
  --tile-surface: rgba(255, 254, 254, 0.88);
  --key-surface: #e8e5ef;
  --key-line: #c7c2d6;
  --badge-surface: rgba(243, 241, 255, 0.94);
  --badge-line: rgba(101, 87, 217, 0.28);
  --badge-ink: #493cae;
  --word-length: 5;
  --tile-fluid: 11vw;
  --tile-max: 4rem;
  --tile: clamp(1.9rem, var(--tile-fluid), var(--tile-max));
  --gap: clamp(0.3rem, 1.7vw, 0.55rem);
  font-family: "Heebo", "Arial", "Noto Sans Hebrew", sans-serif;
}

html.dark {
  color-scheme: dark;
  --iris: #8b7cf6;
  --iris-deep: #b9adff;
  --lavender: #111827;
  --lavender-strong: #29344a;
  --ink: #f8fafc;
  --ink-soft: #aab5c7;
  --paper: #1b2638;
  --line: #465269;
  --exact: #7667e8;
  --present: #d66f5e;
  --absent: #586277;
  --mint: #50c5a8;
  --topbar: rgba(23, 33, 49, 0.86);
  --tile-surface: rgba(27, 38, 56, 0.92);
  --key-surface: #303b50;
  --key-line: #1f293b;
  --badge-surface: rgba(139, 124, 246, 0.18);
  --badge-line: rgba(185, 173, 255, 0.42);
  --badge-ink: #f1efff;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  min-height: 100%;
  background: var(--lavender);
  -webkit-text-size-adjust: 100%;
}

body {
  min-width: 18rem;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, rgba(236, 122, 101, 0.12), transparent 26rem),
    radial-gradient(circle at 88% 92%, rgba(101, 87, 217, 0.12), transparent 28rem),
    var(--lavender);
  touch-action: manipulation;
  overscroll-behavior: none;
}

html.dark body {
  background:
    radial-gradient(circle at 12% 8%, rgba(214, 111, 94, 0.09), transparent 26rem),
    radial-gradient(circle at 88% 92%, rgba(139, 124, 246, 0.13), transparent 28rem),
    var(--lavender);
}

button { font: inherit; }

button, [role="button"] {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
  outline: 3px solid rgba(101, 87, 217, 0.38);
  outline-offset: 3px;
}

.app-shell {
  width: 100%;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto 1fr auto;
  background-image: linear-gradient(rgba(101, 87, 217, 0.035) 1px, transparent 1px), linear-gradient(90deg, rgba(101, 87, 217, 0.035) 1px, transparent 1px);
  background-size: 28px 28px;
}

.topbar {
  min-height: 4.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: max(0.65rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) 0.65rem max(1rem, env(safe-area-inset-left));
  border-bottom: 1px solid rgba(101, 87, 217, 0.12);
  background: var(--topbar);
  backdrop-filter: blur(14px);
}

.brand { display: flex; align-items: center; gap: 0.65rem; color: inherit; text-decoration: none; }
.brand-mark {
  width: 2.6rem;
  height: 2.6rem;
  display: grid;
  place-items: center;
  position: relative;
  border-radius: 1rem 1rem 0.35rem 1rem;
  color: white;
  background: var(--iris);
  font-size: 1.35rem;
  font-weight: 900;
  box-shadow: 0 7px 18px rgba(73, 60, 174, 0.2);
}
.brand strong { display: block; font-size: 1.05rem; line-height: 1.1; font-weight: 900; }
.brand small { display: block; margin-top: 0.18rem; color: var(--ink-soft); font-size: 0.72rem; font-weight: 700; }
.top-actions { display: flex; gap: 0.45rem; }
.icon-button, .modal-close {
  width: 2.7rem;
  height: 2.7rem;
  border: 1px solid rgba(101, 87, 217, 0.16);
  border-radius: 0.9rem;
  color: var(--ink);
  background: var(--paper);
  font-weight: 900;
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(37, 31, 63, 0.06);
  transition: transform 140ms ease, background 140ms ease;
  display: grid;
  place-items: center;
  text-decoration: none;
}
.icon-button:active, .modal-close:active { transform: scale(0.91); }
.icon-button[aria-pressed="true"] { color: white; background: var(--iris); }

.game {
  width: min(100%, 35rem);
  margin: 0 auto;
  padding: clamp(0.75rem, 2.5vh, 1.5rem) 1rem 0.75rem;
  align-self: start;
}

.game-heading { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: 0.8rem; }
.eyebrow { margin: 0 0 0.2rem; color: var(--iris-deep); font-size: 0.72rem; line-height: 1.2; font-weight: 900; letter-spacing: 0.06em; }
.game-heading h1 { margin: 0; font-size: clamp(1.2rem, 5vw, 1.65rem); line-height: 1.15; font-weight: 900; letter-spacing: -0.02em; }
.weekly-badge { display: flex; align-items: center; gap: 0.4rem; flex: 0 0 auto; padding: 0.45rem 0.65rem; border: 1px solid var(--badge-line); border-radius: 999px; background: var(--badge-surface); color: var(--badge-ink); font-size: 0.69rem; font-weight: 800; }
.weekly-badge-dot { width: 0.45rem; height: 0.45rem; border-radius: 50%; background: var(--mint); box-shadow: 0 0 0 4px rgba(47, 155, 131, 0.12); }

.account-strip { min-height: 1.9rem; display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin: -0.2rem 0 0.55rem; padding: 0.35rem 0.65rem; border: 1px solid rgba(101, 87, 217, 0.13); border-radius: 0.75rem; color: var(--ink-soft); background: color-mix(in srgb, var(--paper) 74%, transparent); font-size: 0.68rem; font-weight: 750; }
.account-strip strong { flex: 0 0 auto; color: var(--iris-deep); }

.board-wrap { position: relative; width: max-content; margin: 0 auto; padding-inline-start: 1.75rem; }
.board { display: grid; grid-template-rows: repeat(5, var(--tile)); gap: var(--gap); direction: rtl; }
.guess-row { display: grid; grid-template-columns: repeat(var(--word-length), var(--tile)); gap: var(--gap); position: relative; }
.guess-row::before {
  content: "";
  position: absolute;
  inset: -0.18rem;
  z-index: -1;
  border-radius: 1rem;
  background: transparent;
  transition: background 180ms ease;
}
.guess-row.is-current::before { background: rgba(101, 87, 217, 0.06); }

.tile {
  position: relative;
  display: grid;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 1rem 1rem 0.42rem 1rem;
  background: var(--tile-surface);
  color: var(--ink);
  font-size: clamp(1.32rem, 6vw, 2rem);
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 4px 11px rgba(37, 31, 63, 0.055);
  transform-style: preserve-3d;
  transition: border-color 120ms ease, transform 120ms ease, background 120ms ease;
}
.tile.has-letter { border-color: rgba(101, 87, 217, 0.55); animation: tile-pop 140ms ease-out; }
.tile small { position: absolute; inset-inline-start: 0.3rem; inset-block-end: 0.22rem; font-size: 0.55rem; font-weight: 900; opacity: 0; }
.tile.is-revealing { animation: tile-stamp 460ms cubic-bezier(.2,.72,.22,1) both; }
.tile.is-exact { color: white; border-color: var(--exact); background: var(--exact); box-shadow: 0 7px 17px rgba(101, 87, 217, 0.22); }
.tile.is-present { color: white; border-color: var(--present); background: var(--present); box-shadow: 0 7px 17px rgba(236, 122, 101, 0.18); }
.tile.is-absent { color: white; border-color: var(--absent); background: var(--absent); }
.tile.is-exact small, .tile.is-present small, .tile.is-absent small { opacity: 0.9; }
.guess-row.is-shaking { animation: row-shake 330ms ease; }
.guess-row.is-winner .tile { animation: winner-rise 560ms cubic-bezier(.18,.8,.2,1) both; animation-delay: calc(var(--tile-index) * 70ms); }

.score-rail { position: absolute; inset-inline-start: 0; inset-block: 0; display: grid; grid-template-rows: repeat(5, var(--tile)); gap: var(--gap); color: var(--ink-soft); font-size: 0.7rem; font-weight: 900; }
.score-rail span { display: grid; place-items: center; width: 1.25rem; border-radius: 999px; transition: color 200ms ease, background 200ms ease, transform 200ms ease; }
.score-rail span.is-active { color: white; background: var(--iris); transform: scale(1.08); }

.status-line { min-height: 1.55rem; display: grid; place-items: center; margin: 0.6rem 0 0.35rem; color: var(--ink-soft); text-align: center; font-size: 0.79rem; font-weight: 800; }
.status-line.is-error { color: #a73645; }
.status-line.is-success { color: var(--iris-deep); }
.legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.35rem 0.8rem; margin-bottom: 0.6rem; color: var(--ink-soft); font-size: 0.66rem; font-weight: 700; }
.legend span { display: inline-flex; align-items: center; gap: 0.25rem; }
.legend-mark { width: 1rem; height: 1rem; display: grid; place-items: center; border-radius: 0.34rem; color: white; font-size: 0.58rem; font-style: normal; }
.legend-mark.exact { background: var(--exact); }
.legend-mark.present { background: var(--present); }
.legend-mark.absent { background: var(--absent); }

.keyboard { display: grid; gap: 0.38rem; width: 100%; max-width: 33rem; margin: 0 auto; direction: rtl; }
.keyboard-row { display: flex; justify-content: center; gap: clamp(0.2rem, 1vw, 0.34rem); direction: rtl; }
.key {
  min-width: 0;
  height: clamp(2.65rem, 7.5vh, 3.25rem);
  flex: 1 1 0;
  max-width: 3.25rem;
  border: 0;
  border-bottom: 3px solid var(--key-line);
  border-radius: 0.72rem;
  color: var(--ink);
  background: var(--key-surface);
  font-size: clamp(0.94rem, 4.8vw, 1.16rem);
  font-weight: 900;
  cursor: pointer;
  user-select: none;
  transition: transform 90ms ease, color 160ms ease, background 160ms ease, border-color 160ms ease;
}
.key.action { flex: 1.35 1 0; max-width: 4.25rem; padding: 0 0.35rem; font-size: 0.72rem; }
.key[data-key="delete"] { font-size: calc(0.72rem + 15px); }
.key[data-key="enter"] { font-size: calc(0.72rem + 5px); }
.key:active, .key.is-pressed { transform: translateY(2px) scale(0.96); border-bottom-width: 1px; }
.key.is-exact { color: white; border-color: var(--iris-deep); background: var(--exact); }
.key.is-present { color: white; border-color: #c95f4c; background: var(--present); }
.key.is-absent { color: white; border-color: #6f6b7c; background: var(--absent); }
.key:disabled { cursor: not-allowed; }
.key.is-absent:disabled { opacity: 0.48; filter: saturate(0.4); transform: none; }

.game-footer { min-height: 2.1rem; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 0.35rem 1rem; padding: 0.45rem max(1rem, env(safe-area-inset-right)) max(0.55rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left)); color: var(--ink-soft); font-size: 0.63rem; font-weight: 700; text-align: center; }
.game-footer a { color: inherit; text-underline-offset: 0.15rem; }

.game-gate { max-width: 28rem; margin: 0.8rem auto 0; padding: 1.1rem; border: 1px solid var(--lavender-strong); border-radius: 1.15rem; background: color-mix(in srgb, var(--paper) 90%, transparent); text-align: center; box-shadow: 0 10px 25px rgba(37, 31, 63, 0.08); }
.game-gate[hidden] { display: none; }
.game-gate strong { display: block; font-size: 1rem; }
.game-gate p { margin: 0.4rem 0 0.9rem; color: var(--ink-soft); font-size: 0.8rem; line-height: 1.45; }

.modal { max-width: none; max-height: none; width: 100%; height: 100%; padding: 1rem; border: 0; background: transparent; }
.modal::backdrop { background: rgba(37, 31, 63, 0.46); backdrop-filter: blur(5px); }
.modal[open] { display: grid; place-items: center; }
.modal-card { width: min(100%, 27rem); position: relative; overflow: hidden; margin: auto; padding: 1.4rem; border: 1px solid rgba(101, 87, 217, 0.15); border-radius: 1.6rem; color: var(--ink); background: var(--paper); box-shadow: 0 25px 70px rgba(37, 31, 63, 0.25); }
.modal-close { position: absolute; inset-block-start: 0.8rem; inset-inline-end: 0.8rem; box-shadow: none; }
.modal-card h2 { margin: 0.3rem 0 1rem; padding-inline-end: 2.5rem; font-size: 1.55rem; line-height: 1.2; font-weight: 900; }
.rules-list { display: grid; gap: 0.75rem; margin: 0; padding-inline-start: 1.35rem; color: var(--ink-soft); font-size: 0.9rem; line-height: 1.55; }
.rules-list strong { color: var(--ink); }
.help-example { display: flex; gap: 0.5rem; justify-content: center; margin: 1.2rem 0; direction: rtl; }
.mini-tile { width: 3.15rem; height: 3.15rem; display: grid; place-items: center; position: relative; border-radius: 0.9rem 0.9rem 0.35rem 0.9rem; color: white; font-size: 1.3rem; font-weight: 900; }
.mini-tile.exact { background: var(--exact); }
.mini-tile.present { background: var(--present); }
.mini-tile.absent { background: var(--absent); }
.mini-tile small { position: absolute; inset-inline-start: 0.25rem; inset-block-end: 0.15rem; font-size: 0.55rem; }
.help-note { margin: 0 0 1.1rem; color: var(--ink-soft); font-size: 0.8rem; line-height: 1.5; }
.primary-button { width: 100%; min-height: 3rem; border: 0; border-radius: 1rem; color: white; background: var(--iris); font-weight: 900; cursor: pointer; box-shadow: 0 8px 20px rgba(73, 60, 174, 0.22); transition: transform 120ms ease, background 120ms ease; }
.primary-button:hover { background: var(--iris-deep); }
.primary-button:active { transform: scale(0.98); }
.result-home-button { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.secondary-button { width: 100%; min-height: 3rem; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--lavender-strong); border-radius: 1rem; color: var(--iris-deep); background: var(--lavender); font-weight: 900; text-decoration: none; }
.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.55rem; }

.result-card { text-align: center; }
.result-seal { width: 6.6rem; height: 6.6rem; display: grid; place-content: center; margin: 0 auto 1rem; border: 0.55rem solid var(--lavender-strong); border-radius: 50%; color: white; background: var(--iris); box-shadow: 0 0 0 1px var(--iris), 0 15px 35px rgba(73, 60, 174, 0.25); animation: seal-arrive 520ms cubic-bezier(.18,.89,.32,1.28) both; }
.result-seal span { font-size: 2.5rem; line-height: 0.9; font-weight: 900; }
.result-seal small { margin-top: 0.25rem; font-size: 0.72rem; font-weight: 900; }
.result-seal.is-loss { color: var(--ink); background: #e4e1ea; box-shadow: 0 0 0 1px #c9c4d4, 0 15px 35px rgba(37, 31, 63, 0.12); }
.result-card h2 { padding: 0; }
.result-copy { margin: -0.35rem 0 1rem; color: var(--ink-soft); font-size: 0.9rem; }
.answer-ribbon { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 1rem 0; padding: 0.85rem 1rem; border: 1px solid var(--lavender-strong); border-radius: 1rem; background: var(--lavender); text-align: start; }
.answer-ribbon span { color: var(--ink-soft); font-size: 0.72rem; font-weight: 800; }
.answer-ribbon strong { font-size: 1.35rem; letter-spacing: 0.12em; }
@keyframes tile-pop { 50% { transform: scale(1.08); } }
@keyframes tile-stamp { 0% { transform: rotateX(0deg) scale(1); } 48% { transform: rotateX(88deg) scale(0.93); } 52% { transform: rotateX(92deg) scale(0.93); } 100% { transform: rotateX(0deg) scale(1); } }
@keyframes row-shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
@keyframes winner-rise { 50% { transform: translateY(-0.55rem) rotate(-2deg); } }
@keyframes seal-arrive { from { opacity: 0; transform: scale(0.55) rotate(-10deg); } to { opacity: 1; transform: scale(1) rotate(0); } }

@media (max-width: 25rem) {
  .topbar { min-height: 3.75rem; }
  .brand small { display: none; }
  .game-heading { align-items: center; }
  .weekly-badge { max-width: 7rem; white-space: normal; line-height: 1.15; }
  .legend { margin-bottom: 0.45rem; }
}

@media (max-height: 42rem) and (orientation: portrait) {
  :root { --tile: clamp(1.75rem, var(--tile-fluid), 3rem); --gap: 0.25rem; }
  .game { padding-top: 0.55rem; }
  .game-heading { margin-bottom: 0.45rem; }
  .game-heading h1 { font-size: 1.05rem; }
  .weekly-badge, .legend, .account-strip { display: none; }
  .game-footer { display: none; }
  .status-line { margin-block: 0.35rem 0.2rem; }
  .key { height: 2.45rem; }
}

@media (orientation: landscape) and (max-height: 34rem) {
  .app-shell { min-height: 100dvh; }
  .topbar { min-height: 3.4rem; padding-block: 0.4rem; }
  .brand small, .weekly-badge, .legend, .game-footer, .account-strip { display: none; }
  .game { width: min(100%, 48rem); display: grid; grid-template-columns: auto minmax(18rem, 1fr); grid-template-rows: auto auto; align-items: center; gap: 0.4rem 1.2rem; padding-block: 0.45rem; }
  .game-heading { grid-column: 1 / -1; margin: 0; }
  .board-wrap { grid-row: 2; grid-column: 1; }
  .status-line { grid-row: 2; grid-column: 2; align-self: start; margin: 0; }
  .keyboard { grid-row: 2; grid-column: 2; align-self: center; }
  :root { --tile: clamp(2.2rem, 11.5vh, 3.1rem); --gap: 0.23rem; }
  .key { height: clamp(2.2rem, 12vh, 2.9rem); }
}

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