/* Mahjpoint: a felt table, ivory tiles with jade backs. Gold marks a selection. */

:root {
  --felt: #10372e;
  --felt-glow: #1b5646;
  --felt-raised: #174639;
  --felt-line: #2b6554;
  --ivory: #f5efdf;
  --ivory-bright: #fcf8ec;
  --ivory-shade: #e6dec8;
  --jade: #146b4e;
  --jade-back: #2c8a68;
  --vermilion: #b93424;
  --vermilion-bright: #cc4231;
  --vermilion-back: #7e2014;
  --gold: #e8bb4c;
  --gold-bright: #f3cf73;
  --gold-back: #a67c1e;
  --ink: #1d2a26;
  --ink-soft: #5e6a63;
  --on-felt: #f5efdf;
  --on-felt-soft: #b9cdc3;
  --down-on-felt: #f4a899;
  --numeral: ui-serif, "New York", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia,
    "Noto Serif", serif;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --gutter: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  background: var(--felt);
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--on-felt);
  font: 16px/1.4 var(--ui);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .06 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
    radial-gradient(130% 75% at 50% -10%, var(--felt-glow), var(--felt) 70%);
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

h1,
h2,
h3,
p,
ol {
  margin: 0;
  padding: 0;
}

ol {
  list-style: none;
}

:focus-visible {
  outline: 3px solid var(--gold-bright);
  outline-offset: 2px;
}

/* Tiles */

.tile {
  --back: var(--jade-back);
  --depth: 4px;
  display: flex;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(180deg, var(--ivory-bright), var(--ivory) 60%, var(--ivory-shade));
  color: var(--ink);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 70%),
    0 var(--depth) 0 var(--back),
    0 calc(var(--depth) + 3px) 8px rgb(0 0 0 / 35%);
}

button.tile {
  transition:
    transform 80ms ease,
    box-shadow 80ms ease;
  user-select: none;
  -webkit-user-select: none;
}

button.tile:active:not(:disabled) {
  transform: translateY(calc(var(--depth) - 1px));
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 70%),
    0 1px 0 var(--back),
    0 2px 4px rgb(0 0 0 / 30%);
}

.tile[aria-pressed="true"] {
  --back: var(--gold-back);
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: var(--ink);
}

.tile:disabled {
  opacity: 0.38;
}

.cta {
  display: block;
  width: 100%;
  height: 62px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(180deg, var(--vermilion-bright), var(--vermilion));
  color: var(--ivory-bright);
  font: 700 21px/1 var(--numeral);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 25%),
    0 5px 0 var(--vermilion-back),
    0 9px 16px rgb(0 0 0 / 40%);
  transition:
    transform 80ms ease,
    box-shadow 80ms ease;
  user-select: none;
  -webkit-user-select: none;
}

.cta:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 25%),
    0 1px 0 var(--vermilion-back),
    0 2px 6px rgb(0 0 0 / 35%);
}

.cta:disabled {
  background: var(--felt-raised);
  color: #86a297;
  box-shadow: inset 0 0 0 1px var(--felt-line);
}

.link {
  min-height: 44px;
  padding: 0 4px;
  border: 0;
  background: none;
  color: var(--on-felt-soft);
  font-weight: 600;
}

.link.is-danger {
  color: var(--down-on-felt);
}

.is-up {
  color: var(--jade);
}

.is-down {
  color: var(--vermilion);
}

.is-even {
  color: var(--ink-soft);
}

/* Shared layout */

.screen {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 10px) var(--gutter) calc(var(--safe-bottom) + 24px);
  animation: fade-in 160ms ease-out;
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  margin-bottom: 10px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font: 700 20px/1 var(--numeral);
  letter-spacing: -0.01em;
}

.brand svg {
  width: 20px;
  height: auto;
}

.brand-accent {
  color: var(--gold-bright);
}

.section-title {
  margin-bottom: 12px;
  font: 700 19px/1.2 var(--numeral);
}

.hint {
  color: var(--on-felt-soft);
  font-size: 14px;
  text-align: center;
}

.language-switch {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--felt-line);
  border-radius: 999px;
  background: rgb(23 70 57 / 80%);
}

.language-option {
  min-width: 42px;
  height: 36px;
  padding: 0 8px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--on-felt-soft);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.language-option[aria-pressed="true"] {
  background: var(--gold);
  color: var(--ink);
}

/* Setup */

.setup {
  position: relative;
}

.setup .settings-link {
  position: absolute;
  top: calc(var(--safe-top) + 10px);
  right: var(--gutter);
}

.setup-hero {
  padding: 34px 0 28px;
  text-align: center;
}

.setup-hero svg {
  width: 66px;
  height: auto;
  filter: drop-shadow(0 8px 12px rgb(0 0 0 / 40%));
}

.setup-hero h1 {
  margin-top: 16px;
  font: 700 42px/1.05 var(--numeral);
  letter-spacing: -0.02em;
}

.setup-hero p {
  margin-top: 6px;
  color: var(--on-felt-soft);
  font-size: 17px;
}

.name-list {
  display: grid;
  gap: 14px;
}

.name-input {
  width: 100%;
  height: 58px;
  padding: 0 16px;
  font-size: 18px;
  font-weight: 600;
}

.name-input::placeholder {
  color: var(--ink-soft);
  font-weight: 400;
}

.form-note {
  min-height: 22px;
  margin: 12px 0 8px;
  color: var(--gold-bright);
  font-size: 15px;
  text-align: center;
}

.setup .hint {
  margin-top: 22px;
}

/* Game */

.game {
  padding-bottom: calc(var(--safe-bottom) + 112px);
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 12px;
}

.score-tile {
  position: relative;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  min-height: 104px;
  padding: 12px 14px 14px;
}

.score-name {
  overflow: hidden;
  padding-right: 18px;
  color: var(--ink-soft);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-net {
  font: 700 clamp(28px, 10vw, 40px)/1 var(--numeral);
  font-variant-numeric: tabular-nums lining-nums;
  white-space: nowrap;
}

.score-net.is-long {
  font-size: clamp(24px, 8.4vw, 34px);
}

.score-tile.is-leading::after {
  content: "";
  position: absolute;
  top: 16px;
  right: 14px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 3px rgb(232 187 76 / 35%);
}

.game-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
}

.log {
  margin-top: 10px;
}

.log-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
}

.log-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 64px;
  padding: 9px 14px 9px 10px;
  border: 1px solid var(--felt-line);
  border-radius: 12px;
  background: rgb(23 70 57 / 80%);
  text-align: left;
}

.mini-tile {
  --depth: 3px;
  flex: none;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  height: 42px;
  padding: 0 6px;
  border-radius: 8px;
  font: 700 18px/1 var(--numeral);
  font-variant-numeric: lining-nums;
}

.log-text {
  display: grid;
  flex: 1;
  gap: 1px;
  min-width: 0;
}

.log-title {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.log-detail {
  color: var(--on-felt-soft);
  font-size: 14px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.log-net {
  flex: none;
  color: var(--gold-bright);
  font: 700 21px/1 var(--numeral);
  font-variant-numeric: tabular-nums lining-nums;
}

.log .hint {
  margin-top: 12px;
}

.empty {
  margin-top: 24px;
  color: var(--on-felt-soft);
  text-align: center;
}

.dock {
  position: fixed;
  bottom: 0;
  left: 50%;
  width: 100%;
  max-width: 480px;
  padding: 30px var(--gutter) calc(var(--safe-bottom) + 20px);
  background: linear-gradient(to top, var(--felt) 68%, transparent);
  pointer-events: none;
  transform: translateX(-50%);
}

.dock .cta {
  pointer-events: auto;
}

/* Hand entry */

.sheet {
  width: 100%;
  max-width: 480px;
  height: 100vh;
  height: 100dvh;
  max-height: none;
  margin: 0 auto;
  padding: 0;
  overflow: hidden;
  border: 0;
  background: var(--felt);
  color: var(--on-felt);
}

.sheet[open] {
  display: flex;
  flex-direction: column;
  animation: rise 240ms cubic-bezier(0.2, 0.8, 0.25, 1);
}

.sheet::backdrop {
  background: rgb(3 16 12 / 70%);
}

.sheet-form {
  display: contents;
}

.sheet-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: calc(var(--safe-top) + 4px) var(--gutter) 2px;
}

.sheet-bar .link:first-child {
  justify-self: start;
}

.sheet-bar .link:last-child {
  justify-self: end;
}

.sheet-title {
  font: 700 19px/1 var(--numeral);
}

.sheet-body {
  display: grid;
  flex: 1;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: 12px;
  min-height: 0;
  padding: 2px var(--gutter) 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.question {
  margin-bottom: 8px;
  font: 700 17px/1.2 var(--numeral);
}

.question-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.question-row .question {
  margin-bottom: 0;
}

.pill {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--felt-line);
  border-radius: 999px;
  background: rgb(23 70 57 / 80%);
  color: var(--on-felt-soft);
  font-size: 14px;
  font-weight: 600;
}

.pill[aria-pressed="true"] {
  border-color: transparent;
  background: var(--gold);
  color: var(--ink);
}

.choices {
  display: grid;
  gap: 12px 10px;
}

.choices.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.jokerless-row {
  margin-top: 12px;
}

.choice {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 6px 8px;
  font-weight: 600;
  line-height: 1.15;
  text-align: center;
}

.choice-name {
  overflow: hidden;
  max-width: 100%;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.value-tile {
  font: 700 22px/1 var(--numeral);
  font-variant-numeric: lining-nums;
}

.value-groups {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.value-group-exposed {
  grid-column: 1 / -1;
}

.value-group-label {
  display: block;
  margin-bottom: 5px;
  color: var(--on-felt-soft);
  font-size: 13px;
}

.value-group-tiles {
  display: grid;
  grid-auto-columns: minmax(0, 1fr);
  grid-auto-flow: column;
  gap: 10px;
}

.tall {
  gap: 1px;
  min-height: 58px;
}

.tile-caption {
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 500;
}

.tile[aria-pressed="true"] .tile-caption {
  color: var(--ink);
}

.money-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.money-sign {
  font: 700 26px/1 var(--numeral);
}

.money-input {
  flex: 1;
  min-width: 0;
  height: 58px;
  padding: 0 16px;
  font: 700 22px/1 var(--numeral);
  font-variant-numeric: lining-nums;
}

.money-input::placeholder {
  color: var(--ink-soft);
  font-weight: 400;
}

.settings-hint {
  margin-top: 12px;
  text-align: left;
}

.sheet-foot {
  padding: 10px var(--gutter) calc(var(--safe-bottom) + 18px);
  border-top: 1px solid var(--felt-line);
  background: var(--felt-raised);
}

.preview {
  display: grid;
  grid-template-columns: repeat(var(--seats, 4), minmax(0, 1fr));
  align-items: center;
  min-height: 46px;
  margin-bottom: 10px;
}

.preview-prompt {
  grid-column: 1 / -1;
  color: var(--on-felt-soft);
  font-size: 17px;
  text-align: center;
}

.preview-cell {
  display: grid;
  gap: 3px;
  padding: 0 3px;
  text-align: center;
}

.preview-name {
  overflow: hidden;
  color: var(--on-felt-soft);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-net {
  font: 700 21px/1 var(--numeral);
  font-variant-numeric: tabular-nums lining-nums;
}

.preview-net.is-up {
  color: var(--gold-bright);
}

.preview-net.is-down {
  color: var(--down-on-felt);
}

/* Results */

.results-head {
  padding: 6px 0 18px;
}

.results-head h1 {
  font: 700 36px/1.1 var(--numeral);
  letter-spacing: -0.01em;
}

.results-head p {
  margin-top: 2px;
  color: var(--on-felt-soft);
}

.panel {
  padding: 4px 16px;
  border-radius: 16px;
  background: var(--ivory);
  color: var(--ink);
  box-shadow:
    0 5px 0 var(--jade-back),
    0 10px 20px rgb(0 0 0 / 35%);
}

.rank-row,
.transfer {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--ivory-shade);
  animation: deal 320ms cubic-bezier(0.2, 0.8, 0.25, 1) both;
  animation-delay: calc(var(--order) * 70ms);
}

.rank-row:last-child,
.transfer:last-child {
  border-bottom: 0;
}

.rank-row {
  gap: 12px;
  min-height: 64px;
}

.rank-place {
  display: grid;
  flex: none;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  color: var(--ink-soft);
  font: 700 17px/1 var(--numeral);
  font-variant-numeric: lining-nums;
}

.rank-row.is-first .rank-place {
  background: var(--gold);
  color: var(--ink);
}

.rank-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-size: 18px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-net {
  flex: none;
  font: 700 29px/1 var(--numeral);
  font-variant-numeric: tabular-nums lining-nums;
}

.settle {
  margin-top: 30px;
}

.section-note {
  margin: -8px 0 12px;
  color: var(--on-felt-soft);
  font-size: 15px;
}

.transfer {
  gap: 12px;
  min-height: 58px;
  padding: 8px 0;
}

.transfer-text {
  flex: 1;
  min-width: 0;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.transfer-who {
  font-size: 17px;
  font-weight: 600;
}

.transfer-verb {
  color: var(--ink-soft);
  font-size: 15px;
  white-space: nowrap;
}

.transfer-amount {
  flex: none;
  font: 700 25px/1 var(--numeral);
  font-variant-numeric: tabular-nums lining-nums;
}

.even-note {
  padding: 18px 0;
  color: var(--ink-soft);
  text-align: center;
}

.results-share {
  grid-column: 1 / -1;
}

.results-actions {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  gap: 12px;
  margin-top: 30px;
}

.secondary {
  align-items: center;
  justify-content: center;
  height: 62px;
  padding: 0 8px;
  text-align: center;
  font: 700 18px/1 var(--numeral);
}

/* Confirmation */

.confirm {
  width: min(340px, calc(100vw - 32px));
  padding: 20px;
  border: 0;
  border-radius: 18px;
  background: var(--ivory);
  color: var(--ink);
}

.confirm[open] {
  animation: fade-in 120ms ease-out;
}

.confirm::backdrop {
  background: rgb(3 16 12 / 70%);
}

.confirm h2 {
  font: 700 22px/1.15 var(--numeral);
}

.confirm p {
  margin-top: 6px;
  color: var(--ink-soft);
}

.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 20px;
}

.confirm .secondary {
  height: 52px;
  background: var(--ivory-shade);
}

.confirm .cta {
  height: 52px;
  font-size: 18px;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@keyframes rise {
  from {
    transform: translateY(100%);
  }
}

@keyframes deal {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
