: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; 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); }

main { position: relative; display: flex; flex-direction: column; align-items: center; width: 100%; min-height: calc(100vh - 56px); padding: clamp(30px, 5vw, 56px) clamp(14px, 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); }

.how-to-button, .date-arrow, .input-row button, .share-button { 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 { min-height: 44px; margin-top: 20px; padding: 0 20px; }
.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; font-size: 1.7rem; }
.date-arrow:disabled { opacity: .28; cursor: not-allowed; }

.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); }
.input-row button { min-height: 54px; padding: 0 20px; }
.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; }

.keyboard { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: clamp(3px, .7vw, 7px); width: min(560px, 100%); margin-top: 22px; }
.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:nth-child(11) { grid-column: 4 / span 2; }
.key:nth-child(12) { grid-column: 6 / span 2; }
.key img { display: block; width: 100%; aspect-ratio: 1; object-fit: contain; }
.key:hover:not(:disabled), .key:focus-visible { outline: none; filter: brightness(1.13) drop-shadow(0 5px 5px rgba(0, 0, 0, .5)); transform: translateY(-2px); }
.key:disabled { opacity: .48; cursor: not-allowed; }

.master-grid { display: grid; gap: 7px; width: min(650px, 100%); margin-top: 18px; }
.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); }
.number-code, .number-example { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: clamp(3px, .8vw, 7px); }
.number-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-tile { width: clamp(36px, 6vw, 48px); aspect-ratio: 1; object-fit: contain; filter: drop-shadow(0 3px 3px rgba(0, 0, 0, .42)); }

.footer-links { display: flex; gap: 8px 22px; justify-content: center; margin-top: 34px; }
.footer-links a { color: rgba(255, 241, 189, .68); font: .74rem Arial, sans-serif; letter-spacing: .08em; text-decoration: none; }
.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); }
.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); }
.language-switcher a { padding: 10px 14px; color: var(--gold-light); font: .78rem Arial, sans-serif; text-decoration: none; }

.rules-dialog, .result-dialog { width: min(610px, calc(100% - 28px)); max-height: calc(100vh - 28px); padding: 34px 28px 30px; overflow-y: auto; border: 1px solid rgba(255, 225, 151, .65); border-radius: 24px; color: #fff8e8; 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); }
.result-dialog { width: min(460px, calc(100% - 28px)); text-align: center; }
.rules-dialog::backdrop, .result-dialog::backdrop { background: rgba(4, 2, 8, .78); backdrop-filter: blur(5px); }
.dialog-close { position: absolute; top: 12px; right: 14px; border: 0; color: var(--gold-light); font-size: 1.6rem; cursor: pointer; background: transparent; }
.rules-dialog h2, .result-dialog h2 { margin: 0 0 10px; 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, .rules-text, .rules-note, .rules-dialog ol, .example-secret { color: rgba(255, 248, 232, .78); font: .84rem/1.6 Arial, sans-serif; }
.rules-intro { text-align: center; }
.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, .74); font: .78rem/1.45 Arial, sans-serif; }
.counter-rule strong { display: block; margin-bottom: 3px; color: var(--gold-light); font: 700 .94rem Georgia, serif; }
.number-example { width: min(300px, 100%); margin: 10px auto; }
.number-example img { width: 100%; }
.example-result { display: flex; gap: 18px; justify-content: center; color: var(--gold-light); font: 800 .9rem Arial, sans-serif; }
.result-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 2rem Arial, sans-serif; background: rgba(72, 157, 61, .18); }
.share-button { display: grid; place-items: center; width: min(240px, 100%); min-height: 52px; margin: 22px auto 0; text-decoration: none; }
.share-button[hidden] { display: 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 8px; border-radius: 22px; }
  .language-switcher { top: 12px; right: 12px; }
  .input-row { grid-template-columns: minmax(0, 1fr) 88px; gap: 7px; }
  .master-row { grid-template-columns: minmax(0, 1fr) 42px 42px; gap: 5px; padding: 4px; }
  .keyboard { gap: 2px; }
  .rules-dialog { padding: 30px 16px 22px; }
}
@media (prefers-reduced-motion: reduce) { .ambient-light { animation: none; } .key { transition: none; } }

body, input, button { font-family: Arial, sans-serif; }
.game-main, .rules-dialog, .result-dialog { direction: rtl; }
.rules-dialog { text-align: right; }
.date-picker { direction: ltr; grid-template-columns: 46px minmax(0, 1fr) 46px; width: min(460px, 100%); }
#challenge-date { direction: rtl; }

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

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