/*
 * Sizes are in rem throughout. The root font size is set from JavaScript and grows with the
 * magnification level, so the whole interface scales with the tiles.
 */

:root {
  --felt-hi: #1d6158;
  --felt-mid: #114440;
  --felt-lo: #082a28;
  --ink: #f7f3e6;
  --ink-soft: #bcd3cc;
  --paper: #fbf7ea;
  --paper-ink: #142927;
  --paper-soft: #47605c;
  --accent: #14645a;
  --tile-face-hi: #fffdf4;
  --tile-face-lo: #efe6cc;
  --tile-edge: #cdc19b;
  --tile-back: #1c7a5b;
  --gold: #ffb300;
  --hint: #0a84ff;
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--felt-lo);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.35;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

:focus-visible {
  outline: 0.2rem solid var(--gold);
  outline-offset: 0.12rem;
}

[hidden] {
  display: none !important;
}

/* ---------- frame ---------- */

#app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template: "top" auto "play" 1fr "controls" auto / 1fr;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: radial-gradient(ellipse at 50% 35%, var(--felt-hi), var(--felt-mid) 55%, var(--felt-lo));
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.45rem 0.9rem 0.2rem;
  white-space: nowrap;
}

.topbar h1 {
  margin: 0;
  font-size: min(1.3rem, 7vw);
  font-weight: 800;
}

.topbar p {
  margin: 0;
  font-size: min(1.1rem, 5.6vw);
  font-weight: 700;
  color: var(--ink-soft);
}

#play {
  grid-area: play;
  position: relative;
  min-height: 0;
  min-width: 0;
}

.bottom {
  grid-area: controls;
  position: relative;
}

.bottombar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.35rem;
  padding: 0.35rem 0.5rem 0.45rem;
}

.bar-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.1rem;
  min-width: 0;
  min-height: 3.4rem;
  padding: 0.3rem 0.1rem;
  border: 0.125rem solid rgb(255 255 255 / 0.24);
  border-radius: 0.8rem;
  background: rgb(255 255 255 / 0.1);
  font-size: min(0.85rem, 3.5vw);
  font-weight: 700;
}

.bar-btn svg {
  width: min(1.75rem, 9vw);
  height: min(1.75rem, 9vw);
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.bar-btn:active:not(:disabled),
.bar-btn[aria-expanded="true"] {
  background: rgb(255 255 255 / 0.3);
}

.bar-btn:disabled {
  opacity: 0.38;
  cursor: default;
}

/* From 2× up, the labels would be too small to help; the icons take the room instead. */
.big-ui .bar-btn span {
  display: none;
}

.big-ui .bar-btn svg {
  width: min(2.3rem, 11vw);
  height: min(2.3rem, 11vw);
  stroke-width: 2.4;
}

/* A phone on its side has no height to spare, so the controls move to the right edge. */
@media (orientation: landscape) and (max-height: 540px) {
  #app {
    grid-template: "top controls" auto "play controls" 1fr / 1fr auto;
  }

  .bottombar {
    grid-template-columns: none;
    grid-template-rows: repeat(5, 1fr);
    height: 100%;
    width: 4.4rem;
    padding: 0.4rem;
  }

  .bar-btn {
    min-height: 0;
  }
}

/* ---------- board ---------- */

.board {
  position: absolute;
  inset: 0;
  isolation: isolate;
}

.tile {
  position: absolute;
  width: var(--tw);
  height: var(--th);
  margin: 0;
  padding: 0;
  border: 1px solid #a99e7c;
  border-radius: calc(var(--tw) * 0.13);
  background: linear-gradient(150deg, var(--tile-face-hi), var(--tile-face-lo));
  box-shadow: var(--tile-shadow);
  -webkit-appearance: none;
  appearance: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.tile svg {
  position: absolute;
  inset: 5%;
  width: 90%;
  height: 90%;
  pointer-events: none;
}

.tile::before,
.tile::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  pointer-events: none;
}

.board.dim-blocked .tile.blocked::after {
  background: rgb(30 24 8 / 0.38);
}

.tile.selected {
  background: linear-gradient(150deg, #fff6c7, #ffd95a);
}

.tile.selected::before {
  box-shadow:
    inset 0 0 0 max(3px, calc(var(--tw) * 0.055)) var(--gold),
    inset 0 0 0 max(5px, calc(var(--tw) * 0.085)) #4a2600;
}

/* A hinted tile stays tinted and ringed for the whole pulse, so it reads at any moment. */
.tile.hint {
  background: linear-gradient(150deg, #e8f3ff, #a9d2ff);
}

.tile.hint::before {
  box-shadow:
    inset 0 0 0 max(4px, calc(var(--tw) * 0.07)) var(--hint),
    inset 0 0 0 max(6px, calc(var(--tw) * 0.1)) #00224d;
  animation: hint-pulse 0.7s ease-in-out infinite alternate;
}

@keyframes hint-pulse {
  from { opacity: 0.55; }
  to { opacity: 1; }
}

.tile.gone {
  opacity: 0;
  transform: scale(0.72);
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0s 0.18s;
}

.tile.refused {
  animation: refuse 0.3s ease;
}

@keyframes refuse {
  20% { transform: translateX(-7%); }
  50% { transform: translateX(6%); }
  80% { transform: translateX(-3%); }
}

.tile:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

/* ---------- floating panels ---------- */

.banner,
.size-panel {
  background: var(--paper);
  color: var(--paper-ink);
  border-radius: 1rem;
  box-shadow: 0 0.5rem 1.6rem rgb(0 0 0 / 0.5);
}

.banner {
  position: absolute;
  left: 50%;
  bottom: 0.6rem;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.7rem;
  width: max-content;
  max-width: calc(100% - 1rem);
  padding: 0.5rem 0.6rem 0.5rem 1rem;
  font-size: 1.05rem;
  font-weight: 700;
}

.banner .btn {
  min-height: 2.6rem;
  padding: 0.3rem 1rem;
  white-space: nowrap;
}

.size-panel {
  position: absolute;
  left: 0.5rem;
  right: 0.5rem;
  bottom: calc(100% + 0.4rem);
  max-width: 24rem;
  margin: 0 auto;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem;
  z-index: 2;
}

.size-panel button {
  width: 3.6rem;
  height: 3.6rem;
  border: 0;
  border-radius: 0.9rem;
  background: var(--accent);
  color: #fff;
  font-size: 2.3rem;
  font-weight: 800;
  line-height: 1;
}

.size-panel button:disabled {
  opacity: 0.3;
  cursor: default;
}

/* With the controls down the right edge, the panel opens beside them, over the board's corner. */
@media (orientation: landscape) and (max-height: 540px) {
  .size-panel {
    left: auto;
    right: calc(100% + 0.5rem);
    bottom: 0.5rem;
    width: min(19rem, 100vw - 6rem);
    margin: 0;
  }
}

.size-readout {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--paper-soft);
}

.size-readout strong {
  font-size: 1.7rem;
  line-height: 1.1;
  color: var(--paper-ink);
}

/* ---------- dialogs ---------- */

dialog {
  width: min(92vw, 30rem);
  max-height: 92dvh;
  padding: 1.4rem;
  border: 0;
  border-radius: 1.2rem;
  background: var(--paper);
  color: var(--paper-ink);
  box-shadow: 0 1rem 3rem rgb(0 0 0 / 0.55);
  overflow-y: auto;
}

dialog::backdrop {
  background: rgb(3 18 17 / 0.74);
}

dialog h2 {
  margin: 0 0 0.6rem;
  font-size: 1.55rem;
  line-height: 1.2;
}

dialog h3 {
  margin: 1.3rem 0 0.2rem;
  font-size: 0.9rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--paper-soft);
}

dialog p {
  margin: 0 0 0.7rem;
  font-size: 1.1rem;
}

dialog .note {
  margin-bottom: 0.2rem;
  font-size: 0.95rem;
  color: var(--paper-soft);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 3.2rem;
  padding: 0.5rem 1.2rem;
  border: 0.125rem solid var(--accent);
  border-radius: 0.9rem;
  background: var(--accent);
  color: #fff;
  font-size: 1.15rem;
  font-weight: 800;
  text-decoration: none;
}

.btn.secondary {
  background: transparent;
  color: var(--accent);
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 1.1rem 0 0;
}

.btn-row .btn {
  flex: 1 1 9rem;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.5rem 0;
  font-size: 1.08rem;
  font-weight: 600;
  cursor: pointer;
}

.toggle input {
  flex: none;
  position: relative;
  width: 3.2rem;
  height: 1.9rem;
  margin: 0;
  border-radius: 1rem;
  background: #aaa390;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  transition: background 0.15s;
}

.toggle input::after {
  content: "";
  position: absolute;
  top: 0.2rem;
  left: 0.2rem;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}

.toggle input:checked {
  background: var(--accent);
}

.toggle input:checked::after {
  transform: translateX(1.3rem);
}

.toggle small {
  display: block;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--paper-soft);
}

.toggle small:empty {
  display: none;
}

#dlgCheckin,
#dlgWin {
  text-align: center;
}

.checkin-art svg {
  width: 6rem;
  height: 6rem;
}

dialog .checkin-kicker {
  margin: 0.2rem 0 0.3rem;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--paper-soft);
}

dialog .checkin-text {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1.25;
}

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

  .tile.hint::before {
    opacity: 1;
  }
}
