:root {
  color-scheme: light;
  --ink: #183e3f;
  --muted: #56635c;
  --paper: #fbf8ef;
  --rule: #d3cbbb;
  --wine: #802d40;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font: 100%/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}
* { box-sizing: border-box; }
body, figure, h1, h2, p { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; text-underline-offset: .22em; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid #a54929; outline-offset: 4px; }
.masthead { background: #163e40; color: #fffaed; }
.mast-inner, .desk { width: min(calc(100% - 4rem), 65rem); margin-inline: auto; }
.mast-inner { display: flex; align-items: center; justify-content: space-between; min-height: 4.35rem; }
.brand { display: inline-flex; gap: .6rem; align-items: center; text-decoration: none; font: italic 600 1.7rem/1 var(--serif); letter-spacing: -.065em; }
.brand img { width: 2.05rem; height: 2.05rem; border-radius: .45rem; }
.site-links { display: flex; align-items: center; gap: 1rem; }
.site-links a { font-size: .9375rem; padding: .55rem 0; text-decoration-color: #c2ceba; }
.mast-inner :focus-visible { outline-color: #ffcd87; }
.desk { display: grid; grid-template-columns: minmax(0,.84fr) minmax(0,1.16fr); grid-template-areas: 'intro mat' 'controls mat'; align-content: center; column-gap: clamp(2.5rem,7vw,7rem); padding-block: clamp(1.8rem,4.25vw,3.8rem); }
.intro { grid-area: intro; align-self: end; }
.country, .caption-place { font-size: .8125rem; font-weight: 650; letter-spacing: .14em; text-transform: uppercase; }
.country { display: flex; align-items: center; gap: .55rem; color: var(--muted); margin-bottom: clamp(1rem,2.5vw,2.2rem); }
.flag { display: inline-block; width: 1.4rem; height: .9rem; border: 1px solid #23382a29; background: linear-gradient(to right,#3e765b 0 33.33%,#fff8ed 33.33% 66.66%,#ac5248 66.66%); }
h1 { font: 500 clamp(4.8rem,9vw,7.9rem)/.98 var(--serif); letter-spacing: -.065em; }
h1 span { display: block; margin-bottom: .2em; font: italic 400 clamp(1.7rem,3vw,2.6rem)/1.1 var(--serif); letter-spacing: -.035em; }
.directions, .result p { line-height: 1.6; font-size: 1.0625rem; color: var(--muted); }
.directions { margin-top: 1.25rem; max-width: 23rem; }
.workspace { grid-area: controls; width: 100%; align-self: start; margin-top: 1.85rem; }
progress { display: block; appearance: none; width: 100%; height: .28rem; border: 0; border-radius: 1rem; overflow: hidden; color: var(--wine); background: #e3ddce; margin: .85rem 0 1.3rem; }
progress::-webkit-progress-bar { background: #e3ddce; }
progress::-webkit-progress-value { background: var(--wine); }
progress::-moz-progress-bar { background: var(--wine); }
.mat { grid-area: mat; display: grid; place-items: center; position: relative; isolation: isolate; overflow: hidden; padding: clamp(1.2rem,3vw,2.55rem); background: radial-gradient(ellipse at 25% 5%,#386362,transparent 70%), #234b4b; border-radius: .55rem; }
.mat::before { content: ''; position: absolute; z-index: -1; inset: 0; opacity: .22; background-image: repeating-linear-gradient(0deg, transparent 0 3px,#78938a 3px 4px), repeating-linear-gradient(90deg,transparent 0 3px,#78938a 3px 4px); background-size: 4px 4px; pointer-events: none; }
.paper { position: relative; padding: clamp(.55rem,1.25vw,1.05rem); padding-bottom: .65rem; width: min(100%,clamp(18.75rem,47vh,25.5rem)); border: 1px solid #ede4d2; background: #fffaf0; box-shadow: .22rem .5rem .85rem #0a262854; }
.picture { position: relative; aspect-ratio: 2 / 3; background: #e0dbc9; }
#board { display: grid; position: absolute; inset: 0; grid-template: repeat(var(--side,3),minmax(0,1fr)) / repeat(var(--side,3),minmax(0,1fr)); gap: 2px; user-select: none; -webkit-user-select: none; }
.tile { position: relative; border: 0; border-radius: 0; padding: 0; appearance: none; background: var(--art, url('../../assets/postcard/venice.webp')) var(--tile-x) var(--tile-y) / var(--image-scale,300%) var(--image-scale,300%) no-repeat; touch-action: none; cursor: grab; -webkit-tap-highlight-color: transparent; }
.tile:focus-visible, .tile[data-target], .tile[data-selected] { z-index: 1; outline: 0; box-shadow: inset 0 0 0 3px #fff8dc, inset 0 0 0 6px var(--wine); }
.tile[data-dragging] { z-index: 2; pointer-events: none; transform: translate(var(--drag-x),var(--drag-y)) scale(1.025); cursor: grabbing; opacity: .86; box-shadow: 0 3px 12px #17251e8a; }
.finished-art { display: none; }
.is-complete .finished-art { display: block; width: 100%; height: 100%; }
.is-complete #board, .is-complete .directions { display: none; }
figcaption { display: flex; min-height: 2.35rem; gap: .5rem; align-items: end; justify-content: space-between; }
figcaption > :first-child { color: #444e43; font: italic 500 1.12rem/1.35 var(--serif); }
.caption-place { font-size: .75rem; font-weight: 550; text-transform: none; letter-spacing: .035em; color: #60675b; }
.postmark { display: none; }
.is-complete .postmark { display: block; position: absolute; right: -.4rem; bottom: 1.3rem; width: 38%; height: auto; transform: rotate(-9deg); filter: drop-shadow(0 0 2px #f4e7d9); pointer-events: none; }
.result { border-top: 1px solid var(--rule); padding-top: 1rem; }
.result h2 { font: 550 1.55rem/1.2 var(--serif); }
.result p { margin-top: .45rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (min-width: 1500px) { .desk { padding-block: 4rem; } }
@media (max-width: 710px) {
  .mast-inner, .desk { width: min(calc(100% - 2.25rem),32rem); }
  .mast-inner { min-height: 3.3rem; }
  .brand { font-size: 1.45rem; }
  .brand img { width: 1.75rem; height: 1.75rem; }
  .desk { grid-template-columns: minmax(0,1fr); grid-template-areas: 'intro' 'controls' 'mat'; padding-block: 1.4rem; }
  .country { margin-bottom: .35rem; }
  h1 { font-size: clamp(3rem,11vw,4.3rem); }
  h1 span { display: inline; font-size: .53em; }
  .directions { max-width: 100%; margin-top: .55rem; font-size: 1rem; }
  .mat { margin-top: .9rem; padding: .9rem; }
  .paper { width: min(100%,max(14rem,36svh)); padding: .5rem; }
  figcaption { min-height: 1.8rem; }
  .workspace { margin-top: .75rem; }
  progress { margin: .4rem 0 0; }
}
@media (max-width: 355px) { .desk, .mast-inner { width: calc(100% - 1.5rem); } }

.duel #board { gap: 0; }
.duel .tile[data-dragging] { transform: translate(var(--drag-x),var(--drag-y)); }
.is-error { display: block; }
.is-error .directions { max-width: 34rem; }


.connection-note { color: var(--muted); margin-bottom: .7rem; }
.is-loading .mat, .is-loading #play-panel { visibility: hidden; }
.is-loading .country, .is-error .country { display: none; }
.is-error h1, .is-loading h1 { font-size: clamp(2.4rem, 6vw, 4.5rem); }
.cloud-duel h1 { font-size: clamp(2.8rem, 6vw, 4.8rem); letter-spacing: -.04em; overflow-wrap: anywhere; }
.cloud-duel .paper { width: min(100%, 27rem); }
.cloud-duel .picture { aspect-ratio: var(--art-ratio, 2 / 3); }
.cloud-duel .finished-art { object-fit: fill; }
.cloud-duel .postmark { display: none; }
@media (max-width: 710px) {
  .cloud-duel .paper { width: min(100%, max(15rem, 49svh)); }
  .cloud-duel h1 { font-size: clamp(2rem, 8vw, 3rem); }
}

.retry { margin-top: .8rem; padding: .5rem 1rem; border: 1px solid var(--ink); border-radius: .3rem; background: transparent; }

/* Keep the gesture surface stable while its individual pieces move under the finger. */
#board { touch-action: none; -webkit-touch-callout: none; }
.tile[data-dragging] { pointer-events: none; }
.duel .tile[data-selected] { box-shadow: inset 0 0 0 2px #fff6d9, inset 0 0 0 4px #81384a; }
.duel .tile[data-target] { box-shadow: inset 0 0 0 3px #fce4a7; }
.preview-toggle { min-height: 42px; padding: 0 1em; border: 1px solid #79918a; border-radius: .4rem; background: var(--paper); font-weight: 600; }
.preview-toggle[aria-pressed="true"] { color: #fffaf0; background: var(--ink); }
.is-preview #board { visibility: hidden; }
.is-preview .finished-art { display: block; width: 100%; height: 100%; pointer-events: none; }
.move-feedback { grid-column: 1/-1; min-height: 1.3em; margin: .35rem 0; color: var(--muted); font-size: .85rem; }
.is-complete .move-feedback, .is-error .move-feedback, .is-loading .move-feedback { display: none; }
.mobile-links { display: none; }
@media (max-width: 710px) {
  .masthead { display: none; }
  .desk { width: min(calc(100% - 12px), 36rem); padding-block: max(.55rem,env(safe-area-inset-top)) .2rem;
    grid-template-areas: 'intro' 'controls' 'mat' 'feedback'; }
  .intro { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center;
    grid-template-areas: 'place preview' 'title preview' 'directions directions'; padding-inline: 6px; }
  .country { grid-area: place; margin: 0; font-size: .65rem; }
  .intro h1, .cloud-duel .intro h1 { grid-area: title; margin: 0; font-size: clamp(1.65rem,6.5vw,2.25rem); line-height: 1.1; }
  .intro h1 span { font-size: .65em; }
  .preview-toggle { grid-area: preview; font-size: .85rem; min-width: 72px; min-height: 44px; margin-left: .5rem; }
  .directions { grid-area: directions; margin-top: .28rem; font-size: .82rem; line-height: 1.25; }
  .workspace { width: auto; min-width: 0; margin: .55rem 6px 0; }
  progress { margin: .22rem 0 0; height: 3px; }
  .mat { margin-top: .38rem; padding: 2px; background: var(--ink); border-radius: .3rem; width: fit-content; max-width: 100%; justify-self: center; }
  .mat::before { display: none; }
  .paper, .cloud-duel .paper { width: min(calc(100vw - 16px), 35rem, max(19rem, calc((100svh - 157px) * var(--art-proportion,.66667))));
    padding: 2px; border: 0; box-shadow: none; }
  .picture { width: 100%; }
  figcaption { min-height: 20px; align-items: center; padding: 1px .22rem; }
  figcaption > :first-child { font-size: .82rem; line-height: 1.12; }
  .caption-place { font-size: .69rem; }
  .move-feedback { grid-area: feedback; justify-self: center; min-height: 16px; line-height: 16px; margin: .18rem 5px 0; }
  .mobile-links { display: flex; gap: 1.5rem; justify-content: center; align-items: center;
    margin: .25rem 0 max(.4rem,env(safe-area-inset-bottom)); color: var(--muted); font-size: .79rem; }
  .mobile-links a { padding: .5rem; }
  .is-error .intro, .is-loading .intro { display: block; }
  .is-complete .workspace { margin-top: .75rem; }
}
@media (min-width: 711px) {
  .preview-toggle { margin-top: .75rem; }
  .move-feedback { justify-self: end; }
}

.entry { max-width: 25rem; }
.entry label { display: block; margin-bottom: .35rem; font-weight: 650; }
.entry input { width: 100%; min-height: 46px; padding: .55rem .75rem; border: 1px solid #82928a; border-radius: .35rem; font: inherit; font-size: 1rem; color: var(--ink); background: #fffdf7; }
.entry input[aria-invalid="true"] { border-color: var(--wine); }
.entry button { width: 100%; min-height: 47px; margin-top: 1rem; border: 0; border-radius: .35rem; background: var(--ink); color: #fffaf0; font-weight: 650; }
.entry button:disabled { opacity: .7; }
.entry p { margin-top: .35rem; font-size: .85rem; line-height: 1.4; color: var(--muted); }
.entry .start-note { text-align: center; }
.entry #entry-error { color: var(--wine); }
.is-entry #board, .is-entry .move-feedback { display: none; }
.is-entry .finished-art { display: block; width: 100%; height: 100%; }
.is-entry .directions { max-width: 28rem; }
@media (max-width: 710px) {
  .desk.is-entry { grid-template-areas: 'intro' 'mat' 'controls'; padding: max(1rem,env(safe-area-inset-top)) .65rem .7rem; }
  .is-entry .intro { display: block; padding: 0; }
  .is-entry .country { color: var(--wine); margin-bottom: .2rem; }
  .is-entry .intro h1 { font-size: clamp(2.05rem,8vw,3rem); }
  .is-entry .directions { font-size: .95rem; margin-top: .35rem; }
  .is-entry .mat { margin-block: .85rem .2rem; background: transparent; padding: 0; }
  .is-entry .paper { width: min(calc(100vw - 44px), calc(clamp(8rem,30svh,18rem) * var(--art-proportion,.66667))); padding: .22rem; border: 1px solid var(--rule); }
  .is-entry figcaption { display: none; }
  .is-entry .entry { width: 100%; max-width: 28rem; justify-self: center; margin: .55rem 0 0; }
}

@font-face {
  font-family: "Postcard Baskerville";
  src: url("./challenge-serif.ttf") format("truetype");
  font-display: swap;
}

html:has(.is-app-play) {
  background: #06323e url("./challenge-teal.png") center / 100% min(100%, 115rem) repeat-y;
}

body:has(.is-app-play) :is(.masthead, .mobile-links) { display: none; }

.desk.is-app-play {
  --game-gold: #f1c66b;
  --game-cream: #fff0d5;
  --game-paper: linear-gradient(#fff0d5, #f3d8b0);
  --game-ink: #063d42;
  position: relative;
  display: block;
  width: min(100% - 2rem, 30rem, max(15.8rem, calc((100svh - 12.5rem) * var(--art-proportion, .6667))));
  margin-inline: auto;
  padding: max(.8rem, env(safe-area-inset-top)) 0 max(1.75rem, env(safe-area-inset-bottom));
  color: var(--game-cream);
  font-family: "Postcard Baskerville", Georgia, serif;
}

.is-app-play :focus-visible { outline-color: #fff0d5; }
.is-app-play .intro { display: block; text-align: center; margin: 0; padding: 0 .25rem; }
.is-app-play .country {
  display: block;
  margin: 0 0 .45rem;
  color: var(--game-gold);
  font: bold .83rem/1.3 "Postcard Baskerville", Georgia, serif;
  letter-spacing: .045em;
  text-transform: none;
}
.is-app-play .intro h1 {
  color: inherit;
  font: 400 clamp(1.45rem, 6.7vw, 2.15rem)/1.17 "Postcard Baskerville", Georgia, serif;
  margin: .7rem 0 1.05rem;
  overflow-wrap: anywhere;
}
.is-app-play .intro .directions {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.is-app-play.is-error .intro .directions {
  position: static;
  width: auto;
  height: auto;
  clip-path: none;
  white-space: normal;
  color: inherit;
}
.is-app-play #play-panel { margin: 0 0 .95rem; border-top: 1px solid #f1c66b99; padding: .55rem .25rem 0; }
.challenge-stats { display: flex; justify-content: space-between; gap: 1rem; align-items: start; font-size: .83rem; }
.joined-count { display: grid; width: 60%; grid-template-columns: minmax(0, 1fr) max-content; align-items: center; gap: .14rem .36rem; }
.joined-count label { grid-column: 1 / -1; }
.joined-count progress {
  margin: 0;
  height: .41rem;
  border: 1px solid var(--game-gold);
  color: var(--game-gold);
  background: #426564;
}
.joined-count progress::-webkit-progress-bar { background: #426564; }
.joined-count progress::-webkit-progress-value { border-radius: 1rem; background: var(--game-gold); }
.joined-count progress::-moz-progress-bar { border-radius: 1rem; background: var(--game-gold); }
#progress-percent { font-size: 1.05rem; color: var(--game-gold); }
.challenge-clock { text-align: right; white-space: nowrap; }
.challenge-clock strong {
  display: block;
  font-size: 1.28rem;
  line-height: 1.35;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}
.is-app-play .connection-note { color: var(--game-cream); font-size: .75rem; }
.is-app-play .mat { display: block; padding: 0; margin: 0; width: 100%; background: transparent; }
.is-app-play .mat::before { display: none; }
.is-app-play .paper {
  width: 100%;
  margin-inline: auto;
  padding: .32rem;
  border: 1px solid var(--game-gold);
  border-radius: .6rem;
  background: var(--game-paper);
  box-shadow: none;
}
.is-app-play .picture { border-radius: .27rem; }
.is-app-play #board { border-radius: inherit; }
.is-app-play figcaption {
  position: relative;
  display: grid;
  place-items: center;
  justify-content: stretch;
  min-height: 2.35rem;
  padding: .35rem 0 .15rem;
}
.is-app-play figcaption > :first-child { color: var(--game-ink); font: italic 400 .97rem/1.25 "Postcard Baskerville", Georgia, serif; }
.is-app-play :is(.caption-place, .postmark) { display: none; }
.is-app-play .preview-toggle {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  margin: 0;
  padding: 0 .55rem;
  min-height: 36px;
  min-width: 0;
  border-color: #527a78;
  color: var(--game-ink);
  font: inherit;
  font-size: .72rem;
}
.is-app-play .preview-toggle[aria-pressed="true"] { color: var(--game-cream); }
.is-app-play .preview-toggle:focus-visible { outline-color: #063d42; }
.is-app-play .move-feedback {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}
.is-app-play.duel .tile {
  --seam-top: 1px;
  --seam-right: 1px;
  --seam-bottom: 1px;
  --seam-left: 1px;
}
.is-app-play.duel .tile[data-joined-top] { --seam-top: 0px; }
.is-app-play.duel .tile[data-joined-right] { --seam-right: 0px; }
.is-app-play.duel .tile[data-joined-bottom] { --seam-bottom: 0px; }
.is-app-play.duel .tile[data-joined-left] { --seam-left: 0px; }
.is-app-play.duel .tile::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border: solid #fffaf2;
  border-width: var(--seam-top) var(--seam-right) var(--seam-bottom) var(--seam-left);
  border-radius:
    calc(1.3 * (var(--seam-top) + var(--seam-left)))
    calc(1.3 * (var(--seam-top) + var(--seam-right)))
    calc(1.3 * (var(--seam-bottom) + var(--seam-right)))
    calc(1.3 * (var(--seam-bottom) + var(--seam-left)));
}
.is-app-play.is-complete .intro h1 { display: none; }
.is-app-play .result {
  margin: 0;
  padding: 0;
  border: 0;
  text-align: center;
}
.is-app-play .result h2 {
  margin: .85rem 0 clamp(1.1rem, 4.2vw, 1.85rem);
  padding: 0 .25rem 1rem;
  border-bottom: 1px solid #f1c66b99;
  font: 400 clamp(1.12rem, 5.4vw, 1.95rem)/1.22 "Postcard Baskerville", Georgia, serif;
}
.is-app-play .result .mat { width: min(76%, 20rem); margin-inline: auto; }
.is-app-play .result .finished-art { border-radius: .22rem; }
.is-app-play .result figcaption > :first-child { font-style: normal; overflow-wrap: anywhere; }
.is-app-play .result p { color: var(--game-cream); font-size: .84rem; margin: .38rem 0; }
.is-app-play .result .result-time { margin-top: .85rem; color: var(--game-gold); font-size: 1.08rem; }
#result-detail:empty { display: none; }
.is-app-play .result .retry {
  min-height: 44px;
  padding: .55rem .65rem;
  border: 1px solid var(--game-gold);
  border-radius: .55rem;
  color: var(--game-cream);
  background: linear-gradient(#004955, #063d42);
}
.install-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  margin-top: .65rem;
}
.install-links .install { display: block; border-radius: 6px; }
.install-links .install:hover { opacity: .85; }
.install-links img { display: block; width: auto; height: 44px; }
/* The Google Play artwork includes transparent padding around its visible badge. */
.install-links [data-platform="android"] img { height: 66.3px; }
@media (max-width: 370px) {
  .desk.is-app-play { width: min(100% - 1.5rem, max(15.8rem, calc((100svh - 12.5rem) * var(--art-proportion, .6667)))); }
}

/* A room-wide table is available to every joined player. */
.room-standings { grid-column:1/-1; margin-top:1.1rem; padding:1rem; border:1px solid var(--rule); border-radius:.6rem; background:var(--paper); color:var(--ink); }
.scores-heading { display:flex; align-items:center; justify-content:space-between; gap:.65rem; }
.scores-heading h2 { font:500 1.22rem/1.2 var(--serif); }
.scores-heading button { min-height:44px; padding:.45rem .6rem; border:1px solid #9caa9d; border-radius:.4rem; background:transparent; font-size:.85rem; }
.scores-heading button:disabled { opacity:.6; }
#scores-status, #scores-app-time, #scores-empty { margin-top:.65rem; font: .87rem/1.4 -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif; }
#scores-status:empty { display:none; }
#room-scores { margin:.65rem 0 0; padding:0; list-style:none; }
#room-scores li { display:grid; grid-template-columns:2rem minmax(0,1fr) auto; align-items:center; gap:.5rem; padding:.7rem .3rem; border-top:1px solid var(--rule); font: .95rem/1.4 -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif; }
#room-scores li span:nth-child(2) { overflow-wrap:anywhere; }
#room-scores li.is-self { color:#153e3b; background:#e4ebdb; border-radius:.3rem; }
#room-scores strong { font-variant-numeric:tabular-nums; }
.is-app-play .room-standings { width:100%; margin-top:1rem; background:var(--game-paper); color:var(--game-ink); }
.is-app-play .room-standings :focus-visible { outline-color:#17494a; }
