:root {
  color-scheme: dark;
  --gold: #f4d488;
  --gold-light: #fff1bd;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  overflow-x: hidden;
  color: #fff8e8;
  font-family: Georgia, "Times New Roman", serif;
  background: #0c0812 url("../../assets/background/magic-library-background.png") center / cover fixed no-repeat;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  content: "";
  background: linear-gradient(90deg, rgba(5, 3, 10, .82), rgba(5, 3, 10, .28) 50%, rgba(5, 3, 10, .82)), linear-gradient(180deg, rgba(5, 3, 10, .2), rgba(5, 3, 10, .66));
}

button,
input {
  font: inherit;
}

.magic-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.ambient-light {
  position: fixed;
  z-index: 0;
  width: 38vw;
  aspect-ratio: 1;
  border-radius: 50%;
  opacity: .3;
  filter: blur(80px);
  pointer-events: none;
  mix-blend-mode: screen;
  animation: drift 12s ease-in-out infinite alternate;
}

.ambient-light-one {
  top: -18vw;
  left: 18vw;
  background: #4f7cff;
}

.ambient-light-two {
  right: 10vw;
  bottom: -24vw;
  background: #8b43e8;
  animation-delay: -5s;
}

@keyframes drift {
  to {
    transform: translate3d(5vw, 3vh, 0) scale(1.18);
  }
}

.page {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(110px, 160px) minmax(500px, 1000px) minmax(110px, 160px);
  gap: clamp(16px, 2vw, 34px);
  align-items: start;
  justify-content: center;
  min-height: 100vh;
  padding: 28px clamp(18px, 3vw, 50px);
}

.ad-space {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 600px;
  margin-top: 12vh;
  border: 1px solid rgba(244, 212, 136, .2);
  border-radius: 16px;
  color: rgba(255, 241, 189, .48);
  font: .68rem Arial, sans-serif;
  letter-spacing: .18em;
  text-transform: uppercase;
  background: rgba(8, 5, 14, .3);
  backdrop-filter: blur(2px);
}

main {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  min-height: calc(100vh - 56px);
  padding: clamp(30px, 5vw, 56px) clamp(18px, 5vw, 60px);
  text-align: center;
  border: 1px solid rgba(255, 225, 151, .38);
  border-radius: 32px;
  background: radial-gradient(circle at 50% 8%, rgba(91, 58, 151, .4), transparent 34%), rgba(10, 6, 17, .8);
  box-shadow: 0 28px 80px rgba(0, 0, 0, .58), inset 0 0 60px rgba(131, 92, 211, .1);
  backdrop-filter: blur(8px);
}

.home-link {
  color: inherit;
  text-decoration: none;
}

h1 {
  margin: 0;
  color: var(--gold-light);
  font-size: clamp(3.6rem, 9vw, 6.2rem);
  font-style: italic;
  font-weight: 600;
  line-height: .9;
  letter-spacing: -.07em;
  text-shadow: 0 3px 0 #5c3c17, 0 0 18px rgba(255, 216, 113, .72), 0 0 50px rgba(123, 83, 215, .7);
  transform: skewX(-7deg);
}

main > h2 {
  margin: 26px 0 6px;
  color: var(--gold);
  font-size: clamp(1.7rem, 4vw, 2.7rem);
}

.tagline {
  margin: 0;
  color: rgba(255, 248, 232, .78);
  font-size: clamp(.92rem, 2vw, 1.08rem);
}

.how-to-button {
  min-height: 44px;
  margin-top: 20px;
  padding: 0 20px;
  border: 1px solid rgba(255, 225, 151, .58);
  border-radius: 11px;
  color: #1c1026;
  font-weight: 700;
  cursor: pointer;
  background: linear-gradient(180deg, #ffe9a8, #d7a94c);
  box-shadow: 0 4px 0 #6d481b, 0 8px 16px rgba(0, 0, 0, .3);
}

.how-to-button:hover,
.how-to-button:focus-visible {
  filter: brightness(1.1);
  outline: none;
  transform: translateY(-2px);
}

.date-picker {
  display: grid;
  grid-template-columns: 46px minmax(190px, 1fr) 46px;
  gap: 10px;
  align-items: center;
  width: min(390px, 100%);
  margin: 30px 0 22px;
}

.date-picker time {
  color: var(--gold-light);
  font: 700 .92rem Arial, sans-serif;
  text-transform: capitalize;
}

.date-arrow {
  width: 46px;
  height: 42px;
  border: 1px solid rgba(255, 225, 151, .55);
  border-radius: 10px;
  color: #1c1026;
  font-size: 1.7rem;
  line-height: 1;
  cursor: pointer;
  background: linear-gradient(180deg, #ffe9a8, #d7a94c);
  box-shadow: 0 4px 0 #6d481b;
}

.date-arrow:disabled {
  opacity: .28;
  cursor: not-allowed;
  filter: grayscale(.65);
}

.guess-form {
  width: min(650px, 100%);
}

.guess-form label {
  display: block;
  margin-bottom: 9px;
  color: var(--gold-light);
  font-size: .76rem;
  font-weight: 700;
  letter-spacing: .13em;
  text-transform: uppercase;
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.input-row input {
  min-width: 0;
  height: 54px;
  padding: 0 17px;
  border: 1px solid rgba(255, 225, 151, .55);
  border-radius: 12px;
  outline: none;
  color: #fff8e8;
  font-size: 1.08rem;
  background: rgba(5, 3, 10, .72);
  box-shadow: inset 0 0 20px rgba(124, 76, 196, .13);
}

.input-row input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 18px rgba(244, 212, 136, .2), inset 0 0 20px rgba(124, 76, 196, .15);
}

.input-row button,
.share-button {
  display: grid;
  place-items: center;
  min-height: 54px;
  padding: 0 20px;
  border: 1px solid rgba(255, 225, 151, .58);
  border-radius: 12px;
  color: #1c1026;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  background: linear-gradient(180deg, #ffe9a8, #d7a94c);
  box-shadow: 0 5px 0 #6d481b, 0 9px 18px rgba(0, 0, 0, .3);
}

.input-row button:disabled,
.input-row input:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.message {
  min-height: 20px;
  margin: 10px 0 0;
  color: #ffd88f;
  font: .8rem Arial, sans-serif;
}

.history-section {
  width: min(650px, 100%);
  margin-top: 12px;
}

.history-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.history-heading h3 {
  margin: 0;
  color: var(--gold-light);
  font-size: 1rem;
}

.history-heading span {
  color: rgba(255, 248, 232, .58);
  font: .72rem Arial, sans-serif;
}

.history {
  display: grid;
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
}

.guess-result {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 48px;
  padding: 8px 12px 8px 16px;
  border: 1px solid hsla(var(--hint-hue), 72%, 60%, .58);
  border-radius: 11px;
  text-align: left;
  background: linear-gradient(90deg, hsla(var(--hint-hue), 72%, 38%, .38), rgba(8, 5, 14, .68));
  box-shadow: inset 4px 0 0 hsl(var(--hint-hue), 72%, 54%);
}

.guess-word {
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.guess-hint {
  display: flex;
  gap: 7px;
  align-items: center;
  min-width: 66px;
  justify-content: flex-end;
  color: hsl(var(--hint-hue), 82%, 68%);
  font: 800 .92rem Arial, sans-serif;
}

.guess-hint strong {
  font-size: 1.25rem;
}

.keyboard {
  display: grid;
  grid-template-columns: repeat(20, minmax(0, 1fr));
  gap: clamp(3px, .7vw, 7px);
  width: min(720px, 100%);
  margin-top: 28px;
}

.key {
  grid-column: span 2;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  background: transparent;
  filter: drop-shadow(0 4px 3px rgba(0, 0, 0, .48));
  transition: transform .12s ease, filter .12s ease;
}

.key.special-key {
  grid-column: span 2;
}

.key:nth-child(21) {
  grid-column: 3 / span 2;
}

.key img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
}

.key:hover,
.key:focus-visible {
  outline: none;
  filter: brightness(1.13) drop-shadow(0 5px 5px rgba(0, 0, 0, .5));
  transform: translateY(-2px);
}

.key:active {
  transform: translateY(2px);
}

.key:disabled {
  opacity: .48;
  cursor: not-allowed;
  filter: grayscale(.4);
}

.footer-links {
  display: flex;
  gap: 8px 22px;
  justify-content: center;
  margin-top: 34px;
}

.footer-links a {
  padding: 3px 0;
  border-bottom: 1px solid transparent;
  color: rgba(255, 241, 189, .68);
  font: .74rem Arial, sans-serif;
  letter-spacing: .08em;
  text-decoration: none;
}

.footer-links a:hover,
.footer-links a:focus-visible {
  border-color: var(--gold);
  color: var(--gold-light);
  outline: none;
}

.victory-dialog,
.rules-dialog {
  width: min(440px, calc(100% - 28px));
  padding: 34px 28px 30px;
  border: 1px solid rgba(255, 225, 151, .65);
  border-radius: 24px;
  color: #fff8e8;
  text-align: center;
  background: radial-gradient(circle at 50% 0, rgba(104, 65, 171, .58), transparent 54%), #100919;
  box-shadow: 0 28px 80px rgba(0, 0, 0, .7), inset 0 0 35px rgba(139, 92, 218, .13);
}

.victory-dialog::backdrop,
.rules-dialog::backdrop {
  background: rgba(4, 2, 8, .78);
  backdrop-filter: blur(5px);
}

.rules-dialog {
  width: min(610px, calc(100% - 28px));
  max-height: calc(100vh - 28px);
  overflow-y: auto;
  text-align: left;
}

.rules-dialog h2 {
  margin: 0 0 9px;
  color: var(--gold-light);
  font-size: 2rem;
  text-align: center;
}

.rules-dialog h3 {
  margin: 24px 0 12px;
  color: var(--gold-light);
  font-size: 1.1rem;
}

.rules-intro {
  margin: 0 0 18px;
  color: rgba(255, 248, 232, .78);
  text-align: center;
}

.lemma-definition {
  margin: 0 0 18px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 225, 151, .3);
  border-radius: 10px;
  color: rgba(255, 248, 232, .76);
  font: .8rem/1.55 Arial, sans-serif;
  background: rgba(8, 5, 14, .52);
}

.lemma-definition strong {
  display: block;
  margin-bottom: 4px;
  color: var(--gold-light);
  font-family: Georgia, "Times New Roman", serif;
  font-size: .92rem;
}

.rules-dialog ol {
  margin: 0;
  padding-left: 24px;
  color: rgba(255, 248, 232, .8);
  font: .88rem/1.65 Arial, sans-serif;
}

.rule-example {
  margin-top: 10px;
  padding: 12px 14px;
  border: 1px solid hsla(var(--example-hue), 72%, 60%, .6);
  border-radius: 11px;
  background: linear-gradient(90deg, hsla(var(--example-hue), 72%, 38%, .36), rgba(8, 5, 14, .7));
  box-shadow: inset 4px 0 0 hsl(var(--example-hue), 72%, 54%);
}

.rule-example > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.rule-example span {
  color: hsl(var(--example-hue), 82%, 70%);
  font: 800 .9rem Arial, sans-serif;
}

.rule-example span b {
  margin-right: 5px;
  font-size: 1.2rem;
}

.rule-example p {
  margin: 7px 0 0;
  color: rgba(255, 248, 232, .7);
  font: .76rem/1.45 Arial, sans-serif;
}

.far-example {
  --example-hue: 49;
}

.close-example {
  --example-hue: 105;
}

.found-example {
  --example-hue: 125;
}

.arrow-guide {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin-top: 14px;
}

.arrow-guide p {
  margin: 0;
  padding: 10px;
  border: 1px solid rgba(255, 225, 151, .25);
  border-radius: 9px;
  color: rgba(255, 248, 232, .76);
  font: .75rem/1.4 Arial, sans-serif;
  background: rgba(8, 5, 14, .55);
}

.arrow-guide strong {
  display: block;
  margin-bottom: 3px;
  color: var(--gold-light);
  font-size: 1.25rem;
}

.rules-note {
  margin: 18px 0 0;
  color: rgba(255, 241, 189, .7);
  font: .76rem/1.5 Arial, sans-serif;
}

.rules-note + .rules-note {
  margin-top: 7px;
}

.dialog-close {
  position: absolute;
  top: 12px;
  right: 15px;
  padding: 0;
  border: 0;
  color: rgba(255, 248, 232, .7);
  font-size: 1.65rem;
  cursor: pointer;
  background: transparent;
}

.victory-symbol {
  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  margin: 0 auto 15px;
  border: 2px solid #8de278;
  border-radius: 50%;
  color: #a7f38c;
  font: 800 2.2rem Arial, sans-serif;
  background: rgba(72, 157, 61, .22);
  box-shadow: 0 0 28px rgba(94, 219, 84, .32);
}

.victory-dialog h2 {
  margin: 0 0 10px;
  color: var(--gold-light);
  font-size: 2rem;
}

.victory-dialog p {
  margin: 0 0 24px;
  line-height: 1.55;
}

.share-button {
  width: min(240px, 100%);
  margin: 0 auto;
}

.share-button[hidden] {
  display: none;
}

.master-grid {
  display: grid;
  gap: 7px;
  width: min(650px, 100%);
  margin-top: 14px;
}

.master-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  min-height: 54px;
  padding: 5px 8px;
  border: 1px solid rgba(255, 225, 151, .16);
  border-radius: 11px;
  background: rgba(6, 4, 11, .42);
}

.tile-word,
.rules-word,
.revealed-word {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: clamp(3px, .8vw, 7px);
  min-width: 0;
}

.letter-tile {
  display: block;
  width: 100%;
  max-width: 54px;
  aspect-ratio: 1;
  object-fit: contain;
  filter: drop-shadow(0 3px 3px rgba(0, 0, 0, .48));
}

.score-box {
  display: flex;
  gap: 4px;
  align-items: center;
}

.score-tile {
  width: clamp(36px, 6vw, 48px);
  aspect-ratio: 1;
  object-fit: contain;
  filter: drop-shadow(0 3px 3px rgba(0, 0, 0, .42));
}

.counter-rule {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 13px;
  align-items: center;
  margin-top: 10px;
  padding: 11px 13px;
  border: 1px solid rgba(255, 225, 151, .22);
  border-radius: 11px;
  background: rgba(8, 5, 14, .55);
}

.counter-rule img {
  width: 58px;
}

.counter-rule p {
  margin: 0;
  color: rgba(255, 248, 232, .72);
  font: .78rem/1.45 Arial, sans-serif;
}

.counter-rule strong {
  display: block;
  margin-bottom: 3px;
  color: var(--gold-light);
  font-family: Georgia, "Times New Roman", serif;
  font-size: .94rem;
}

.rules-word {
  width: min(300px, 100%);
  margin: 10px auto;
}

.example-secret,
.rules-text {
  color: rgba(255, 248, 232, .75);
  font: .8rem/1.55 Arial, sans-serif;
}

.example-result {
  display: flex;
  gap: 18px;
  justify-content: center;
  color: var(--gold-light);
  font: 800 .9rem Arial, sans-serif;
}

.example-details {
  margin: 10px 0 0;
  padding-left: 22px;
  color: rgba(255, 248, 232, .72);
  font: .78rem/1.55 Arial, sans-serif;
}

.result-dialog {
  width: min(460px, calc(100% - 28px));
  padding: 34px 28px 30px;
  border: 1px solid rgba(255, 225, 151, .65);
  border-radius: 24px;
  color: #fff8e8;
  text-align: center;
  background: radial-gradient(circle at 50% 0, rgba(104, 65, 171, .58), transparent 54%), #100919;
  box-shadow: 0 28px 80px rgba(0, 0, 0, .7), inset 0 0 35px rgba(139, 92, 218, .13);
}

.result-dialog::backdrop {
  background: rgba(4, 2, 8, .78);
  backdrop-filter: blur(5px);
}

.result-symbol {
  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  margin: 0 auto 15px;
  border: 2px solid var(--result-color, #8de278);
  border-radius: 50%;
  color: var(--result-color, #a7f38c);
  font: 800 2rem Arial, sans-serif;
  background: rgba(72, 157, 61, .18);
  box-shadow: 0 0 28px color-mix(in srgb, var(--result-color, #8de278) 38%, transparent);
}

.result-dialog h2 {
  margin: 0 0 10px;
  color: var(--gold-light);
  font-size: 2rem;
}

.result-dialog p {
  margin: 0 0 20px;
  line-height: 1.5;
}

.language-switcher {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 10;
  width: 46px;
}

.language-switcher summary {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 1px solid rgba(255, 225, 151, .55);
  border-radius: 50%;
  cursor: pointer;
  list-style: none;
  background: rgba(12, 8, 20, .88);
  box-shadow: 0 7px 18px rgba(0, 0, 0, .38);
}

.language-switcher summary::-webkit-details-marker {
  display: none;
}

.language-switcher nav {
  position: absolute;
  top: 100%;
  right: 0;
  display: grid;
  min-width: 145px;
  margin-top: 8px;
  overflow: hidden;
  border: 1px solid rgba(255, 225, 151, .42);
  border-radius: 12px;
  background: rgba(10, 6, 17, .96);
  box-shadow: 0 12px 30px rgba(0, 0, 0, .5);
}

.language-switcher a {
  padding: 10px 14px;
  color: var(--gold-light);
  font: .78rem Arial, sans-serif;
  text-decoration: none;
}

.language-switcher a:hover,
.language-switcher a:focus-visible {
  outline: none;
  background: rgba(139, 92, 218, .25);
}

@media (max-width: 560px) {
  .master-row {
    grid-template-columns: minmax(0, 1fr) 44px 44px;
    gap: 5px;
    padding: 4px;
  }

  .score-tile {
    width: 42px;
  }

  .language-switcher {
    top: 12px;
    right: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ambient-light {
    animation: none;
  }

  .key {
    transition: none;
  }
}

@media (max-width: 1050px) {
  .page {
    grid-template-columns: minmax(0, 1fr);
  }

  .ad-space {
    display: none;
  }
}

@media (max-width: 560px) {
  .page {
    padding: 10px;
  }

  main {
    min-height: calc(100vh - 20px);
    padding: 28px 10px;
    border-radius: 22px;
  }

  .input-row {
    grid-template-columns: minmax(0, 1fr) 88px;
    gap: 7px;
  }

  .input-row button {
    padding: 0 10px;
    font-size: .82rem;
  }

  .date-picker {
    grid-template-columns: 42px minmax(0, 1fr) 42px;
  }

  .keyboard {
    gap: 2px;
  }

  .footer-links {
    gap: 8px 14px;
  }

  .rules-dialog {
    padding: 30px 16px 22px;
  }

  .arrow-guide {
    grid-template-columns: 1fr;
  }
}

body, input, button { font-family: Arial, sans-serif; }
.game-main, .rules-dialog, .result-dialog { direction: rtl; }
.rules-dialog { text-align: right; }
#guess-input { direction: rtl; text-align: right; }
.tile-word { direction: rtl; }
.master-grid { direction: rtl; }
.date-picker { direction: ltr; grid-template-columns: 46px minmax(0, 1fr) 46px; width: min(460px, 100%); }
#challenge-date { direction: rtl; }
.keyboard { display: flex; flex-direction: column; gap: clamp(3px, .7vw, 7px); }
.keyboard-row { display: flex; gap: clamp(3px, .7vw, 7px); justify-content: center; width: 100%; }
.keyboard-row .key { flex: 0 1 54px; width: min(7.2vw, 54px); }
.keyboard-row .special-key { flex-basis: 54px; }

h1 { font-family: Georgia, "Times New Roman", serif; direction: ltr; }

.page { grid-template-columns: minmax(0, 1120px); }
.ad-space { display: none; }
