:root {
  font-family: Segoe UI, system-ui, sans-serif;
  color: #213c32;
  background: #f6f4ec;
  font-synthesis: none;
  --green: #1e5945;
  --muted: #69776f;
  --line: #dedfd4;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

button, input, select {
  font: inherit;
}

button, a, input, select {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid #bf8735;
  outline-offset: 4px;
}

[hidden] {
  display: none!important;
}

header, footer {
  max-width: 1280px;
  margin: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 32px 48px;
}

.brand {
  text-decoration: none;
  color: var(--green);
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -2px;
}

.brand span {
  font-size: 12px;
  vertical-align: sub;
  letter-spacing: 0;
  margin-left: 3px;
}

.badge {
  font-size: 10px;
  letter-spacing: 2px;
  border: 1px solid var(--line);
  border-radius: 30px;
  padding: 9px 13px;
  color: var(--muted);
}

main {
  max-width: 1280px;
  margin: 54px auto 80px;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 72px;
  padding: 0 48px;
  align-items: center;
}

.eyebrow {
  font-size: 10px;
  letter-spacing: 2px;
  font-weight: 700;
  color: var(--green);
}

h1 {
  font-family: Georgia, serif;
  font-weight: 400;
  font-size: clamp(60px, 6vw, 88px);
  line-height: 1.03;
  letter-spacing: -4px;
  margin: 24px 0;
}

h2 {
  font-family: Georgia, serif;
  font-weight: 400;
  font-size: 30px;
  line-height: 1.2;
  margin: 22px 0;
}

.lede {
  max-width: 400px;
  font-size: 16px;
  line-height: 1.8;
  color: var(--muted);
}

.tiles {
  display: flex;
  gap: 7px;
  margin: 36px 0;
}

.tiles span {
  display: grid;
  place-items: center;
  width: 44px;
  height: 50px;
  background: #ead4a9;
  border: 1px solid #d7bb87;
  border-radius: 5px;
  box-shadow: 0 4px 0 #c6a879, 0 7px 12px #213c3210;
  font-size: 23px;
  font-weight: 600;
  color: #55452e;
  transform: rotate(-3deg);
}

.tiles span:nth-child(2n) {
  transform: rotate(3deg);
}

.details {
  display: flex;
  gap: 20px;
  font-size: 11px;
  color: var(--muted);
}

.details span+span:before {
  content: '·';
  margin-right: 20px;
}

.card {
  background: #fffefa;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 20px 60px #233b3210;
  min-width: 0;
}

.card-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

#connection {
  font-size: 11px;
  color: var(--muted);
}

#connection[data-live=true] {
  color: var(--green);
}

#connection[data-live=true]:before {
  content: '●';
  font-size: 9px;
  margin-right: 6px;
}

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin: 20px 0 9px;
}

input, select {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid #d4d9cf;
  border-radius: 7px;
  background: #fffefa;
  color: #213c32;
  min-width: 0;
}

button {
  border: 0;
  background: var(--green);
  color: #fffefa;
  padding: 14px 18px;
  border-radius: 7px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}

form>button, #join-button {
  width: 100%;
  margin-top: 22px;
}

button:hover {
  background: #287254;
}

button:disabled {
  cursor: default;
  background: #eaede5;
  color: #7d877e;
}

.secondary {
  background: #eff2e9;
  color: var(--green);
  white-space: nowrap;
}

.secondary:hover {
  background: #dfe8d9;
}

.muted, .field-note {
  color: var(--muted);
}

.field-note, .small {
  font-size: 12px;
  line-height: 1.65;
}

.room-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
}

#players {
  padding: 0;
  list-style: none;
  margin: 4px 0 22px;
}

#players li {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 13px 0;
  border-bottom: 1px solid #eeeee6;
}

.avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #e9eee2;
  color: var(--green);
  font-weight: 600;
}

.player-name {
  flex: 1;
  overflow-wrap: anywhere;
  font-size: 14px;
}

.player-status {
  font-size: 11px;
  color: var(--muted);
}

.invite-row {
  display: flex;
  gap: 8px;
}

.invite-row input {
  font-size: 12px;
}

.actions {
  display: flex;
  gap: 10px;
  margin-top: 22px;
}

.actions button {
  flex: 1;
}

#error {
  padding: 12px;
  background: #f9e8de;
  color: #843d24;
  border-radius: 7px;
  font-size: 13px;
  line-height: 1.5;
}

footer {
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--muted);
  gap: 20px;
  padding-top: 24px;
}

@media (max-width: 800px) {
  header, footer {
    padding: 24px;
  }

  main {
    grid-template-columns: 1fr;
    gap: 34px;
    padding: 0 24px;
    margin: 26px auto 44px;
  }

  .intro h1 br {
    display: none;
  }

  h1 {
    font-size: 56px;
    letter-spacing: -2px;
  }

  .intro .lede {
    max-width: 100%;
  }

  .tiles {
    margin: 25px 0;
  }

  .card {
    padding: 25px;
  }

  footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

}

@media (max-width: 380px) {
  .details {
    gap: 9px;
  }

  .details span+span:before {
    margin-right: 9px;
  }

  .tiles {
    gap: 5px;
  }

  .tiles span {
    width: 36px;
    height: 44px;
  }

  .invite-row {
    flex-direction: column;
  }

  .badge {
    font-size: 8px;
  }

}

/* Match layout */
body.playing .intro {
  display: none;
}
body.playing main {
  max-width: 1120px;
  grid-template-columns: minmax(0, 1fr) 310px;
  align-items: start;
  gap: 32px;
  margin-top: 24px;
}
body.playing .card {
  padding: 24px;
}
body.playing #players li {
  flex-wrap: wrap;
}
body.playing .player-status {
  margin-left: 46px;
  width: 100%;
}
.current-player .avatar {
  background: var(--green);
  color: #fffefa;
}
.game-area {
  min-width: 0;
}
.game-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
.game-heading h1 {
  font-size: clamp(28px, 3vw, 44px);
  letter-spacing: -1px;
  margin: 8px 0 24px;
}
.game-heading .eyebrow {
  margin-top: 0;
}
.bag-count {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.board-scroll {
  overflow-x: auto;
  padding: 5px;
  margin: -5px;
}
.board {
  display: grid;
  grid-template-columns: repeat(15, minmax(0, 1fr));
  gap: 2px;
  padding: 7px;
  border: 1px solid #476654;
  border-radius: 9px;
  background: #375744;
  min-width: 465px;
}
.square {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  padding: 0;
  border-radius: 2px;
  min-width: 0;
  background: #e9ece0;
  color: #58684d;
  font-size: 9px;
  font-weight: 700;
}
.square:hover {
  filter: brightness(1.07);
  background: #e9ece0;
}
.square:focus-visible {
  z-index: 2;
  outline: 3px solid #f0c55b;
  outline-offset: 1px;
}
.premium-DoubleLetter, .premium-DoubleLetter:hover {
  background: #b9d9de;
  color: #245769;
}
.premium-TripleLetter, .premium-TripleLetter:hover {
  background: #4f899f;
  color: #fff;
}
.premium-DoubleWord, .premium-DoubleWord:hover {
  background: #e9b9a6;
  color: #7e4236;
}
.premium-TripleWord, .premium-TripleWord:hover {
  background: #b75b4d;
  color: #fff;
}
.tile-square, .tile-square:hover {
  background: #ead4a9;
  color: #443c2b;
  box-shadow: inset 0 -3px #c6a879;
  font-size: clamp(16px, 1.7vw, 23px);
}
.square sub, .rack-tile sub {
  position: absolute;
  font-size: 9px;
  bottom: 4px;
  right: 4px;
}
.blank-tile > span {
  opacity: 50%;
}
.staged, .staged:hover {
  background: #f8e8b9;
  outline: 2px solid #f5c74e;
  outline-offset: -2px;
}
.premium-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 14px 0 22px;
  font-size: 10px;
  color: var(--muted);
}
.premium-legend span {
  border-bottom: 3px solid;
  padding-bottom: 4px;
}
.legend-dl { border-color: #b9d9de !important; }
.legend-tl { border-color: #4f899f !important; }
.legend-dw { border-color: #e9b9a6 !important; }
.legend-tw { border-color: #b75b4d !important; }
.rack-heading {
  display: flex;
  flex-wrap: wrap;
  gap: 0 12px;
  align-items: center;
  justify-content: space-between;
}
.rack-heading h2 {
  font-size: 24px;
  margin: 10px 0 16px;
}
.text-button, .text-button:hover {
  background: transparent;
  color: var(--green);
  font-size: 12px;
  padding: 8px;
  text-decoration: underline;
}
.rack {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  background: #e4e4d5;
  border-radius: 8px;
  padding: 14px;
  min-height: 84px;
}
.rack-tile, .rack-tile:hover, .rack-tile:disabled {
  position: relative;
  width: 42px;
  height: 50px;
  padding: 0;
  background: #ead4a9;
  color: #443c2b;
  border: 1px solid #c6a879;
  border-radius: 5px;
  box-shadow: 0 3px #c6a879;
  font-size: 23px;
}
.rack-tile[aria-pressed=true] {
  outline: 3px solid var(--green);
  transform: translateY(-5px);
}
.rack-tile.used {
  opacity: .3;
}
.rack-tile {
  touch-action: none;
  user-select: none;
}
.rack-tile.dragging {
  z-index: 3;
  opacity: .85;
  cursor: grabbing;
}
.rack-tile.drop-target {
  outline: 3px dashed var(--green);
}
.rack-tools {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 4px;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
#blank-picker input {
  max-width: 90px;
  text-transform: uppercase;
}
.game-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.game-actions button {
  font-size: 12px;
}
.move-preview {
  font-weight: 600;
  font-size: 14px;
  color: var(--green);
  min-height: 20px;
}
.result-banner, .retry-panel {
  padding: 16px;
  border-radius: 8px;
  background: #e3ecd9;
  font-size: 14px;
  line-height: 1.6;
}
.retry-panel {
  background: #f5e5c5;
  margin-top: 16px;
}
.move-history {
  list-style: none;
  padding: 0;
  max-height: 300px;
  overflow: auto;
  font-size: 12px;
}
.move-history li {
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
  line-height: 1.6;
  overflow-wrap: anywhere;
}
.move-history small {
  display: block;
  color: var(--muted);
}
@media (max-width: 1000px) {
  body.playing main {
    grid-template-columns: minmax(0, 1fr);
    max-width: 760px;
  }
  .tile-square {
    font-size: 20px;
  }
}
@media (max-width: 500px) {
  body.playing main {
    padding: 0 14px;
  }
  .game-heading {
    align-items: start;
  }
  .bag-count {
    font-size: 10px;
    margin-top: 5px;
  }
  .rack {
    gap: 5px;
    padding: 10px;
  }
  .rack-tile {
    width: 36px;
    height: 46px;
  }
}

.square.drop-target {
  outline: 3px solid #235c45;
  outline-offset: -3px;
  filter: brightness(1.12);
}

.staged {
  touch-action: none;
  user-select: none;
  cursor: grab;
}
.tile-drag-ghost {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  opacity: .9;
  margin: 0;
}
.rack.drop-target {
  outline: 3px dashed var(--green);
}
#blank-dialog {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px;
  width: 420px;
  max-width: calc(100vw - 32px);
  background: #faf8f0;
  color: var(--green);
  box-shadow: 0 24px 80px rgb(20 40 30 / 25%);
}
#blank-dialog h2 {
  margin: 0 0 8px;
  font-size: 26px;
}
#blank-destination {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}
#blank-dialog::backdrop {
  background: rgb(20 35 28 / 40%);
  backdrop-filter: blur(3px);
}
.blank-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}
.blank-controls button {
  padding: 14px 12px;
  font-size: 13px;
  white-space: nowrap;
}
#blank-choice {
  flex: 0 0 64px;
  width: 64px;
  height: 56px;
  padding: 8px;
  text-align: center;
  font-size: 24px;
  font-weight: 600;
  text-transform: uppercase;
  background: #ead4a9;
  border-color: #c6a879;
  box-shadow: 0 3px #c6a879;
}
@media (max-width: 400px) {
  #blank-dialog { padding: 20px; }
  .blank-controls { gap: 8px; }
  .blank-controls button { padding: 14px 10px; }
}

.turn-notice {
  position: fixed;
  z-index: 20;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 16px;
  width: max-content;
  max-width: min(560px, calc(100vw - 32px));
  padding: 14px 16px 14px 20px;
  border: 1px solid #b8cbb3;
  border-radius: 12px;
  background: #e3ecd9;
  color: var(--green);
  box-shadow: 0 8px 32px rgb(20 40 30 / 18%);
}
.turn-notice p {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.turn-notice button {
  flex-shrink: 0;
  padding: 6px 10px;
  background: transparent;
  color: var(--green);
  font-size: 24px;
}

.tile-square.last-opponent-word,
.tile-square.last-opponent-word:hover {
  background: #e1dfb8;
  box-shadow: inset 0 0 0 2px #8ba079;
}
