* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root { --menu-surface: #43e1ba; --panel-surface: #8cbce0; }

html,
body {
  height: 100%;
  overflow: hidden;
  background: var(--menu-surface);
  color: #0c3b30;
  font-family: "Vazirmatn", "IRANSansX", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  touch-action: none;
}

button,
textarea,
input { font: inherit; }

#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
#board { position: relative; flex: 1 1 auto; }
canvas { display: block; width: 100%; height: 100%; touch-action: none; }
#cv { transition: filter 520ms ease, transform 520ms ease; }
#board.isGameOver #cv { filter: blur(7px) saturate(.82); transform: scale(1.025); }

.screen {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 26px 22px calc(26px + env(safe-area-inset-bottom));
  overflow: auto;
  text-align: center;
  background: var(--panel-surface);
}

.screen.isLeaving { pointer-events: none; animation: screenFadeOut 240ms ease forwards; }
.gameReveal { position: absolute; z-index: 3; inset: 0; display: none; overflow: hidden; pointer-events: none; }
.gameReveal.armed { display: block; }
.gameReveal span { position: absolute; right: 0; left: 0; height: 50%; }
.gameRevealTop { background: var(--menu-surface); }
.gameRevealBottom { background: var(--menu-surface); }
.gameRevealTop { top: 0; }
.gameRevealBottom { bottom: 0; }
.gameReveal.playing .gameRevealTop { animation: revealTop 1080ms cubic-bezier(.22, .8, .25, 1) forwards; }
.gameReveal.playing .gameRevealBottom { animation: revealBottom 1080ms cubic-bezier(.22, .8, .25, 1) forwards; }

@keyframes screenFadeOut { to { opacity: 0; } }
@keyframes revealTop { to { transform: translateY(-100%); } }
@keyframes revealBottom { to { transform: translateY(100%); } }

@media (prefers-reduced-motion: reduce) {
  .screen.isLeaving,
  .gameReveal.playing .gameRevealTop,
  .gameReveal.playing .gameRevealBottom { animation-duration: 1ms; }
  #cv,
  #gameover { transition-duration: 1ms; }
}

.screen h1 { color: #0c3b30; font-size: 52px; font-weight: 900; letter-spacing: 10px; }
.screen h2 { color: #0c3b30; font-size: 20px; font-weight: 800; letter-spacing: 2px; }
.screen p { max-width: 360px; color: #0c3b30; font-size: 14px; line-height: 1.5; opacity: .8; }
#gameover { z-index: 7; background: rgb(140 188 224 / 84%); opacity: 0; transform: translateY(12px); transition: opacity 420ms ease, transform 420ms ease; }
#gameover.isVisible { opacity: 1; transform: translateY(0); }

.profileScreen {
  z-index: 10;
  background: var(--menu-surface);
  color: #0c3b30;
}

.profileCard {
  display: flex;
  width: min(100%, 356px);
  flex-direction: column;
  align-items: stretch;
  gap: 14px;
  text-align: start;
}

.profileCard h1 { margin-block: 2px 0; text-align: center; font-size: 60px; font-weight: 300; letter-spacing: 13px; }
.profileCard h2 { text-align: center; font-weight: 500; letter-spacing: 0; }
.profileCard > p:not(.eyebrow, .msg) { text-align: center; }
.eyebrow { color: #54716a; font-size: 11px !important; font-weight: 700; letter-spacing: 1.8px; text-align: center; text-transform: uppercase; }
.fieldLabel { color: #35544c; font-size: 13px; font-weight: 600; }
.profileCard input {
  width: 100%;
  border: 1px solid #bdc9c5;
  border-radius: 12px;
  padding: 14px 15px;
  background: #fff;
  color: #0c3b30;
  font-size: 16px;
  outline: none;
}
.profileCard input:focus { border-color: #0c3b30; box-shadow: 0 0 0 3px rgb(12 59 48 / 10%); }
.localePicker { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 4px; border-radius: 14px; background: #e3e8e6; }
.localePicker button { min-height: 42px; cursor: pointer; border: 0; border-radius: 10px; background: transparent; color: #54716a; font-size: 14px; font-weight: 500; }
.localePicker button[aria-pressed="true"] { background: #fff; color: #0c3b30; box-shadow: 0 1px 3px rgb(12 59 48 / 12%); }
.profileCard .primaryText { margin-top: 8px; width: 100%; }

.textAction,
.menuLink {
  cursor: pointer;
  border: 0;
  padding: 4px 0;
  background: transparent;
  color: #0c3b30;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: .02em;
}
.textAction:hover,
.textAction:focus-visible,
.menuLink:hover,
.menuLink:focus-visible { color: #0a7d60; outline: none; }
.primaryText { color: #0a7d60; font-weight: 700; }
.themeList { display: flex; flex-direction: column; gap: 4px; width: 100%; }
.themeCard { display: flex; align-items: center; gap: 12px; cursor: pointer; border: 0; border-inline-start: 2px solid transparent; padding: 10px 12px; background: transparent; }
.themeCard.sel { border-color: #0c3b30; }
.swatches { display: flex; gap: 6px; }
.sw { width: 22px; height: 22px; border: 1px solid rgb(0 0 0 / 15%); border-radius: 50%; }
.themeName { flex: 1; color: #0c3b30; font-weight: 800; text-align: start; }
.row { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.hidden { display: none !important; }
.toggle { display: flex; align-items: center; gap: 8px; color: #0c3b30; font-size: 14px; font-weight: 700; }
.msg { min-height: 14px; color: #b00; font-size: 12px; font-weight: 700; }
.onlineStatus { min-height: 22px; font-weight: 700; }
.roomInfo { display: flex; flex-direction: column; gap: 4px; min-width: 250px; border-radius: 16px; padding: 16px; background: rgb(255 255 255 / 55%); }
.roomInfo span { font-size: 12px; font-weight: 800; letter-spacing: 2px; }
.roomInfo strong { font-size: 34px; letter-spacing: 6px; }
.roomInfo small { font-size: 12px; opacity: .8; }
.joinBox { display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 320px; }
.joinBox label { font-size: 12px; font-weight: 800; letter-spacing: 1px; }
.joinBox input { min-width: 0; flex: 1; border: 2px solid #0c3b30; border-radius: 18px; padding: 12px; background: #fff; color: #0c3b30; font-size: 16px; font-weight: 800; letter-spacing: 2px; text-align: center; }
.textBtn { cursor: pointer; border: 0; background: transparent; color: #0c3b30; font-size: 13px; font-weight: 800; text-decoration: underline; }
.matchExit { position: absolute; z-index: 6; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); display: grid; width: 40px; height: 40px; cursor: pointer; place-items: center; border: 0; border-radius: 50%; background: rgb(255 255 255 / 86%); color: #0c3b30; box-shadow: 0 2px 8px rgb(12 59 48 / 18%); }
.matchExit:hover,
.matchExit:focus-visible { background: #fff; color: #b23b3b; outline: none; }
.matchExit svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }
.confirmDialog { position: absolute; z-index: 8; inset: 0; display: grid; place-items: center; padding: 24px; background: rgb(12 59 48 / 24%); }
.confirmCard { display: flex; width: min(100%, 280px); flex-direction: column; gap: 18px; padding: 22px; border-radius: 16px; background: var(--panel-surface); box-shadow: 0 12px 36px rgb(0 0 0 / 24%); text-align: center; }
.confirmCard p { color: #0c3b30; font-size: 15px; font-weight: 600; line-height: 1.6; }

.menuScreen { justify-content: center; gap: 32px; background: var(--menu-surface); }
.menuScreen h1 { color: #0c3b30; font-size: clamp(52px, 16vw, 86px); font-weight: 300; letter-spacing: .22em; text-indent: .22em; }
.mainMenu { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.menuLink { font-size: 19px; font-weight: 400; }
.iconButton { position: absolute; top: max(18px, env(safe-area-inset-top)); inset-inline-end: 18px; cursor: pointer; border: 0; padding: 6px; background: transparent; color: #54716a; font-size: 22px; line-height: 1; }
.iconButton:hover,
.iconButton:focus-visible { color: #0c3b30; outline: none; }
.settingsScreen { justify-content: flex-start; gap: 18px; padding-top: max(32px, calc(22px + env(safe-area-inset-top))); }
.screenHeader { display: flex; width: min(100%, 380px); align-items: center; justify-content: space-between; }
.screenHeader h2 { margin: 0; }
.settingsSection { display: flex; width: min(100%, 560px); flex-direction: column; align-items: stretch; gap: 9px; text-align: start; }
.settingsSection h3 { color: #35544c; font-size: 12px; font-weight: 800; letter-spacing: .08em; }
.settingsInputRow { display: flex; align-items: center; gap: 12px; }
.settingsInputRow input,
.themeBuilder > input { min-width: 0; width: 100%; border: 1px solid #bdc9c5; border-radius: 10px; padding: 10px 12px; background: #fff; color: #0c3b30; outline: none; }
.settingsInputRow input:focus,
.themeBuilder > input:focus { border-color: #0c3b30; box-shadow: 0 0 0 3px rgb(12 59 48 / 10%); }
.settingsInputRow .textAction { flex: 0 0 auto; }
.themeWorkbench { display: grid; grid-template-columns: minmax(118px, .75fr) minmax(0, 1.25fr); align-items: start; gap: 18px; padding: 16px; border: 1px solid #d9e0dd; border-radius: 16px; background: rgb(255 255 255 / 42%); }
.themePreviewPanel { display: flex; flex-direction: column; gap: 9px; }
.themePreviewCanvas { width: 100%; max-width: 180px; aspect-ratio: 1 / 1.8; height: auto; border-radius: 10px; box-shadow: 0 3px 12px rgb(12 59 48 / 14%); }
.themeBuilder { display: flex; min-width: 0; flex-direction: column; gap: 9px; }
.colorGrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.colorField { display: flex; min-width: 0; align-items: center; justify-content: space-between; gap: 6px; color: #35544c; font-size: 11px; font-weight: 600; }
.colorField span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.colorField input { width: 28px; height: 25px; cursor: pointer; border: 0; padding: 0; background: transparent; }
.themeBuilder .textAction { align-self: start; margin-top: 2px; }
.fingerPicker { display: flex; flex-direction: column; gap: 6px; }
.fingerPicker h4 { color: #35544c; font-size: 11px; font-weight: 800; letter-spacing: .04em; }
.fingerModelList { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; }
.fingerModelCard { display: flex; min-width: 0; cursor: pointer; flex-direction: column; align-items: center; gap: 2px; border: 1px solid transparent; border-radius: 8px; padding: 4px 2px; background: rgb(255 255 255 / 35%); color: #35544c; font-size: 9px; font-weight: 700; }
.fingerModelCard.sel { border-color: #0c3b30; background: rgb(255 255 255 / 70%); }
.fingerModelCard:focus-visible { outline: 2px solid #0c3b30; outline-offset: 1px; }
.fingerModelPreview { width: 100%; height: 40px; }
.themeCollection { gap: 3px; }

@media (max-width: 390px) {
  .themeWorkbench { grid-template-columns: 112px minmax(0, 1fr); gap: 12px; padding: 12px; }
  .colorGrid { grid-template-columns: 1fr; }
  .fingerModelList { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .themePreviewCanvas { max-width: 112px; }
}

#toast {
  position: absolute;
  z-index: 5;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  border-radius: 20px;
  padding: 8px 16px;
  background: rgb(0 0 0 / 70%);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  transition: opacity .25s;
}

#toast.show { opacity: 1; }
