: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 {
  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, 4vw, 52px);
  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);
}

.gold-button,
.date-arrow,
.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 20px;
}

.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,
.action-key:disabled {
  opacity: .42;
  cursor: not-allowed;
}

.current-guess {
  width: min(480px, 100%);
}

.current-guess h3 {
  margin: 0 0 10px;
  color: var(--gold-light);
  font-size: .82rem;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.card-slots {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: clamp(5px, 1vw, 10px);
}

.card-slot {
  position: relative;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  border: 1px dashed rgba(255, 225, 151, .4);
  border-radius: 8px;
  background: rgba(5, 3, 10, .52);
}

.card-slot.locked {
  border-style: solid;
  border-color: rgba(119, 222, 127, .7);
  box-shadow: 0 0 16px rgba(83, 210, 95, .2);
}

.rules-proposal {
  width: min(360px, 100%);
  margin: 14px auto 10px;
}

.rules-proposal .card-slot {
  display: grid;
  place-items: center;
}

.rules-proposal .card-slot:not(.locked)::after {
  content: "?";
  color: rgba(255, 241, 189, .5);
  font: 700 1.5rem Georgia, serif;
}

.rules-proposal .card-slot.locked::after {
  position: absolute;
  right: 3px;
  bottom: 3px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  content: "✓";
  color: #10220f;
  font: 800 .72rem Arial, sans-serif;
  background: #8de278;
}

.proposal-explanation {
  margin-top: 8px;
}

.card-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 4px 4px rgba(0, 0, 0, .45));
}

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

.card-keyboard {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: clamp(4px, .7vw, 8px);
  width: min(860px, 100%);
  margin-top: 28px;
}

.card-key,
.action-key {
  min-width: 0;
  padding: 0;
  overflow: hidden;
  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;
}

.card-key {
  aspect-ratio: 2 / 3;
}

.card-key.selected {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.card-key:disabled {
  cursor: not-allowed;
}

.card-key:hover:not(:disabled),
.card-key:focus-visible,
.action-key:hover:not(:disabled),
.action-key:focus-visible {
  outline: none;
  filter: brightness(1.12) drop-shadow(0 6px 5px rgba(0, 0, 0, .55));
  transform: translateY(-2px);
}

.action-keys {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: min(150px, 45%);
  margin-top: 14px;
}

.action-key {
  aspect-ratio: 2 / 3;
}

.action-key img,
.card-key img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.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 {
  color: rgba(255, 248, 232, .78);
  font: .84rem/1.6 Arial, sans-serif;
}

.rules-intro {
  text-align: center;
}

.rule-card {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 14px;
  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);
}

.rule-card img {
  width: 50px;
}

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

.rule-card strong {
  display: block;
  margin-bottom: 3px;
  color: var(--gold-light);
  font: 700 .94rem Georgia, 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; }
  .card-keyboard { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; width: min(390px, 100%); }
  .rules-dialog { padding: 30px 16px 22px; }
}

@media (prefers-reduced-motion: reduce) {
  .ambient-light { animation: none; }
  .card-key, .action-key { transition: none; }
}

body, 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; }
