@import url("https://fonts.googleapis.com/css2?family=Inter:wght@100..900&display=swap");

:root {
  --rc-green-950: #0c2e27;
  --rc-green-900: #123d32;
  --rc-green-800: #18503f;
  --rc-green-700: #21664f;
  --rc-green-600: #2d7a5e;
  --rc-green-100: #dff0e7;
  --rc-green-50: #eef7f2;
  --rc-gold-700: #9c742a;
  --rc-gold-600: #b98b34;
  --rc-gold-500: #d1a347;
  --rc-gold-300: #ead19a;
  --rc-gold-100: #f8edcf;
  --rc-cream: #fbfaf6;
  --rc-paper: #ffffff;
  --rc-ink: #1e2b27;
  --rc-muted: #65736e;
  --rc-line: #dfe7e2;
  --rc-danger: #c9443b;
  --rc-info: #267a85;
  --rc-shadow: 0 20px 50px rgba(18, 61, 50, 0.09);
  --rc-shadow-soft: 0 10px 30px rgba(18, 61, 50, 0.07);
}

* { box-sizing: border-box; }

html {
  min-width: 320px;
  background: var(--rc-cream);
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 8% 6%, rgba(223, 240, 231, .92), transparent 30rem),
    radial-gradient(circle at 94% 18%, rgba(248, 237, 207, .78), transparent 28rem),
    var(--rc-cream);
  color: var(--rc-ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, select { font: inherit; }
button, select, .cp-cell { -webkit-tap-highlight-color: transparent; }

button:focus-visible,
select:focus-visible,
.cp-cell:focus-visible {
  outline: 3px solid rgba(209, 163, 71, .55);
  outline-offset: 3px;
}

.site-shell {
  width: min(1180px, calc(100% - 40px));
  margin-inline: auto;
}

.game-site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(12, 46, 39, .97);
  color: #fff;
  box-shadow: 0 1px 0 rgba(255,255,255,.08);
  backdrop-filter: blur(14px);
}

.header-inner {
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand,
.footer-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.5);
  border-radius: 50%;
  background: linear-gradient(145deg, rgba(255,255,255,.12), rgba(255,255,255,.03));
  color: #fff;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .04em;
}

.brand-copy {
  display: grid;
  gap: 2px;
  line-height: 1.1;
}
.brand-copy strong { font-size: 17px; letter-spacing: -.015em; }
.brand-copy small,
.header-kicker { color: rgba(255,255,255,.64); }
.brand-copy small { font-size: 10px; letter-spacing: .06em; text-transform: uppercase; }
.header-kicker { font-size: 13px; }

.game-page { padding: 48px 0 64px; }

.game-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 36px;
  padding: 34px 38px;
  border: 1px solid rgba(33,102,79,.12);
  border-radius: 28px;
  background: linear-gradient(120deg, rgba(223,240,231,.88), rgba(248,237,207,.72));
  box-shadow: var(--rc-shadow-soft);
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--rc-green-700);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .09em;
  text-transform: uppercase;
}
.eyebrow::before {
  width: 22px;
  height: 2px;
  border-radius: 999px;
  background: var(--rc-gold-500);
  content: "";
}

.game-hero h1 {
  margin: 8px 0;
  color: var(--rc-green-950);
  font-size: clamp(34px, 5vw, 58px);
  line-height: 1;
  letter-spacing: -.04em;
}
.game-hero p {
  max-width: 780px;
  margin: 0;
  color: var(--rc-muted);
  font-size: 16px;
}

.hero-symbol {
  width: 108px;
  height: 108px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(185,139,52,.2);
  border-radius: 30px;
  background: rgba(255,255,255,.76);
  color: var(--rc-green-900);
  box-shadow: var(--rc-shadow-soft);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 27px;
  font-weight: 700;
}

.game-panel {
  display: grid;
  grid-template-columns: minmax(260px, 1.1fr) minmax(270px, .9fr) minmax(330px, 1fr);
  align-items: end;
  gap: 18px;
  margin-top: 22px;
  padding: 22px;
  border: 1px solid var(--rc-line);
  border-radius: 22px;
  background: rgba(255,255,255,.92);
  box-shadow: var(--rc-shadow-soft);
}

.control-group { min-width: 0; }
.control-label {
  display: block;
  margin-bottom: 7px;
  color: var(--rc-green-950);
  font-size: 13px;
  font-weight: 800;
}
.control-group small {
  display: block;
  margin-top: 6px;
  color: var(--rc-muted);
  font-size: 12px;
}

.level-dropdown-button {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border: 1px solid #cad9d1;
  border-radius: 12px;
  background: #fff;
  color: var(--rc-ink);
  padding: 0 14px;
  text-align: left;
  transition: border-color .18s ease, box-shadow .18s ease;
}
.level-dropdown-button:hover,
.level-dropdown-button:focus {
  border-color: var(--rc-green-600);
  box-shadow: 0 0 0 4px rgba(45,122,94,.09);
}

.dropdown-menu.levels-menu {
  width: 100%;
  max-height: 300px;
  overflow-y: auto;
  border-color: var(--rc-line);
  border-radius: 12px;
  box-shadow: var(--rc-shadow-soft);
}
.dropdown-item { padding: 9px 14px; }
.dropdown-item:active,
.dropdown-item:hover { background: var(--rc-green-50); color: var(--rc-green-950); }

.button-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.game-actions { padding-bottom: 1px; }

.game-button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 0 16px;
  font-size: 14px;
  font-weight: 750;
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease, border-color .18s ease;
}
.game-button:hover { transform: translateY(-1px); }
.game-button:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.game-button-primary {
  background: var(--rc-green-700);
  border-color: var(--rc-green-700);
  color: #fff;
  box-shadow: 0 8px 18px rgba(33,102,79,.18);
}
.game-button-primary:hover { background: var(--rc-green-800); border-color: var(--rc-green-800); color: #fff; }

.game-button-secondary {
  background: var(--rc-gold-100);
  border-color: var(--rc-gold-300);
  color: #765215;
}
.game-button-secondary:hover { background: #f4e3b8; color: #68470f; }

.game-button-ghost {
  background: #fff;
  border-color: #d7e1dc;
  color: #586862;
}
.game-button-ghost:hover { border-color: #bdcbc4; color: var(--rc-green-950); }

#closeBtn {
  background: #c9362d;
  border-color: #b92f27;
  color: #fff;
  box-shadow: 0 8px 20px rgba(201, 54, 45, .24);
  animation: close-button-pulse 1.7s ease-in-out infinite;
}
#closeBtn:hover,
#closeBtn:focus-visible {
  background: #b72d25;
  border-color: #a82620;
  color: #fff;
  box-shadow: 0 10px 24px rgba(201, 54, 45, .34);
}
@keyframes close-button-pulse {
  0%, 100% {
    box-shadow: 0 8px 20px rgba(201, 54, 45, .22), 0 0 0 0 rgba(201, 54, 45, .22);
  }
  50% {
    box-shadow: 0 10px 24px rgba(201, 54, 45, .30), 0 0 0 6px rgba(201, 54, 45, .10);
  }
}

html.dedicated-game-window,
body.dedicated-game-window {
  min-height: 100%;
}
body.dedicated-game-window {
  min-height: 100dvh;
}
body.dedicated-game-window .game-site-header,
body.dedicated-game-window .game-site-footer {
  display: none !important;
}
body.dedicated-game-window .game-page {
  min-height: 100dvh;
  padding: 18px 0 28px;
}
body.dedicated-game-window .site-shell {
  width: min(1440px, calc(100% - 24px));
}
body.dedicated-game-window .game-hero {
  display: none !important;
}
body.dedicated-game-window .game-panel {
  margin-top: 0;
}

.btn-blink { animation: btn-blink 1s ease-in-out infinite; }
@keyframes btn-blink {
  0%, 100% { box-shadow: 0 0 0 rgba(209,163,71,0); transform: translateY(0); }
  50% { box-shadow: 0 0 0 5px rgba(209,163,71,.16); transform: translateY(-1px); }
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px;
}
.stat-card {
  min-height: 72px;
  display: grid;
  align-content: center;
  gap: 3px;
  padding: 12px 13px;
  border: 1px solid #dbe8e1;
  border-radius: 14px;
  background: var(--rc-green-50);
}
.stat-card span:first-child {
  color: var(--rc-muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.stat-card strong {
  color: var(--rc-green-950);
  font-size: 18px;
  line-height: 1.1;
}
.stat-card strong small { font-size: 10px; font-weight: 700; color: var(--rc-muted); }

.play-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.75fr) minmax(280px, .75fr);
  align-items: start;
  gap: 20px;
  margin-top: 22px;
}

.game-card {
  border: 1px solid var(--rc-line);
  border-radius: 22px;
  background: rgba(255,255,255,.94);
  box-shadow: var(--rc-shadow-soft);
}

.board-panel { padding: 24px; }
.panel-heading,
.source-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}
.panel-heading h2,
.source-heading h2 {
  margin: 6px 0 0;
  color: var(--rc-green-950);
  font-size: clamp(25px, 3.4vw, 36px);
  line-height: 1.05;
  letter-spacing: -.035em;
}

#boardStatus.badge {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 11px;
  font-weight: 750;
}
#boardStatus.bg-secondary { background: #edf2ef !important; border-color: #d7e1dc; color: #60706a; }
#boardStatus.bg-info { background: #e5f1f3 !important; border-color: #c7dde0; color: #23616a; }
#boardStatus.bg-warning { background: var(--rc-gold-100) !important; border-color: var(--rc-gold-300); color: #765215; }
#boardStatus.bg-success { background: var(--rc-green-100) !important; border-color: #c9e2d5; color: var(--rc-green-800); }
#boardStatus.bg-danger { background: #fae8e6 !important; border-color: #edc9c5; color: #983930; }
#boardStatus.bg-primary { background: var(--rc-green-700) !important; border-color: var(--rc-green-700); color: #fff; }

.board-frame {
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: 14px;
  border: 1px solid #d7e3dd;
  border-radius: 18px;
  background: linear-gradient(145deg, #f7fbf8, #fffaf0);
  overflow: hidden;
}

.cp-board {
  --grid-size: 10;
  display: grid;
  grid-template-columns: repeat(var(--grid-size), minmax(0, 1fr));
  grid-template-rows: repeat(var(--grid-size), minmax(0, 1fr));
  gap: clamp(2px, .42vw, 5px);
  width: 100%;
  height: 100%;
  user-select: none;
  touch-action: none;
}

.cp-cell {
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #c9d9d1;
  border-radius: clamp(4px, .55vw, 8px);
  background: #fff;
  color: var(--rc-green-950);
  font-size: clamp(.52rem, 1.25vw, 1rem);
  font-weight: 800;
  line-height: 1;
  transition: background .15s ease, transform .1s ease, border-color .15s ease, box-shadow .15s ease;
}
.cp-cell:hover {
  border-color: #9dbbad;
  background: var(--rc-green-50);
}
.cp-cell.cp-preview {
  background: var(--rc-gold-100);
  border-color: var(--rc-gold-500);
  color: #765215;
  box-shadow: inset 0 0 0 1px rgba(209,163,71,.18);
}
.cp-cell.cp-found {
  background: var(--rc-green-100);
  border-color: #6aa488;
  color: var(--rc-green-950);
  box-shadow: inset 0 0 0 1px rgba(45,122,94,.14);
}
.cp-cell.cp-error {
  background: #fae8e6;
  border-color: var(--rc-danger);
  color: #983930;
}

.board-placeholder {
  margin: 14px 0 0;
  color: var(--rc-muted);
  font-size: 13px;
  text-align: center;
}

.game-sidebar {
  display: grid;
  gap: 20px;
}
.sidebar-card { overflow: hidden; }
.sidebar-heading { padding: 18px 18px 12px; }
.sidebar-heading h3 {
  margin: 5px 0 0;
  color: var(--rc-green-950);
  font-size: 21px;
  letter-spacing: -.025em;
}

.word-list,
.history-list { margin: 0; }
.list-group-item {
  border: 0;
  border-top: 1px solid var(--rc-line);
  background: #fff;
  color: var(--rc-ink);
  padding: 11px 16px;
  font-size: 12px;
}
.list-group-item:first-child { border-top: 1px solid var(--rc-line); }
.list-group-item.word-found {
  background: var(--rc-green-50);
  color: var(--rc-green-800);
  font-weight: 700;
}
.list-group-item.text-muted { color: var(--rc-muted) !important; }
.list-group-item small { color: var(--rc-muted); }

.badge.bg-secondary {
  background: #edf2ef !important;
  color: #66736e;
}
.badge.bg-success {
  background: var(--rc-green-700) !important;
  color: #fff;
}
.badge.bg-amber {
  background: var(--rc-gold-100);
  border: 1px solid var(--rc-gold-300);
  color: #765215;
}

.source-card {
  margin-top: 20px;
  padding: 24px;
}
.source-heading p {
  max-width: 430px;
  margin: 0;
  color: var(--rc-muted);
  font-size: 12px;
  text-align: right;
}
.cp-source-text {
  padding: 18px;
  border: 1px solid var(--rc-line);
  border-radius: 16px;
  background: #fbfcfb;
  color: #485650;
  font-size: 14px;
  line-height: 1.75;
  white-space: pre-line;
}
.cp-source-text .word-target {
  border-radius: 5px;
  background: var(--rc-gold-100);
  color: #805a18;
  padding: 1px 3px;
  font-weight: 750;
}
.cp-source-text .word-target.word-found {
  background: var(--rc-green-100);
  color: var(--rc-green-800);
}

.game-site-footer {
  background: var(--rc-green-950);
  color: rgba(255,255,255,.72);
  border-top: 1px solid rgba(255,255,255,.05);
}
.footer-inner {
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 28px;
  font-size: 11px;
}
.brand-mark-footer {
  width: 36px;
  height: 36px;
  flex-basis: 36px;
  font-size: 14px;
}
.footer-brand div { display: grid; gap: 1px; }
.footer-brand strong { color: #fff; font-size: 13px; }
.footer-brand span { color: rgba(255,255,255,.58); font-size: 10px; }

@media (max-width: 980px) {
  .game-panel {
    grid-template-columns: 1fr 1fr;
  }
  .stats { grid-column: 1 / -1; }
  .play-layout { grid-template-columns: 1fr; }
  .game-sidebar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  .site-shell { width: min(100% - 28px, 1180px); }
  .header-inner { min-height: 72px; }
  .header-kicker { display: none; }
  .game-page { padding: 28px 0 42px; }

  .game-hero {
    grid-template-columns: 1fr;
    gap: 0;
    padding: 28px 26px;
    border-radius: 24px;
  }
  .game-hero h1 { font-size: clamp(36px, 12vw, 50px); }
  .game-hero p { font-size: 15px; }
  .hero-symbol { display: none; }

  .game-panel {
    grid-template-columns: 1fr;
    align-items: stretch;
    padding: 20px;
    border-radius: 22px;
  }
  .button-row { align-items: stretch; }
  .game-button { flex: 1 1 auto; }
  .stats { grid-column: auto; }

  .board-panel { padding: 16px; }
  .panel-heading,
  .source-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }
  .board-frame { padding: 7px; border-radius: 14px; }
  .cp-board { gap: 2px; }
  .cp-cell {
    border-radius: 4px;
    font-size: clamp(.48rem, 2.8vw, .72rem);
  }

  .game-sidebar { grid-template-columns: 1fr; }
  .source-card { padding: 18px; }
  .source-heading p { text-align: left; }

  .footer-inner {
    min-height: 150px;
    align-items: flex-start;
    flex-direction: column;
    justify-content: center;
    gap: 18px;
  }
}

@media (max-width: 420px) {
  .site-shell { width: calc(100% - 22px); }
  .brand-copy strong { font-size: 16px; }
  .game-panel { padding: 17px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat-card:last-child { grid-column: 1 / -1; }
  .board-panel { padding: 12px; }
  .board-frame { padding: 5px; }
  .cp-cell { font-size: clamp(.43rem, 2.55vw, .66rem); }
}
