/* Felosy — game styling. Palette lifted from the physical board:
   deep table green, parchment white, pharaoh gold, hustle red. */

:root {
  --table: #2e5339;        /* board felt green */
  --table-dark: #1d3a27;
  --parchment: #f7f3e8;
  --ink: #23301f;
  --gold: #c9a13b;
  --gold-bright: #e8c766;
  --red: #b3362c;
  --purple: #6d4d9c;       /* Amaan / safe-zone sheet */
  --purple-dark: #4d3573;
  --green-pos: #2f8f57;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overscroll-behavior: none; }
body {
  font-family: "Segoe UI", Tahoma, "Noto Naskh Arabic", sans-serif;
  background: radial-gradient(ellipse at center, var(--table) 0%, var(--table-dark) 100%);
  color: var(--parchment);
  overflow: hidden;
  touch-action: manipulation;
}
.hidden { display: none !important; }
.mobile-only { display: none; }
button { font-family: inherit; cursor: pointer; border: none; border-radius: 10px; touch-action: manipulation; }

/* ------------------------------------------------ start screen ---- */
.screen {
  height: 100vh;
  height: var(--app-height, 100vh); /* real visible height on mobile browsers */
  height: 100dvh;
  width: 100vw;
}
#start-screen { display: flex; align-items: center; justify-content: center; }
.start-card {
  background: var(--parchment); color: var(--ink);
  border: 3px solid var(--gold); border-radius: 18px;
  padding: 36px 42px; width: min(430px, 92vw);
  box-shadow: var(--shadow); text-align: center;
}
.logo { font-size: 44px; margin: 0; color: var(--table-dark); }
.logo-en { font-size: 20px; color: var(--gold); display: block; letter-spacing: 4px; }
.tagline { margin: 6px 0 24px; opacity: 0.75; }
.field { display: block; text-align: start; margin: 14px 0; font-weight: 700; }
.field input {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px;
  font-size: 16px; border: 2px solid #bbb; border-radius: 10px; background: #fff;
}
.field input:focus { outline: none; border-color: var(--gold); }
.count-row { display: flex; gap: 8px; margin-top: 6px; }
.count-btn {
  flex: 1; padding: 8px 0; font-size: 16px; font-weight: 800;
  background: #e5e0d2; color: var(--ink); border: 2px solid transparent; border-radius: 10px;
}
.count-btn.selected { border-color: var(--gold); background: #fff; }
.player-row {
  display: flex; gap: 8px; align-items: center; margin: 8px 0;
}
.player-row input {
  flex: 1; padding: 9px 10px; font-size: 15px; border: 2px solid #bbb; border-radius: 10px; background: #fff;
  min-width: 0;
}
.player-row .gender-mini {
  padding: 8px 14px; font-size: 14px; font-weight: 800;
  background: #e5e0d2; color: var(--ink); border: 2px solid transparent; border-radius: 10px;
}
.player-row .gender-mini.selected { border-color: var(--gold); background: #fff; }
.player-row .color-dot { width: 22px; height: 22px; border-radius: 50%; flex: none; border: 2px solid #0002; }
.gender-row { display: flex; gap: 10px; margin-top: 6px; }
.gender-btn {
  flex: 1; padding: 10px; font-size: 16px; font-weight: 700;
  background: #e5e0d2; color: var(--ink); border: 2px solid transparent;
}
.gender-btn.selected { border-color: var(--gold); background: #fff; box-shadow: 0 0 0 3px #c9a13b33; }
.hint { font-size: 12px; font-weight: 400; opacity: 0.65; margin: 6px 0 0; }
.primary {
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: #3a2c07; font-weight: 800; padding: 10px 22px; font-size: 16px;
  box-shadow: 0 3px 0 #8a6d24;
}
.primary:active { transform: translateY(2px); box-shadow: none; }
.primary:disabled { filter: grayscale(0.8); opacity: 0.6; cursor: default; }
.primary.big { width: 100%; margin-top: 18px; padding: 14px; font-size: 20px; }
.ghost { background: none; color: var(--ink); opacity: 0.6; margin-top: 12px; text-decoration: underline; }

/* ------------------------------------------------ game layout ---- */
#game-screen {
  display: flex; gap: 0;
  height: 100vh; height: var(--app-height, 100vh); height: 100dvh;
}
#board-wrap {
  position: relative; flex: 1 1 auto; height: 100%;
  display: flex; align-items: center; justify-content: center;
  min-width: 0; background: #142b1c; overflow: hidden;
}
#board-frame { position: relative; max-width: 100%; max-height: 100%; }
#board-img {
  max-width: 100%; max-height: 100vh; max-height: var(--app-height, 100vh); max-height: 100dvh;
  display: block; user-select: none; -webkit-touch-callout: none;
}
#spaces-layer, #token { position: absolute; }
#spaces-layer { inset: 0; pointer-events: none; }

.space-marker {
  position: absolute; transform: translate(-50%, -50%);
  width: 3.2%; aspect-ratio: 1; border-radius: 50%;
  border: 2px solid transparent; transition: all 0.25s ease;
}
.space-marker.active {
  border-color: var(--gold-bright);
  background: radial-gradient(circle, #e8c76655 0%, transparent 70%);
  box-shadow: 0 0 18px 6px #e8c76688;
}

#tokens-layer { position: absolute; inset: 0; pointer-events: none; }
.token {
  position: absolute;
  width: 2.4%; aspect-ratio: 1; border-radius: 50%;
  transform: translate(-50%, -50%);
  border: 2.5px solid #fff8e2;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.6);
  transition: left 0.28s ease-in-out, top 0.28s ease-in-out, opacity 0.3s;
  z-index: 5;
  display: grid; place-items: center;
  color: #fff; font-size: 0.7vw; font-weight: 900; text-shadow: 0 1px 2px #0009;
}
.token.inactive { opacity: 0.55; z-index: 4; }
.token.current { box-shadow: 0 0 0 3px #fff8, 0 3px 14px rgba(0,0,0,0.7); }

/* clickable buildings painted on the board art */
.board-btn {
  position: absolute; background: transparent; border: 3px dashed transparent;
  border-radius: 14px; cursor: pointer; z-index: 6;
  transition: border-color 0.25s, background 0.25s;
}
.board-btn:hover, .board-btn.pulse {
  border-color: var(--gold-bright);
  background: radial-gradient(circle, #e8c76622 0%, transparent 75%);
}
.board-btn.pulse { animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { border-color: transparent; } }
#bank-btn   { left: 14%; top: 60%; width: 13.5%; height: 20%; }
#gamaya-btn { left: 71.5%; top: 19%; width: 15%; height: 22%; }

/* pass-and-play handoff banner */
#handoff {
  position: fixed; inset: 0; z-index: 40; display: flex;
  align-items: center; justify-content: center;
  background: rgba(10, 20, 12, 0.65); backdrop-filter: blur(2px);
}
#handoff-inner {
  background: var(--parchment); color: var(--ink);
  border: 3px solid var(--gold); border-radius: 18px;
  padding: 30px 48px; text-align: center; font-size: 26px; font-weight: 900;
  box-shadow: var(--shadow); animation: pop 0.25s ease-out;
}
#handoff-inner .sub { font-size: 15px; font-weight: 600; opacity: 0.7; margin-top: 6px; }
#handoff-inner .dot {
  display: inline-block; width: 18px; height: 18px; border-radius: 50%;
  margin-inline-end: 10px; vertical-align: baseline;
}

/* card flip */
.flip-scene { perspective: 1200px; margin: 0 auto 12px; width: 200px; }
.flip-inner {
  position: relative; width: 200px; height: 277px;
  transform-style: preserve-3d; transition: transform 0.65s cubic-bezier(.4,.1,.2,1);
}
.flip-scene.flipped .flip-inner { transform: rotateY(180deg); }
.flip-face {
  position: absolute; inset: 0; backface-visibility: hidden;
  border-radius: 12px; overflow: hidden; box-shadow: 0 6px 18px rgba(0,0,0,0.35);
}
.flip-face img { width: 100%; height: 100%; object-fit: cover; display: block; }
.flip-face.front { transform: rotateY(180deg); }

/* financed purchase options on Chance cards */
.finance-row { margin-top: 8px; }
.finance-btn {
  flex: 1; padding: 10px 8px; font-size: 13px; font-weight: 800;
  background: #fff; color: var(--table-dark); border: 2px solid var(--table-dark);
}
.finance-btn:disabled { opacity: 0.4; cursor: default; }
.finance-note { font-size: 11.5px; opacity: 0.65; text-align: center; margin-top: 6px; font-weight: 600; }

/* sell buttons in the assets tab */
.sell-btn {
  background: var(--red); color: #fff; font-weight: 800; font-size: 12px;
  padding: 6px 12px; border-radius: 8px; white-space: nowrap;
}
.sell-btn:disabled { background: #b9b2a0; cursor: default; }

/* bank / gam3ya modal forms */
.loan-form { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }
.loan-form label { font-size: 13px; font-weight: 700; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.loan-form input, .loan-form select {
  width: 140px; padding: 8px 10px; font-size: 16px; font-weight: 700;
  border: 2px solid #bbb; border-radius: 8px; text-align: center; background: #fff;
}
.loan-summary { background: #fff; border-radius: 10px; padding: 10px 12px; font-size: 14px; font-weight: 700; }
.loan-summary .warn { color: var(--red); }

/* ------------------------------------------------ side panel ---- */
#side-panel {
  flex: 0 0 min(380px, 38vw); height: 100%; overflow-y: auto;
  background: linear-gradient(180deg, #f9f6ee, #efe9da);
  color: var(--ink); box-shadow: -6px 0 20px rgba(0,0,0,0.35);
  display: flex; flex-direction: column; padding: 14px 16px; gap: 10px;
}
#panel-grip {
  display: none; /* shown only in the mobile bottom-sheet layout */
  width: 40px; height: 5px; border-radius: 3px; background: #00000022;
  margin: 2px auto 4px; flex: none;
}
#panel-toggle-btn {
  display: none; align-items: center; gap: 6px;
  background: var(--table-dark); color: #fff; font-weight: 800; font-size: 12px;
  padding: 10px 14px; white-space: nowrap;
}
#panel-toggle-icon { display: inline-block; transition: transform 0.25s; font-size: 10px; }
#cash-mini {
  font-weight: 900; color: var(--gold-bright); background: var(--table-dark);
  border-radius: 8px; padding: 8px 12px; font-size: 14px; white-space: nowrap;
}
#hud { display: flex; justify-content: space-between; align-items: center; }
#hud-identity { display: flex; flex-direction: column; }
#hud-name { font-size: 20px; font-weight: 800; }
#hud-job { font-size: 13px; opacity: 0.7; }
.zone-chip {
  padding: 4px 12px; border-radius: 999px; font-size: 13px; font-weight: 800; color: #fff;
}
.zone-chip.hustle { background: var(--green-pos); }
.zone-chip.amaan { background: var(--purple); }

#cash-strip {
  display: flex; align-items: baseline; gap: 10px;
  background: var(--table-dark); color: #fff; border-radius: 12px;
  padding: 10px 16px; border: 2px solid var(--gold);
}
.cash-label { font-size: 13px; opacity: 0.8; }
#cash-value { font-size: 26px; font-weight: 900; color: var(--gold-bright); }
#cash-delta { font-size: 15px; font-weight: 800; opacity: 0; transition: opacity 0.3s; }
#cash-delta.show { opacity: 1; }
#cash-delta.pos { color: #7fe3a6; }
#cash-delta.neg { color: #ff9c8f; }

#escape-banner {
  border-radius: 10px; padding: 8px 12px; font-size: 13px; font-weight: 700;
  background: #dcefe2; border: 1.5px solid var(--green-pos); color: #1d4a2f;
}
#escape-banner.amaan { background: #e9e2f5; border-color: var(--purple); color: var(--purple-dark); }
#escape-banner .bar {
  height: 8px; background: #ffffff; border-radius: 99px; margin-top: 6px; overflow: hidden;
}
#escape-banner .fill { height: 100%; background: var(--green-pos); border-radius: 99px; transition: width 0.4s; }
#escape-banner.amaan .fill { background: var(--purple); }

/* dice */
#dice-area { display: flex; align-items: center; gap: 12px; }
#dice-cups { display: flex; gap: 8px; min-height: 44px; }
.die {
  width: 44px; height: 44px; border-radius: 10px; background: #fff;
  border: 2px solid var(--ink); display: grid; place-items: center;
  font-size: 24px; font-weight: 900; color: var(--ink);
  box-shadow: 0 3px 6px rgba(0,0,0,0.25);
}
.die.rolling { animation: shake 0.4s infinite; }
@keyframes shake {
  0%,100% { transform: rotate(-8deg); } 50% { transform: rotate(8deg); }
}

/* tabs */
#tabs { display: flex; gap: 4px; border-bottom: 2px solid #d8d0bc; }
.tab {
  flex: 1; background: none; padding: 8px 2px; font-size: 13px; font-weight: 700;
  color: var(--ink); opacity: 0.55; border-radius: 8px 8px 0 0;
}
.tab.selected { opacity: 1; background: #fff; box-shadow: inset 0 -3px 0 var(--gold); }
#tab-body { flex: 1; overflow-y: auto; font-size: 14px; }

/* ledger */
.ledger-block { margin-bottom: 10px; background: #fff; border-radius: 10px; padding: 10px 12px; }
.ledger-block h3 {
  margin: 0 0 6px; font-size: 13px; letter-spacing: 0.5px;
  color: var(--table-dark); border-bottom: 1.5px solid #eee; padding-bottom: 4px;
}
.ledger-block.amaan h3 { color: var(--purple-dark); }
.lrow { display: flex; justify-content: space-between; padding: 2px 0; }
.lrow .amt { font-weight: 700; font-variant-numeric: tabular-nums; }
.lrow.total { border-top: 1.5px solid #eee; margin-top: 4px; padding-top: 5px; font-weight: 800; }
.lrow .pos { color: var(--green-pos); }
.lrow .neg { color: var(--red); }
.cashflow-line { font-size: 16px; }

/* assets & history & log */
.asset-row {
  background: #fff; border-radius: 10px; padding: 8px 12px; margin-bottom: 6px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.asset-row .meta { font-size: 12px; opacity: 0.65; }
.asset-earn { font-weight: 800; color: var(--green-pos); white-space: nowrap; }
.asset-dormant { color: #a08326; font-size: 12px; font-weight: 700; }
.hrow { display: flex; justify-content: space-between; gap: 8px; padding: 5px 2px; border-bottom: 1px solid #00000010; }
.hrow .d { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.hrow .bal { opacity: 0.55; font-size: 12px; white-space: nowrap; }
.logrow { padding: 5px 2px; border-bottom: 1px solid #00000010; font-size: 13px; }
.logrow .k { font-weight: 800; color: var(--table-dark); }

/* ------------------------------------------------ card modal ---- */
#modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 20, 12, 0.72);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
#card-modal {
  width: min(430px, 92vw); max-height: 88vh; overflow-y: auto;
  background: var(--parchment); color: var(--ink);
  border-radius: 16px; border: 3px solid var(--gold);
  box-shadow: var(--shadow); padding: 22px 24px;
  animation: pop 0.22s ease-out;
}
@keyframes pop { from { transform: scale(0.85); opacity: 0; } }
.card-deck-chip {
  display: inline-block; padding: 3px 12px; border-radius: 999px;
  font-size: 12px; font-weight: 800; color: #fff; margin-bottom: 8px;
}
.card-title { font-size: 22px; font-weight: 900; margin: 2px 0 2px; }
.card-sub { font-size: 14px; opacity: 0.7; margin-bottom: 10px; }
.card-body { font-size: 14px; line-height: 1.7; }
.card-amount { font-size: 26px; font-weight: 900; margin: 10px 0; }
.card-amount.pos { color: var(--green-pos); }
.card-amount.neg { color: var(--red); }
.card-facts { background: #fff; border-radius: 10px; padding: 8px 12px; margin: 10px 0; }
.card-actions { display: flex; gap: 10px; margin-top: 16px; }
.card-actions button { flex: 1; padding: 12px; font-size: 16px; font-weight: 800; }
.secondary { background: #d9d2c0; color: var(--ink); }
.qty-row { display: flex; align-items: center; gap: 12px; justify-content: center; margin-top: 10px; }
.qty-row button { width: 42px; height: 42px; font-size: 22px; font-weight: 900; background: #d9d2c0; }
.qty-row .qty { font-size: 22px; font-weight: 900; min-width: 40px; text-align: center; }

/* deck colors */
.deck-chance { background: #b98a2c; } .deck-hustle { background: #2c7a4d; }
.deck-luck { background: var(--red); } .deck-market { background: #2c5f9e; }
.deck-responsibility { background: #6b7280; } .deck-marriage { background: #c05299; }
.deck-investment { background: var(--purple); } .deck-dream { background: #3d7ea6; }
.deck-event { background: #444; }

/* win / game over */
.endgame { text-align: center; }
.endgame h2 { font-size: 30px; margin: 4px 0; }
.endgame .trophy { font-size: 60px; }

/* ------------------------------------------------ responsive ---- */
/* Mobile layout is opt-in via body.mobile-ui — the start screen lets the
   player choose Phone or PC mode, so nothing is guessed from pixel widths. */
body.mobile-ui .mobile-only { display: flex; }

/* the board becomes the whole screen; the ledger becomes a bottom sheet
   that slides up on demand, so the board is never cramped by default */
body.mobile-ui #game-screen { display: block; position: relative; overflow: hidden; }
body.mobile-ui #board-wrap {
  height: 100%; width: 100%;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* the persistent action bar: always visible regardless of sheet state.
   it stays pinned to the true viewport because #side-panel is animated
   via `bottom`, not `transform` — transform would create a new
   containing block and trap this fixed child inside the sliding sheet. */
body.mobile-ui #dice-area {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 28;
  background: linear-gradient(0deg, #efe9da, #f9f6eeee);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -4px 16px rgba(0,0,0,0.3);
  justify-content: center;
}
body.mobile-ui #dice-area #dice-cups { min-height: 0; }
body.mobile-ui #roll-btn, body.mobile-ui #endturn-btn {
  flex: 1; padding: 14px 10px; font-size: 15px; min-height: 48px;
}

body.mobile-ui #side-panel {
  position: fixed; left: 0; right: 0; bottom: calc(-1 * (100dvh - 8px));
  height: calc(100dvh - 8px);
  flex: none;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -10px 30px rgba(0,0,0,0.5);
  z-index: 26;
  padding: 6px 16px 90px; /* bottom padding clears the fixed action bar */
  transition: bottom 0.32s cubic-bezier(.4,0,.2,1);
}
body.mobile-ui #side-panel.expanded { bottom: 0; }
body.mobile-ui #panel-grip { display: block; }
body.mobile-ui #panel-toggle-btn { display: flex; }
body.mobile-ui #cash-mini { display: flex; align-items: center; }

/* space markers and buttons stay comfortably tappable at any board size */
body.mobile-ui .board-btn { border-width: 2px; }

body.mobile-ui #card-modal {
  width: min(430px, 94vw); max-height: 92dvh; padding: 16px 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}
body.mobile-ui .card-actions button { min-height: 48px; }
body.mobile-ui #handoff-inner { padding: 22px 28px; font-size: 21px; max-width: 92vw; }

@media (orientation: landscape) {
  body.mobile-ui #side-panel { padding-bottom: 76px; }
  body.mobile-ui #dice-area { padding: 6px 10px calc(6px + env(safe-area-inset-bottom, 0px)); }
  body.mobile-ui #roll-btn, body.mobile-ui #endturn-btn { min-height: 40px; padding: 10px; }
  body.mobile-ui .flip-scene, body.mobile-ui .flip-inner { width: 150px; }
  body.mobile-ui .flip-inner { height: 208px; }
}

/* wrong-way overlay when the player chose an orientation */
#force-rotate {
  position: fixed; inset: 0; z-index: 70; display: flex;
  align-items: center; justify-content: center;
  background: rgba(10, 20, 12, 0.9);
}
#force-rotate-inner { text-align: center; font-size: 54px; }
#force-rotate-inner .rot-ico {
  display: inline-block;
  animation: spin-nudge 1.6s ease-in-out infinite;
}
#force-rotate-text {
  font-size: 18px; font-weight: 800; color: var(--parchment); margin-top: 10px;
}
@keyframes spin-nudge { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(90deg); } }

/* start-screen niceties for the mode chooser */
#orient-field.hidden-soft { display: none; }
#mode-row .count-btn, #orient-row .count-btn { font-size: 14px; padding: 10px 4px; }
