:root {
  color-scheme: light;
  font-family: "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
  font-size: 18px;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  color: var(--ink);
  background: #f7f3e8;
  --ink: #253343;
  --muted-ink: #526171;
  --felt: #24475b;
  --felt-edge: #142c3b;
  --ivory: #fff9e9;
  --paper: #fffaf0;
  --paper-shadow: #c4bca5;
  --edge: #8a826d;
  --control-edge: #526171;
  --line: #d1cbbb;
  --action-blue: #0069a6;
  --action-blue-dark: #005282;
  --selection-blue: #0069a6;
  --blocker-gap: #fff9e9;
  --blocker-separator: #253343;
  --blocker-outer: #ffb36b;
  --focus: #153f6e;
  --gold: #f1cb78;
  --base-tile-width: 56px;
  --base-tile-height: 72px;
  --tile-width: var(--base-tile-width);
  --tile-height: var(--base-tile-height);
  --layer-offset-x: calc(var(--tile-width) * 0.2);
  --layer-offset-y: calc(var(--tile-height) * 0.155);
}

#board-canvas[data-layout="grand-72-v2"] {
  --layer-offset-x: 0px;
  --layer-offset-y: 0px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 0;
  min-height: 100%;
}

body {
  margin: 0;
  background: #f7f3e8;
}

button,
input,
select,
summary {
  font: inherit;
}

a {
  color: inherit;
}

.app-shell {
  width: min(100%, 1680px);
  height: 100vh;
  height: 100dvh;
  min-height: 24rem;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.site-header {
  position: relative;
  z-index: 30;
  flex: 0 0 auto;
  min-width: 0;
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 7px clamp(16px, 3vw, 42px);
  border-bottom: 1px solid var(--line);
  background: #fbf8ef;
}

.brand {
  min-width: 0;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 25px;
  letter-spacing: -0.035em;
  text-decoration: none;
  white-space: nowrap;
}

.header-utility {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
}

.quiet-link {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 12px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--action-blue-dark);
  cursor: pointer;
  font-size: 18px;
  font-weight: 650;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
  white-space: nowrap;
}

.quiet-link:hover,
.view-menu summary:hover {
  background: #eee9dc;
}

.quiet-link:focus-visible,
.view-menu summary:focus-visible,
.new-game-menu summary:focus-visible,
.game-action-button:focus-visible,
.view-options a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.view-menu,
.new-game-menu {
  position: relative;
  color: var(--ink);
}

.view-menu summary,
.new-game-menu summary {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 7px 13px;
  border: 1px solid transparent;
  border-radius: 9px;
  color: var(--action-blue-dark);
  cursor: pointer;
  font-size: 18px;
  font-weight: 650;
  list-style: none;
  text-decoration: underline;
  text-underline-offset: 4px;
  white-space: nowrap;
}

.view-menu summary::-webkit-details-marker,
.new-game-menu summary::-webkit-details-marker {
  display: none;
}

.view-menu summary::after,
.new-game-menu summary::after {
  content: "⌄";
  font-size: 17px;
  line-height: 1;
  text-decoration: none;
}

.view-menu[open] summary::after,
.new-game-menu[open] summary::after {
  content: "⌃";
}

.view-options,
.new-game-options {
  position: absolute;
  z-index: 40;
  top: calc(100% + 7px);
  right: 0;
  width: min(340px, calc(100vw - 24px));
  padding: 14px;
  border: 1px solid #9da89a;
  border-radius: 13px;
  background: var(--paper);
  box-shadow: 0 12px 32px rgb(23 39 29 / 18%);
}

.view-options {
  display: grid;
  gap: 5px;
}

.setting-option {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 5px 7px;
  border-radius: 7px;
  color: var(--ink);
  cursor: pointer;
  font-size: 17px;
  line-height: 1.35;
}

.setting-option input {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  margin: 0;
  accent-color: var(--action-blue);
}

.view-note {
  margin: 2px 5px 5px 42px;
  color: var(--muted-ink);
  font-size: 15px;
  line-height: 1.4;
}

.privacy-in-view {
  min-height: 48px;
  display: flex;
  align-items: center;
  padding: 6px 7px;
  color: var(--action-blue-dark);
  font-size: 16px;
  font-weight: 650;
  text-underline-offset: 4px;
}

.game-main {
  width: 100%;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  padding: 9px clamp(12px, 3vw, 42px) 14px;
}

.game-controls {
  grid-row: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 1px 0;
}

.priority-actions {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.game-action-button {
  min-width: 86px;
  min-height: 54px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 17px;
  border: 1px solid var(--control-edge);
  border-radius: 10px;
  background: var(--paper);
  color: var(--action-blue-dark);
  cursor: pointer;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  touch-action: manipulation;
}

.game-action-button:hover:not(:disabled) {
  border-color: var(--action-blue-dark);
  background: #fffdf7;
}

.game-action-button:disabled {
  border-style: solid;
  background: #e9e5d9;
  color: #59685f;
  cursor: not-allowed;
}

.game-action-primary {
  border-color: var(--action-blue);
  background: var(--action-blue);
  color: #fffdf7;
}

.game-action-primary:hover:not(:disabled) {
  border-color: var(--action-blue-dark);
  background: var(--action-blue-dark);
  color: #ffffff;
}

.new-game-menu summary {
  min-height: 52px;
  padding-inline: 16px;
  border-color: var(--control-edge);
  background: var(--paper);
  text-decoration: none;
}

.new-game-menu summary:hover {
  background: #fffdf7;
}

.new-game-options {
  display: grid;
  gap: 9px;
}

.new-game-options label {
  color: var(--ink);
  font-size: 16px;
  font-weight: 700;
}

.new-game-options select {
  width: 100%;
  min-height: 52px;
  padding: 7px 36px 7px 11px;
  border: 1px solid var(--control-edge);
  border-radius: 9px;
  background: #fffdf7;
  color: var(--ink);
  cursor: pointer;
  font-size: 17px;
}

.new-game-options .game-action-button {
  width: 100%;
}

.board-section {
  grid-row: 2;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.board-topline {
  flex: 0 0 auto;
  min-width: 0;
  min-height: 29px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 18px;
}

.game-count {
  min-width: 0;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin: 0;
  color: var(--muted-ink);
  line-height: 1.3;
}

.game-count strong {
  color: var(--ink);
  font-size: 19px;
  font-weight: 700;
}

.game-count > span {
  font-size: 16px;
}

.scroll-hint {
  flex: 0 1 auto;
  margin: 0;
  color: var(--muted-ink);
  font-size: 15px;
  line-height: 1.35;
  text-align: right;
}

.scroll-hint[aria-hidden="true"] {
  display: none;
}

.save-recovery {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 14px;
  padding: 10px 13px;
  border: 1px solid #9b7950;
  border-radius: 10px;
  background: #f5ebd7;
  color: #493717;
}

.save-recovery[hidden] {
  display: none;
}

.save-recovery p {
  flex: 1 1 18rem;
  margin: 0;
  font-size: 16px;
  line-height: 1.4;
}

.save-recovery-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.save-recovery-actions .game-action-button {
  min-height: 48px;
  font-size: 16px;
}

.board-viewport {
  position: relative;
  isolation: isolate;
  min-width: 0;
  min-height: 12rem;
  flex: 1 1 0;
  max-height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-color: #9fb7c5 #183b4f;
  scrollbar-width: auto;
  border: 2px solid var(--felt-edge);
  border-radius: 14px;
  background: var(--felt);
  box-shadow: 0 3px 12px rgb(30 50 37 / 11%);
  color: var(--ivory);
  -webkit-overflow-scrolling: touch;
}

.board-canvas {
  position: relative;
  min-width: 100%;
  min-height: 100%;
  margin: 0;
  background:
    radial-gradient(ellipse at 49% 45%, rgb(255 249 233 / 5%), transparent 70%),
    var(--felt);
}

.tile-button {
  position: absolute;
  width: var(--tile-width);
  height: var(--tile-height);
  display: grid;
  place-items: stretch;
  padding: 0;
  overflow: visible;
  border: 1px solid #948a72;
  border-radius: 8px;
  background: var(--ivory);
  box-shadow:
    0 4px 0 var(--paper-shadow),
    0 7px 0 #153345,
    0 9px 9px rgb(12 27 38 / 30%);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.tile-face {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 7px;
  background: var(--ivory);
}

.tile-face svg {
  width: 100%;
  height: 100%;
  display: block;
}

.tile-button[aria-disabled="true"] {
  box-shadow:
    0 2px 0 #b5ad98,
    0 4px 5px rgb(12 34 26 / 22%);
}

.tile-side-marker {
  position: absolute;
  z-index: 2;
  top: 24%;
  width: 3px;
  height: 52%;
  border-radius: 3px;
  background: #3f5968;
  pointer-events: none;
}

.tile-side-marker--left {
  left: 3px;
}

.tile-side-marker--right {
  right: 3px;
}

.tile-button[data-playable="true"]::before {
  position: absolute;
  z-index: 3;
  inset: 3px;
  border: 2px solid #007463;
  border-radius: 5px;
  content: "";
  pointer-events: none;
}

.tile-button[aria-pressed="true"] {
  border: 3px double var(--selection-blue);
  box-shadow:
    0 0 0 2px var(--ivory),
    0 0 0 5px var(--selection-blue),
    0 5px 0 #b4ac95,
    0 8px 9px rgb(12 27 38 / 28%);
}

.tile-button[aria-pressed="true"] .tile-face {
  border-radius: 4px;
}

.tile-button[data-blocker-cause="true"] {
  box-shadow:
    0 0 0 2px var(--blocker-gap),
    0 0 0 4px var(--blocker-separator),
    0 0 0 7px var(--blocker-outer),
    0 3px 0 #b5ad98,
    0 6px 7px rgb(12 27 38 / 25%);
}

.tile-marker {
  position: absolute;
  z-index: 5;
  width: 16px;
  height: 16px;
  display: grid;
  place-items: center;
  border: 1px solid #253343;
  border-radius: 50%;
  background: #fffdf6;
  color: #253343;
  font-family: Arial, sans-serif;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  pointer-events: none;
}

.tile-marker--selected {
  border-color: var(--selection-blue);
  color: var(--action-blue-dark);
}

.tile-button[data-marker-side="right"] .tile-marker--selected {
  top: -13px;
  right: -13px;
}

.tile-button[data-marker-side="left"] .tile-marker--selected {
  top: -13px;
  left: -13px;
}

.tile-button[data-marker-side="right"] .tile-marker--hint {
  right: -13px;
  top: calc(50% - 8px);
}

.tile-button[data-marker-side="left"] .tile-marker--hint {
  left: -13px;
  top: calc(50% - 8px);
}

.tile-marker--hint {
  border-color: #674912;
  background: #fff1c9;
  color: #513809;
  font-size: 12px;
}

.tile-button[data-hinted="true"]::after {
  position: absolute;
  z-index: 4;
  inset: -5px;
  border: 3px dashed #f0cd79;
  border-radius: 12px;
  content: "";
  pointer-events: none;
}

.tile-button:focus-visible {
  outline: 4px solid #b8d7ff;
  outline-offset: 4px;
}

.board-empty {
  position: absolute;
  inset: 0;
  min-width: 100%;
  min-height: 180px;
  display: grid;
  place-items: center;
  margin: 0;
  color: var(--ivory);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 32px;
  font-weight: 400;
  text-align: center;
}

.feedback-area {
  grid-row: 3;
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 3px;
  padding: 0 2px;
}

.board-message {
  height: 2.8em;
  min-height: 2.8em;
  max-height: 2.8em;
  margin: 0;
  overflow: auto;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.4;
  scrollbar-width: thin;
}

.focus-marker {
  height: 1.35em;
  min-height: 1.35em;
  max-height: 1.35em;
  margin: 0;
  padding: 0 0 0 9px;
  overflow: auto;
  border-left: 3px solid var(--focus);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.35;
  scrollbar-width: thin;
}

.focus-marker[aria-hidden="true"] {
  visibility: hidden;
}

.save-status {
  min-width: 0;
  min-height: 1.35em;
  margin: 0;
  overflow: hidden;
  color: var(--muted-ink);
  font-size: 15px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.save-status[data-state="saved"]::before,
.save-status[data-state="saving"]::before,
.save-status[data-state="unavailable"]::before,
.save-status[data-state="conflict"]::before {
  width: 8px;
  height: 8px;
  display: inline-block;
  margin: 0 7px 1px 1px;
  border: 1px solid currentColor;
  border-radius: 50%;
  background: #52715c;
  content: "";
  vertical-align: middle;
}

.save-status[data-state="saving"]::before {
  background: #9b7950;
}

.save-status[data-state="unavailable"]::before,
.save-status[data-state="conflict"]::before {
  background: #8a4a35;
}

.confirm-dialog {
  width: min(calc(100% - 24px), 480px);
  padding: 0;
  border: 1px solid #938a72;
  border-radius: 15px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 18px 60px rgb(22 39 29 / 30%);
}

.confirm-dialog::backdrop {
  background: rgb(18 30 22 / 55%);
}

.confirm-dialog-content {
  padding: 24px;
}

.confirm-dialog h2 {
  margin: 0 0 11px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 29px;
  font-weight: 400;
  line-height: 1.2;
}

.confirm-dialog p {
  margin: 0;
  color: var(--muted-ink);
  font-size: 17px;
  line-height: 1.5;
}

.confirm-dialog-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap-reverse;
  gap: 9px;
  margin-top: 22px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

html[data-contrast="high"] {
  --ink: #111820;
  --muted-ink: #263b4d;
  --felt: #172f41;
  --felt-edge: #071b27;
  --line: #6e786e;
  --control-edge: #263b4d;
  --selection-blue: #005282;
  --blocker-gap: #ffffff;
  --blocker-separator: #111820;
  --focus: #051d37;
}

html[data-contrast="high"] .site-header,
html[data-contrast="high"] .view-options,
html[data-contrast="high"] .new-game-options,
html[data-contrast="high"] .confirm-dialog {
  border-color: #1a2e20;
  background: #fffdf5;
}

html[data-contrast="high"] .board-viewport {
  border-width: 3px;
}

html[data-contrast="high"] .tile-button {
  border: 2px solid #17271d;
  background: #ffffff;
  box-shadow:
    0 4px 0 #a5a99f,
    0 7px 0 #0a251a,
    0 9px 8px rgb(0 0 0 / 35%);
}

html[data-contrast="high"] .tile-button[aria-disabled="true"] {
  border-style: solid;
}

html[data-contrast="high"] .tile-button[aria-pressed="true"] {
  border: 3px double var(--selection-blue);
}

html[data-contrast="high"] .tile-button[data-blocker-cause="true"] {
  box-shadow:
    0 0 0 2px var(--blocker-gap),
    0 0 0 4px var(--blocker-separator),
    0 0 0 7px var(--blocker-outer),
    0 3px 0 #b5ad98,
    0 6px 7px rgb(0 0 0 / 30%);
}

html[data-contrast="high"] .tile-button:focus-visible {
  outline-width: 5px;
}

html[data-tile-size="large"] {
  --tile-width: calc(var(--base-tile-width) * 1.15);
  --tile-height: calc(var(--base-tile-height) * 1.15);
}

@media (max-width: 1023px) {
  :root {
    --base-tile-width: 54px;
    --base-tile-height: 70px;
  }
}

@media (max-width: 639px) {
  :root {
    --base-tile-width: 52px;
    --base-tile-height: 68px;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .site-header {
    min-height: 62px;
    padding: 6px 12px;
  }

  .brand {
    font-size: 22px;
  }

  .header-utility {
    gap: 1px;
  }

  .quiet-link,
  .view-menu summary {
    min-height: 46px;
    padding-inline: 8px;
    font-size: 16px;
  }

  .view-menu summary::after {
    font-size: 15px;
  }

  .game-main {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px 12px 12px;
  }

  .board-section {
    order: 1;
    min-height: 20rem;
  }

  .feedback-area {
    order: 2;
    flex: 0 0 auto;
  }

  .game-controls {
    order: 3;
    flex: 0 0 auto;
    justify-content: space-between;
    gap: 8px;
    padding: 2px 0 4px;
  }

  .priority-actions {
    flex: 1 1 auto;
    gap: 8px;
  }

  .game-action-button {
    min-width: 0;
    min-height: 56px;
    padding: 8px 12px;
    font-size: 17px;
  }

  .priority-actions .game-action-button {
    flex: 1 1 0;
  }

  .new-game-menu {
    position: relative;
    flex: 0 0 auto;
  }

  .new-game-menu summary {
    min-height: 56px;
    padding-inline: 11px;
    font-size: 16px;
  }

  .new-game-options {
    position: absolute;
    top: auto;
    right: 0;
    bottom: calc(100% + 8px);
    width: min(340px, calc(100vw - 24px));
    max-height: min(80dvh, 520px);
    overflow: auto;
  }

  .board-topline {
    align-items: flex-start;
  }

  .game-count strong {
    font-size: 18px;
  }

  .game-count > span {
    font-size: 15px;
  }

  .scroll-hint {
    max-width: 48%;
    font-size: 14px;
  }

  .board-viewport {
    min-height: 17rem;
    max-height: 62dvh;
  }

  .board-message {
    height: 3.9em;
    min-height: 3.9em;
    max-height: 3.9em;
    font-size: 17px;
    line-height: 1.35;
  }

  .focus-marker {
    font-size: 15px;
  }

  .save-status {
    font-size: 14px;
  }

  .save-recovery {
    display: block;
  }

  .save-recovery p {
    font-size: 15px;
  }

  .save-recovery-actions {
    justify-content: flex-start;
    margin-top: 8px;
  }

  .confirm-dialog-content {
    padding: 20px;
  }

  .confirm-dialog h2 {
    font-size: 26px;
  }

  .confirm-dialog-actions .game-action-button {
    flex: 1 1 45%;
  }
}

@media (max-width: 380px) {
  .site-header {
    flex-wrap: wrap;
    justify-content: center;
    gap: 0 8px;
    padding-block: 3px;
  }

  .brand {
    flex: 1 1 100%;
    text-align: center;
  }

  .header-utility {
    flex: 1 1 100%;
    justify-content: center;
  }

  .board-section {
    min-height: 22rem;
  }

  .board-viewport {
    min-height: 15rem;
  }

  .game-controls {
    gap: 5px;
  }

  .game-main {
    padding-inline: 3px;
  }

  .view-options {
    position: fixed;
    top: 94px;
    right: 12px;
    left: 12px;
    width: auto;
    max-width: 340px;
    margin-inline: auto;
  }

  .new-game-options {
    right: 0;
    left: auto;
    width: min(340px, calc(100vw - 24px));
    max-width: 340px;
    margin: 0;
  }

  .priority-actions {
    gap: 5px;
  }

  .game-action-button {
    padding-inline: 8px;
  }

  .new-game-menu summary {
    padding-inline: 8px;
  }
}

@media (max-height: 40rem) and (min-width: 640px) {
  .app-shell {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .game-main {
    display: flex;
    flex-direction: column;
  }

  .board-section {
    min-height: 0;
  }

  .board-viewport {
    flex: 0 0 auto;
    height: min(48vh, 26rem);
    max-height: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (forced-colors: active) {
  .tile-button,
  .view-menu summary,
  .new-game-menu summary,
  .game-action-button,
  .board-viewport,
  .save-recovery,
  .view-options,
  .new-game-options {
    border: 1px solid ButtonText;
  }

  .save-recovery {
    background: Canvas;
    color: CanvasText;
  }

  .tile-button[aria-pressed="true"] {
    outline: 3px double Highlight;
  }
}
