:root {
  color-scheme: dark;
  --paper: #07110f;
  --surface: rgba(255, 250, 239, 0.9);
  --panel: rgba(11, 24, 21, 0.76);
  --panel-strong: rgba(17, 35, 31, 0.9);
  --ink: #f8efe1;
  --ink-dark: #18211f;
  --muted: #c6bba6;
  --line: rgba(236, 211, 161, 0.28);
  --line-strong: rgba(245, 219, 165, 0.5);
  --teal: #2fb7b1;
  --brick: #c65340;
  --gold: #dca94b;
  --green: #3d8f62;
  --violet: #6d5bd0;
  --shadow: 0 22px 54px rgba(0, 0, 0, 0.34);
  --glow: 0 0 0 1px rgba(245, 219, 165, 0.18), 0 20px 52px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  overflow: hidden;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
}

body::before {
  z-index: -2;
  background:
    linear-gradient(90deg, rgba(6, 13, 12, 0.95) 0%, rgba(6, 13, 12, 0.4) 34%, rgba(6, 13, 12, 0.48) 100%),
    linear-gradient(180deg, rgba(3, 7, 6, 0.52), rgba(3, 7, 6, 0.88)),
    url("images/table-lounge-bg.png") center / cover no-repeat;
}

body::after {
  z-index: -1;
  background:
    linear-gradient(180deg, rgba(245, 219, 165, 0.08), rgba(245, 219, 165, 0) 42%),
    linear-gradient(90deg, rgba(47, 183, 177, 0.12), rgba(198, 83, 64, 0.1));
  mix-blend-mode: screen;
  opacity: 0.62;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.appShell {
  min-height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  isolation: isolate;
}

.topbar {
  min-height: 72px;
  padding: 10px 22px;
  border-bottom: 1px solid rgba(245, 219, 165, 0.22);
  background: rgba(7, 17, 15, 0.78);
  backdrop-filter: blur(18px) saturate(130%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  min-width: max-content;
  color: var(--ink);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.brandMark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: inline-grid;
  place-items: center;
  background:
    linear-gradient(145deg, rgba(246, 215, 143, 0.96), rgba(150, 90, 42, 0.95));
  color: #17120c;
  font-size: 0.78rem;
  font-weight: 950;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.38), 0 12px 28px rgba(0, 0, 0, 0.36);
}

.brandText {
  display: grid;
  gap: 2px;
}

.brandText strong {
  font-size: 1rem;
  line-height: 1;
}

.brandText small {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
  line-height: 1;
}

.filters {
  min-width: 0;
  display: flex;
  gap: 8px;
  align-items: center;
  overflow-x: auto;
  scrollbar-width: none;
}

.filters::-webkit-scrollbar {
  display: none;
}

.filterButton,
.iconButton,
.overlayButton {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 239, 0.1);
  color: var(--ink);
}

.filterButton {
  min-height: 36px;
  padding: 0 14px;
  font-weight: 700;
  color: #efe1c8;
  white-space: nowrap;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.filterButton.isActive {
  border-color: rgba(247, 222, 166, 0.82);
  background: linear-gradient(145deg, rgba(246, 215, 143, 0.96), rgba(177, 103, 45, 0.96));
  color: #17120c;
  box-shadow: 0 10px 26px rgba(174, 112, 38, 0.25);
}

.layout {
  width: min(1440px, 100%);
  height: 100%;
  min-height: 0;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  gap: 22px;
  align-items: stretch;
  overflow: hidden;
}

.libraryPane {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(16, 35, 31, 0.92), rgba(8, 20, 18, 0.72));
  box-shadow: var(--glow);
  overflow: hidden;
}

.libraryHero {
  flex: 0 0 auto;
  padding: 4px 2px 14px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.libraryHeader {
  flex: 0 0 auto;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 0;
}

.libraryHeader h1 {
  margin: 0;
  font-size: 1.75rem;
  line-height: 1.1;
}

.libraryHeader span {
  min-width: 40px;
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid rgba(245, 219, 165, 0.3);
  border-radius: 8px;
  display: inline-grid;
  place-items: center;
  color: #fff6dd;
  background: rgba(255, 250, 239, 0.1);
  font-weight: 800;
}

.gameList {
  min-height: 0;
  flex: 1 1 auto;
  display: grid;
  gap: 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
  scrollbar-gutter: stable;
}

.gameList::-webkit-scrollbar,
.playPane::-webkit-scrollbar {
  width: 10px;
}

.gameList::-webkit-scrollbar-thumb,
.playPane::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 999px;
  background: rgba(245, 219, 165, 0.36);
  background-clip: padding-box;
}

.gameCard {
  width: 100%;
  text-align: left;
  border: 1px solid rgba(245, 219, 165, 0.24);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 250, 239, 0.14), rgba(255, 250, 239, 0.06));
  padding: 13px;
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  color: var(--ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.gameCard:hover,
.gameCard:focus-visible {
  border-color: rgba(47, 183, 177, 0.86);
  background:
    linear-gradient(135deg, rgba(47, 183, 177, 0.22), rgba(255, 250, 239, 0.08));
  box-shadow: 0 0 0 3px rgba(47, 183, 177, 0.18);
  outline: none;
}

.gameCard.isSelected {
  border-color: rgba(245, 219, 165, 0.76);
  background:
    linear-gradient(135deg, rgba(246, 215, 143, 0.24), rgba(198, 83, 64, 0.12));
  box-shadow: inset 4px 0 0 var(--gold), 0 14px 28px rgba(0, 0, 0, 0.22);
}

.thumb {
  width: 46px;
  height: 46px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #ffffff;
  font-weight: 900;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 8px 18px rgba(0, 0, 0, 0.28);
}

.gameCard h3 {
  margin: 0 0 4px;
  font-size: 0.98rem;
  line-height: 1.2;
}

.gameCard p {
  margin: 0;
  color: #d5cab6;
  font-size: 0.84rem;
  line-height: 1.35;
}

.gameMeta {
  display: grid;
  gap: 6px;
  justify-items: end;
  color: #cfbea1;
  font-size: 0.76rem;
  font-weight: 800;
}

.playPane {
  min-width: 0;
  min-height: 0;
  height: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 250, 239, 0.92), rgba(248, 239, 225, 0.86));
  color: var(--ink-dark);
  box-shadow: var(--shadow);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.playHeader {
  min-height: 86px;
  padding: 16px;
  border-bottom: 1px solid rgba(91, 72, 40, 0.18);
  background:
    linear-gradient(90deg, rgba(255, 250, 239, 0.96), rgba(238, 224, 194, 0.88));
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  backdrop-filter: blur(14px);
}

.gameTag {
  margin: 0 0 5px;
  color: var(--brick);
  font-weight: 900;
  font-size: 0.78rem;
}

.playHeader h2 {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1.12;
  color: var(--ink-dark);
}

.scoreStrip {
  display: grid;
  grid-template-columns: repeat(3, minmax(72px, 1fr));
  gap: 8px;
  min-width: 272px;
}

.scoreStrip div {
  border: 1px solid rgba(91, 72, 40, 0.16);
  border-radius: 8px;
  padding: 8px 10px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(248, 238, 218, 0.72));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.scoreStrip span {
  display: block;
  color: #716550;
  font-size: 0.72rem;
  font-weight: 800;
}

.scoreStrip strong {
  display: block;
  margin-top: 3px;
  font-size: 1.2rem;
  line-height: 1;
}

.stageWrap {
  position: relative;
  background:
    linear-gradient(135deg, #07110f, #101817 44%, #17110e);
  aspect-ratio: 3 / 2;
  width: 100%;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(245, 219, 165, 0.22), inset 0 0 60px rgba(0, 0, 0, 0.44);
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.overlayButton {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  min-width: 132px;
  min-height: 46px;
  padding: 0 22px;
  border-color: rgba(255, 255, 255, 0.58);
  background:
    linear-gradient(145deg, rgba(255, 247, 221, 0.98), rgba(228, 170, 76, 0.96));
  color: #19120b;
  font-weight: 900;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.25);
}

.overlayButton.isHidden {
  display: none;
}

.controlDock {
  min-height: 64px;
  padding: 12px 14px;
  border-top: 1px solid rgba(91, 72, 40, 0.18);
  background:
    linear-gradient(90deg, rgba(255, 250, 239, 0.94), rgba(239, 227, 201, 0.88));
  position: sticky;
  bottom: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: auto auto minmax(160px, 260px) minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  backdrop-filter: blur(14px);
}

.iconButton {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  font-size: 1.2rem;
  font-weight: 900;
  color: var(--ink-dark);
  background: rgba(255, 255, 255, 0.56);
}

.iconButton:hover,
.iconButton:focus-visible {
  border-color: var(--teal);
  outline: none;
}

.typingInput {
  width: 100%;
  height: 40px;
  border: 1px solid rgba(91, 72, 40, 0.22);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink-dark);
  background: rgba(255, 255, 255, 0.68);
}

.typingInput[hidden] {
  display: none;
}

.controlHint {
  color: #615747;
  font-size: 0.9rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.opsBar {
  min-height: 44px;
  padding: 0 22px;
  border-top: 1px solid rgba(245, 219, 165, 0.18);
  background: rgba(7, 17, 15, 0.72);
  backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

@media (max-width: 980px) {
  body {
    overflow: auto;
  }

  .appShell {
    height: auto;
  }

  .layout {
    grid-template-columns: 1fr;
    height: auto;
    min-height: auto;
    align-items: start;
    overflow: visible;
  }

  .libraryPane {
    order: 2;
    height: auto;
  }

  .playPane {
    order: 1;
    height: auto;
  }

  .gameList {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow: visible;
    padding-right: 0;
  }
}

@media (max-width: 720px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    padding: 10px 14px;
    overflow: hidden;
  }

  .brand {
    min-width: 0;
  }

  .filters {
    width: 100%;
  }

  .layout {
    padding: 14px;
  }

  .playHeader {
    align-items: stretch;
    flex-direction: column;
  }

  .scoreStrip {
    min-width: 0;
  }

  .gameList {
    grid-template-columns: 1fr;
  }

  .controlDock {
    grid-template-columns: auto auto minmax(0, 1fr);
  }

  .typingInput {
    grid-column: 1 / -1;
  }

  .controlHint {
    font-size: 0.82rem;
  }

  .opsBar {
    align-items: flex-start;
    flex-direction: column;
    justify-content: center;
    padding: 8px 14px;
  }
}
