@import url("./themes.css");
* {
  box-sizing: border-box;
}
html {
  min-height: 100%;
  background: var(--background, #202932);
  color: var(--text, #e4ebec);
  font:
    15px/1.5 system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}
body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
button,
select {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
button:disabled {
  opacity: 0.4;
  cursor: default;
}
button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--selection);
  outline-offset: 4px;
}
select {
  outline: none;
}
.settings-row select:focus-visible,
.theme-picker select:focus-visible {
  border-color: var(--green);
}
button,
svg,
img {
  -webkit-user-select: none;
  user-select: none;
}
h1,
h2,
h3,
p {
  margin: 0;
}
h1,
h2,
h3,
.brand {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 400;
}
h1 {
  font-size: clamp(28px, 4vw, 39px);
  letter-spacing: -1px;
}
h2 {
  font-size: 29px;
}
h3 {
  font-size: 23px;
}
p {
  color: var(--muted);
}
.app-header {
  min-height: 90px;
  max-width: 1280px;
  width: 100%;
  margin: auto;
  padding: 20px 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  color: var(--text);
  text-decoration: none;
  font-size: 28px;
  line-height: 1;
}
.brand img {
  width: 38px;
  height: 38px;
}

nav {
  display: flex;
  gap: 8px;
}
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--text);
}
.icon-button:hover {
  background: var(--hover);
}
.ui-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  color: var(--text);
}
main {
  flex: 1;
  width: 100%;
  margin: 0 auto;
}
.home {
  max-width: 1100px;
  margin: auto;
  padding: 22px 40px 48px;
}
.home-heading {
  display: flex;
  justify-content: space-between;
  align-items: end;
  margin-bottom: 28px;
  gap: 20px;
}
.home-heading p {
  margin-top: 8px;
}
.eyebrow {
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--green);
  margin-bottom: 10px;
}
.layouts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}
.layout-card {
  padding: 0;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 17px;
  overflow: hidden;
  background: var(--surface);
  color: var(--text);
  transition:
    transform 0.18s,
    border-color 0.18s;
}
.layout-card:hover {
  transform: translateY(-3px);
  border-color: var(--green);
}
.layout-preview {
  height: 170px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 45% 15%, #34444b, #19252b 85%);
  box-shadow: inset 0 0 40px #0002;
  position: relative;
}
.layout-preview svg {
  width: 74%;
  height: 80%;
  filter: drop-shadow(3px 7px 4px #0005);
  transform: rotate(-5deg);
}
.layout-info {
  padding: 17px 20px 19px;
}
.layout-info p {
  font-size: 12px;
  margin-top: 4px;
}
.layout-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.tile-count {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}
.resume {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 17px 20px;
  margin-bottom: 24px;
  border: 1px solid var(--green);
  border-radius: 12px;
  background: var(--hover);
}
.resume > div {
  flex: 1;
}
.resume small {
  display: block;
  color: var(--muted);
}
.play-shell {
  display: flex;
  flex-direction: column;
  padding: 12px 24px;
}
.game-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto 14px;
}
.game-heading {
  display: flex;
  align-items: center;
  gap: 16px;
}
.game-heading h1 {
  font-size: 26px;
  letter-spacing: -0.4px;
}
.game-stats {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  gap: 16px;
}
.table {
  --table-light: #304149;
  --table-dark: #121c24;
  position: relative;
  border: 1px solid #ffffff0b;
  border-radius: 24px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex: 1;
  padding: 26px 16px;
  overflow: auto;
  min-height: 350px;
  background:
    radial-gradient(ellipse at 42% 25%, #ffffff08, transparent 65%),
    radial-gradient(ellipse at 50% 25%, var(--table-light), var(--table-dark));
  box-shadow:
    inset 0 2px 7px #0004,
    0 1px 0 #ffffff08;
}
.table::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  opacity: 0.15;
  background: repeating-linear-gradient(
    115deg,
    #ffffff05 0,
    #ffffff05 1px,
    transparent 1px,
    transparent 5px
  );
}
[data-surface="walnut"] .table,
[data-surface="walnut"] .layout-preview {
  --table-light: #564334;
  --table-dark: #2b221f;
  background:
    radial-gradient(ellipse at 50% 15%, #ffffff08, transparent),
    repeating-linear-gradient(
      92deg,
      #ffffff02 0,
      #ffffff02 2px,
      #00000004 3px,
      transparent 7px
    ),
    linear-gradient(
      100deg,
      var(--table-dark),
      var(--table-light),
      var(--table-dark)
    );
}
[data-surface="frost"] .table,
[data-surface="frost"] .layout-preview {
  background:
    radial-gradient(ellipse at 20% 10%, #77939966, transparent 60%),
    linear-gradient(130deg, #344e58, #24383d 70%, #466163);
}
.board {
  position: relative;
  /* Keep tile depth below the page-level match animation. */
  isolation: isolate;
  flex-shrink: 0;
  margin: auto;
  touch-action: pan-x pan-y;
}
.tile {
  position: absolute;
  padding: 0;
  border: 0;
  border-radius: 7%;
  background: transparent;
  isolation: isolate;
  touch-action: manipulation;
  transition: transform 0.16s ease-out;
}
/* Extrude the same rounded outline along one axis. The jade is a thin
   material layer around both visible walls, rather than a horizontal gradient. */
.tile::before,
.tile::after {
  content: "";
  position: absolute;
  inset: 0 var(--tile-side, 5px) var(--tile-foot, 9px) 0;
  border-radius: 7%;
  pointer-events: none;
}
.tile::before {
  background: #496c5d;
  transform: translate(var(--tile-side, 5px), var(--tile-foot, 9px));
  box-shadow:
    calc(var(--tile-side, 5px) * -0.16) calc(var(--tile-foot, 9px) * -0.16) 0
      #567764,
    calc(var(--tile-side, 5px) * -0.32) calc(var(--tile-foot, 9px) * -0.32) 0
      #567764,
    var(--contact-x, calc(var(--tile-detail, 1px) * 2))
      var(--contact-y, calc(var(--tile-detail, 1px) * 3))
      var(--contact-blur, var(--tile-shadow, 5px)) #0008;
}
.tile::after {
  background: linear-gradient(110deg, #c7bfa6, #b4aa8d);
  transform: translate(
    calc(var(--tile-side, 5px) * 0.64),
    calc(var(--tile-foot, 9px) * 0.64)
  );
  box-shadow:
    calc(var(--tile-side, 5px) * -0.2) calc(var(--tile-foot, 9px) * -0.2) 0
      #c7bfa6,
    calc(var(--tile-side, 5px) * -0.4) calc(var(--tile-foot, 9px) * -0.4) 0
      #d2c9ae,
    calc(var(--tile-side, 5px) * -0.64) calc(var(--tile-foot, 9px) * -0.64) 0
      #d2c9ae;
}

.tile-face {
  position: absolute;
  z-index: 1;
  inset: 0 var(--tile-side, 5px) var(--tile-foot, 9px) 0;
  border: 0;
  border-radius: 7% 7% 8% 7%;
  background: linear-gradient(115deg, #fffbed, #ece6d4 75%, #ddd7c3);
  box-shadow:
    inset 0 0 0 var(--tile-detail, 1px) #fff9,
    inset var(--tile-detail, 1px) var(--tile-detail, 1px) 0 #fff,
    inset calc(var(--tile-detail, 1px) * -2) calc(var(--tile-detail, 1px) * -3)
      calc(var(--tile-detail, 1px) * 3) #98897155,
    var(--tile-detail, 1px) var(--tile-detail, 1px) 0 #b3a98d;
  display: grid;
  place-items: center;
  transition:
    transform 0.15s,
    box-shadow 0.15s;
}
.tile svg {
  width: 87%;
  height: 93%;
  pointer-events: none;
}
.tile.blocked .tile-face {
  background: linear-gradient(115deg, #f0edde, #e3ddca);
}
.tile.blocked svg {
  opacity: 0.9;
}
.tile:not(.blocked):not(.selected):hover .tile-face {
  box-shadow:
    inset 0 0 0 calc(var(--tile-detail, 1px) * 2) #fff7,
    0 0 calc(var(--tile-detail, 1px) * 10) #e2e8bd33;
}
.tile.selected {
  /* Raise face, ivory walls and jade base together along the stack's axis. */
  transform: translate(
      calc(var(--tile-side, 5px) * -0.8),
      calc(var(--tile-foot, 9px) * -0.8)
    )
    scale(1.035);
  --contact-x: calc(var(--tile-side, 5px) * 1.4);
  --contact-y: calc(var(--tile-foot, 9px) * 1.4);
  --contact-blur: calc(var(--tile-foot, 9px) * 1.1);
}
.tile.hinted .tile-face {
  box-shadow:
    inset 0 0 0 calc(var(--tile-detail, 1px) * 3) #be8b28,
    0 0 0 calc(var(--tile-detail, 1px) * 2) #f6d28b;
}
.tile:focus-visible {
  outline-offset: 2px;
}
.game-bottom {
  max-width: 1180px;
  width: 100%;
  margin: 17px auto 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
}
.game-bottom p {
  font-size: 12px;
}
.game-tools {
  display: flex;
  gap: 8px;
}
.game-message {
  max-width: 550px;
}
.win-panel {
  text-align: center;
  padding: 50px 24px;
}
.win-panel h2 {
  font-size: 42px;
  color: #f1eddb;
  margin-bottom: 10px;
}
.win-panel p {
  color: #bacac6;
  margin-bottom: 24px;
}
.match-effects {
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
}
.flying {
  pointer-events: none;
  box-shadow: 3px 12px 15px #0005;
}
.collision {
  position: fixed;
  z-index: 2;
  width: 1px;
  height: 1px;
}
.collision i {
  position: absolute;
  background: #ffe4a0;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  box-shadow: 0 0 10px #fff3bc;
}
dialog {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 20px;
  padding: 32px;
  max-width: min(480px, calc(100vw - 32px));
  width: 100%;
  max-height: 85dvh;
  box-shadow: 0 22px 80px #0007;
}
dialog::backdrop {
  background: var(--overlay);
  backdrop-filter: blur(5px);
}
dialog h2 {
  padding-right: 30px;
  margin-bottom: 16px;
}
.dialog-copy {
  margin-bottom: 20px;
}
.dialog-close {
  position: absolute;
  right: 16px;
  top: 16px;
  border: 0;
  font-size: 28px;
}
.dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 24px;
  flex-wrap: wrap;
}
.settings-row,
.theme-picker {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.settings-row select {
  max-width: 55%;
  background: var(--background);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
}
.settings-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--green);
}
.help-copy p + p {
  margin-top: 16px;
}
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translate(-50%, 15px);
  opacity: 0;
  pointer-events: none;
  max-width: min(500px, calc(100vw - 32px));
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 10px 30px #0004;
  border-radius: 12px;
  padding: 14px 20px;
  z-index: 200;
  transition: 0.2s;
  font-size: 14px;
}
.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}
[hidden] {
  display: none !important;
}
@media (max-width: 700px) {
  .app-header {
    padding: 16px 20px;
    min-height: 78px;
  }
  .home {
    padding: 15px 20px 30px;
  }
  .home-heading {
    margin-bottom: 22px;
  }
  .home-heading > .eyebrow {
    display: none;
  }
  .layouts {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
  .layout-preview {
    height: 135px;
  }
  .layout-info {
    padding: 12px;
  }
  .layout-title {
    display: block;
  }
  .layout-title h3 {
    font-size: 21px;
  }
  .layout-info p {
    font-size: 11px;
  }
  .tile-count {
    font-size: 10px;
  }
  .play-shell {
    padding: 10px;
  }
  .game-top {
    padding: 0 6px;
  }
  .game-heading {
    gap: 9px;
  }
  .game-heading h1 {
    font-size: 22px;
  }
  .game-stats {
    display: block;
    font-size: 11px;
    text-align: right;
  }
  .game-stats span {
    display: block;
  }
  .table {
    border-radius: 16px;
    padding: 22px 8px;
    min-height: 320px;
  }
  .game-bottom {
    flex-direction: column-reverse;
    gap: 10px;
    margin-top: 12px;
  }
  .game-bottom p {
    text-align: center;
    font-size: 11px;
  }
  .game-tools {
    justify-content: center;
  }
  .game-tools .button {
    padding: 10px 14px;
  }
  .resume {
    padding: 13px;
    gap: 10px;
  }
  .resume .button {
    padding: 10px;
  }
  .resume strong {
    font-size: 14px;
  }
  dialog {
    padding: 26px;
  }
  .home-heading p {
    font-size: 13px;
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
  }
}

/* Game screens fit the live viewport; home and dialogs keep natural scrolling. */
body {
  -webkit-user-select: none;
  user-select: none;
}
input,
textarea,
[contenteditable="true"] {
  -webkit-user-select: text;
  user-select: text;
}
body[data-screen="game"] {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}
body[data-screen="game"] main {
  flex: 1;
  min-height: 0;
  display: flex;
}
body[data-screen="game"] .play-shell {
  flex: 1;
  min-height: 0;
}
body[data-screen="game"] .table {
  min-height: 0;
  padding: 0;
  /* Clip the camera without creating a native focus-scroll container. */
  overflow: clip;
  touch-action: none;
  cursor: grab;
}
.table.panning {
  cursor: grabbing;
}
.board-camera {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
}
.board {
  margin: 0;
  touch-action: none;
}
.tile {
  touch-action: none;
}
.win-panel {
  position: relative;
  z-index: 1;
  margin: auto;
}
@media (max-height: 500px) {
  body[data-screen="game"] .game-top {
    margin-bottom: 6px;
  }
  body[data-screen="game"] .game-bottom {
    margin-top: 6px;
  }
}
body[data-screen="game"] .play-shell {
  min-width: 0;
}
.game-tools {
  flex-wrap: wrap;
}
@media (max-width: 380px) {
  .game-tools {
    gap: 5px;
  }
  .game-tools .button {
    padding: 10px;
    font-size: 12px;
  }
}

.game-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
}
.game-heading,
.game-heading h1 {
  min-width: 0;
}
.game-heading .icon-button {
  flex-shrink: 0;
}
.game-bottom {
  justify-content: flex-end;
}
[data-update]:not(:empty) {
  margin-top: 20px;
}
@media (max-width: 700px) {
  .game-top {
    gap: 8px;
  }
  .game-heading h1 {
    font-size: 20px;
    line-height: 1.15;
  }
}

@media (max-width: 700px) {
  .play-shell {
    padding-left: 0;
    padding-right: 0;
  }
  .game-top {
    padding-left: 12px;
    padding-right: 12px;
  }
  .game-bottom {
    padding-left: 10px;
    padding-right: 10px;
  }
  .table {
    border-left: 0;
    border-right: 0;
    border-radius: 0;
  }
  .table::before {
    border-radius: 0;
  }
}
.table.panning,
.table.panning .tile {
  cursor: grabbing;
}

/* Home follows the shared Jigsaw proportions; gameplay keeps its compact header. */
.app-header {
  min-height: 90px;
  border-bottom: 1px solid var(--line);
}
.brand {
  font:
    36px/1 Georgia,
    serif;
  letter-spacing: -1.5px;
  white-space: nowrap;
}
.brand img {
  width: 40px;
  height: 40px;
  display: block;
  flex-shrink: 0;
}
#header-actions,
.home-tools,
.home-preferences,
.language-picker {
  display: flex;
  align-items: center;
}
#header-actions {
  gap: 20px;
}
.home-tools,
.home-preferences {
  gap: 8px;
}
.language-choice {
  min-width: 32px;
  min-height: 44px;
  padding: 0 5px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}
.language-choice[aria-pressed="true"] {
  background: var(--selected);
  color: var(--green);
  font-weight: 700;
}
.install-note:empty {
  display: none;
}
@media (max-width: 1000px) {
  .app-header {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 12px 8px;
    padding: 16px 20px;
  }
  #header-actions {
    display: contents;
  }
  .home-preferences {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
  }
  .home-tools {
    grid-column: 1 / -1;
    grid-row: 2;
    flex-wrap: wrap;
  }
  .home-tools > .icon-button {
    margin-left: auto;
  }
}
@media (max-width: 600px) {
  .app-header {
    padding: 12px;
  }
  .brand {
    font-size: 26px;
    gap: 5px;
    min-height: 44px;
  }
  .brand img {
    width: 26px;
    height: 26px;
  }
  .home-preferences .icon-button {
    width: 44px;
    height: 44px;
  }
}
@media (max-width: 360px) {
  .brand {
    font-size: 22px;
  }
  .brand img {
    width: 24px;
    height: 24px;
  }
}
.app-header .theme-picker {
  width: auto;
  padding: 0;
  border: 0;
  gap: 8px;
}
.app-header .theme-picker select {
  min-height: 44px;
}
.app-header .icon-button {
  flex-shrink: 0;
}
.app-header #install {
  white-space: nowrap;
}
@media (max-width: 600px) {
  .app-header .theme-picker > span {
    display: none;
  }
  .app-header #install {
    padding: 10px 12px;
  }
}
@media (max-width: 600px) {
  .home-tools {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) 44px;
  }
  .app-header #install {
    white-space: normal;
    font-size: 12px;
    padding: 6px;
    min-height: 44px;
  }
  .app-header .theme-picker {
    min-width: 0;
  }
  .app-header .theme-picker select {
    width: 100%;
    min-width: 0;
  }
  .home-tools:has(#install[hidden]) {
    grid-template-columns: minmax(0, 1fr) 44px;
  }
}

/* Solitaire's collection caption, visible on home at every viewport size. */
.bottom-caption {
  font:
    italic 12px Georgia,
    serif;
  color: var(--muted);
  opacity: 0.65;
  text-align: center;
  flex-shrink: 0;
  margin: 0 12px max(4px, env(safe-area-inset-bottom));
}
.bottom-caption a {
  color: inherit;
  text-underline-offset: 3px;
  margin-left: 5px;
  display: inline-block;
  padding: 8px 0;
}
.bottom-caption a:hover {
  color: var(--text);
}
