:root {
  --ink: #17324d;
  --red: #ff5b70;
  --red-deep: #db3055;
  --blue: #4e82ff;
  --blue-deep: #2350dd;
  --panel: rgba(255, 255, 255, 0.72);
  --shadow: 0 24px 60px rgba(40, 54, 88, 0.18);
  --radius-xl: 32px;
  --radius-lg: 24px;
  --bg-default:
    radial-gradient(circle at top left, rgba(255, 191, 71, 0.75), transparent 28%),
    radial-gradient(circle at top right, rgba(78, 130, 255, 0.25), transparent 20%),
    linear-gradient(180deg, #fff4cb 0%, #fff9f1 50%, #eef7ff 100%);
  --bg-red:
    radial-gradient(circle at top left, rgba(255, 140, 160, 0.65), transparent 35%),
    radial-gradient(circle at bottom right, rgba(219, 48, 85, 0.55), transparent 40%),
    linear-gradient(160deg, #ff8aa0 0%, #ff5b70 55%, #c21f45 100%);
  --bg-blue:
    radial-gradient(circle at top left, rgba(140, 185, 255, 0.65), transparent 35%),
    radial-gradient(circle at bottom right, rgba(35, 80, 221, 0.55), transparent 40%),
    linear-gradient(160deg, #8cb9ff 0%, #4e82ff 55%, #1e3fa8 100%);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  font-family: "Trebuchet MS", "Avenir Next", sans-serif;
  color: var(--ink);
  background: var(--bg-default);
  transition: background 320ms ease, color 320ms ease;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
  touch-action: pan-x pan-y;
}


body.turn-red {
  background: var(--bg-red);
  color: white;
}

body.turn-blue {
  background: var(--bg-blue);
  color: white;
}

body {
  padding: 16px;
}

button {
  font: inherit;
  cursor: pointer;
  border: 0;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.app-shell {
  max-width: 1400px;
  margin: 0 auto;
  min-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.sidebar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
}

body.turn-red .sidebar,
body.turn-blue .sidebar {
  color: white;
}

.sidebar__title {
  grid-column: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 4px;
}

.sidebar__title h1 {
  font-size: clamp(1.8rem, 2.6vw, 2.4rem);
}

.sidebar__subtitle {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  opacity: 0.78;
  margin: 0;
}

body.turn-red .sidebar__subtitle,
body.turn-blue .sidebar__subtitle {
  opacity: 0.95;
}

.sidebar__actions {
  grid-column: 3;
  justify-self: end;
  display: flex;
  gap: 10px;
}

body.layout-sidebar .app-shell {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 20px;
}

body.layout-sidebar main#app {
  flex: 1 1 0;
  min-width: 0;
}

body.layout-sidebar .sidebar {
  flex: 0 0 auto;
  width: auto;
  max-width: 200px;
  position: sticky;
  top: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 0;
  text-align: left;
  background: transparent;
  border: 0;
  box-shadow: none;
  backdrop-filter: none;
  border-radius: 0;
}

body.layout-sidebar .sidebar__title h1 {
  font-size: 1.4rem;
  opacity: 0.9;
}

body.layout-sidebar .sidebar__subtitle {
  font-size: 0.85rem;
  opacity: 0.7;
}

body.layout-sidebar .sidebar__actions .ghost-button {
  background: rgba(255, 255, 255, 0.55);
  box-shadow: none;
}

body.layout-sidebar.turn-red .sidebar__actions .ghost-button,
body.layout-sidebar.turn-blue .sidebar__actions .ghost-button {
  background: rgba(255, 255, 255, 0.18);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

body.layout-sidebar .sidebar__title {
  align-items: flex-start;
  text-align: left;
}

body.layout-sidebar .sidebar__actions {
  justify-self: stretch;
  flex-direction: column;
  margin-top: auto;
}

body.layout-sidebar .sidebar__actions .cta-button,
body.layout-sidebar .sidebar__actions .ghost-button {
  width: 100%;
  min-width: 0;
}

.section-kicker {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.78rem;
  font-weight: 800;
  color: rgba(23, 50, 77, 0.68);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 3.4vw, 3.4rem);
  line-height: 0.94;
}

h2 {
  font-size: clamp(1.6rem, 2.6vw, 2.6rem);
  line-height: 1;
}

h3 {
  font-size: 1.35rem;
}

.screen-stack {
  position: relative;
  flex: 1;
  display: grid;
}

.screen {
  display: none;
  animation: rise 240ms ease;
}

.screen.active {
  display: grid;
  gap: 18px;
}

.screen.active#setupScreen {
  align-content: center;
  justify-items: center;
}

.win-card {
  background: var(--panel);
  border: 2px solid rgba(255, 255, 255, 0.48);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

.support-copy {
  color: rgba(23, 50, 77, 0.78);
  line-height: 1.5;
}

.setup-grid {
  width: min(100%, 980px);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
}

.ghost-button,
.cta-button {
  transition: transform 180ms ease, box-shadow 180ms ease, opacity 180ms ease;
}

.player-door {
  position: relative;
  display: flex;
  padding: 28px;
  min-height: 380px;
  border-radius: 28px;
  text-align: left;
  color: white;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.player-door__content {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.player-door__footer {
  margin-top: auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
}

.player-door__accent {
  position: absolute;
  width: 86%;
  height: auto;
  color: rgba(0, 0, 0, 0.34);
  pointer-events: none;
  z-index: 0;
  display: none;
}

.player-door.is-chosen .player-door__accent {
  display: block;
}

.player-door.red {
  background: linear-gradient(145deg, var(--red), #ff8b65);
}

.player-door.blue {
  background: linear-gradient(145deg, var(--blue), #63cbff);
}

.player-door__badge,
.starter-state,
.player-door__action {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  font-size: 0.92rem;
  font-weight: 800;
}



.starter-state,
.player-door__action,
.ghost-button,
.cta-button {
  border-radius: 18px;
  font-weight: 900;
}

.player-door__action,
.starter-state {
  padding: 14px 12px;
  justify-content: center;
  text-align: center;
  width: 100%;
}

.player-door__action {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.92);
}

.player-door__action.is-chosen {
  background: rgba(255, 255, 255, 0.24);
  color: white;
  cursor: default;
}

.starter-state {
  background: rgba(255, 255, 255, 0.18);
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.26);
}

.starter-state.active {
  background: rgba(255, 255, 255, 0.95);
  color: var(--ink);
  border-color: rgba(255, 255, 255, 0.95);
}

.starter-state:disabled {
  opacity: 0.52;
  cursor: default;
}

.ghost-button {
  padding: 12px 16px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 10px 24px rgba(55, 70, 108, 0.12);
}

.cta-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 20px;
  min-width: 168px;
  min-height: 52px;
  width: auto;
  background: linear-gradient(180deg, #40c463, #269b49);
  color: white;
  box-shadow: 0 18px 34px rgba(38, 155, 73, 0.26);
}

.cta-button:disabled {
  opacity: 0.46;
  cursor: default;
  box-shadow: none;
}

.cta-button.is-compact {
  min-width: 0;
  min-height: 0;
  padding: 10px 16px;
  font-size: 0.95rem;
  box-shadow: 0 10px 20px rgba(38, 155, 73, 0.22);
}

.end-turn-fab {
  position: fixed;
  left: 16px;
  bottom: 16px;
  transform: none;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 22px 14px 18px;
  border-radius: 999px;
  background: linear-gradient(180deg, #40c463, #269b49);
  color: white;
  font-weight: 900;
  font-size: 1rem;
  box-shadow: 0 4px 10px rgba(38, 155, 73, 0.18);
  z-index: 20;
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.end-turn-fab svg {
  width: 22px;
  height: 22px;
  display: block;
}

.end-turn-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(38, 155, 73, 0.24);
}

.board {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 14px;
}

body.layout-sidebar .board {
  align-content: start;
  overflow-y: auto;
}

.character-card {
  position: relative;
  padding: 0;
  background: transparent;
  border-radius: 20px;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 2px solid rgba(255, 255, 255, 0.82);
}

.card-front {
  position: absolute;
  inset: 0;
  display: block;
  border-radius: 20px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.92);
}

.portrait {
  position: absolute;
  inset: 0;
  display: block;
  background: linear-gradient(135deg, #7f7fd5, #86a8e7);
  transition: filter 220ms ease;
}

.portrait-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card-name {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 12px;
  font-weight: 900;
  font-size: 1rem;
  color: white;
  text-align: center;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.55) 100%);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
}

.character-card.closed .portrait {
  filter: grayscale(1) brightness(0.72) contrast(0.9);
}

.character-card.closed .card-front {
  opacity: 0.72;
}

.character-card.closed .card-name {
  display: none;
}

.character-card.closed::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 20px;
  background: rgba(23, 50, 77, 0.18);
  pointer-events: none;
}

.secret-portrait {
  width: 120px;
  height: 120px;
  border-radius: 22px;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #7f7fd5, #86a8e7);
  color: white;
  font-size: 2.3rem;
  font-weight: 900;
  box-shadow: inset 0 -10px 18px rgba(0, 0, 0, 0.12);
}

.secret-name {
  font-weight: 900;
  font-size: 1.6rem;
}

.handoff-screen {
  place-items: center;
  align-content: center;
  min-height: calc(100vh - 120px);
}

.handoff-card {
  position: relative;
  width: min(92vw, 720px);
  min-height: min(70vh, 520px);
  text-align: center;
  padding: 48px 40px;
  border-radius: 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  color: white;
  overflow: hidden;
  box-shadow: 0 28px 60px rgba(15, 29, 48, 0.32);
}

body.turn-red .handoff-card {
  background: linear-gradient(160deg, #ff8aa0 0%, #ff5b70 55%, #c21f45 100%);
}

body.turn-blue .handoff-card {
  background: linear-gradient(160deg, #8cb9ff 0%, #4e82ff 55%, #1e3fa8 100%);
}

.handoff-card__silhouette {
  width: 180px;
  height: 180px;
  color: rgba(255, 255, 255, 0.35);
  margin-bottom: 4px;
}

.handoff-card__kicker {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.85rem;
  font-weight: 800;
  opacity: 0.85;
}

.handoff-card__copy {
  max-width: 420px;
  line-height: 1.5;
  opacity: 0.92;
}

.handoff-card h2 {
  font-size: clamp(2rem, 4vw, 3.2rem);
}

#winScreen.active {
  place-items: center;
  align-content: center;
}

.win-card {
  width: min(92vw, 360px);
  padding: 24px;
  border-radius: 28px;
  display: grid;
  gap: 14px;
  text-align: center;
  justify-items: center;
  background:
    radial-gradient(circle at top, rgba(255, 191, 71, 0.55), transparent 55%),
    rgba(255, 255, 255, 0.92);
}

.win-card.is-mistake {
  background:
    radial-gradient(circle at top, rgba(255, 91, 112, 0.45), transparent 55%),
    rgba(255, 255, 255, 0.92);
}

.win-card.is-mistake h2 {
  color: var(--red-deep);
}

.win-card h2 {
  font-size: clamp(1.5rem, 2.4vw, 2rem);
}

.win-card .secret-portrait {
  width: 140px;
  height: 140px;
}

.win-card .secret-name {
  font-size: 1.4rem;
}

.win-secret {
  display: grid;
  gap: 8px;
  justify-items: center;
}

.secret-dialog {
  border: 0;
  padding: 0;
  background: transparent;
}

.secret-dialog::backdrop {
  background: rgba(18, 31, 47, 0.5);
  backdrop-filter: blur(8px);
}

.secret-card {
  width: min(92vw, 440px);
  padding: 28px;
  border-radius: 34px;
  background: linear-gradient(180deg, #fffdf8, #fff2d4);
  display: grid;
  justify-items: center;
  gap: 16px;
  box-shadow: 0 28px 70px rgba(15, 29, 48, 0.25);
}

.secret-card .secret-portrait {
  width: min(70vw, 280px);
  height: min(70vw, 280px);
}

.secret-card .secret-name {
  font-size: 2.2rem;
}

.confirm-card {
  text-align: center;
}

.confirm-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.is-hidden {
  display: none;
}

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

.player-door__action:hover:not(.is-chosen),
.starter-state:hover:not(:disabled),
.ghost-button:hover,
.cta-button:hover:not(:disabled),
.character-card:hover {
  transform: translateY(-2px);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 980px) {
  body.layout-sidebar .app-shell {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  body.layout-sidebar .sidebar {
    position: static;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    flex-direction: row;
    gap: 10px;
    padding: 6px 12px;
    text-align: center;
  }

  body.layout-sidebar .sidebar__title {
    grid-column: 2;
    align-items: center;
    text-align: center;
  }

  body.layout-sidebar .sidebar__title h1 {
    font-size: 1.3rem;
  }

  body.layout-sidebar .sidebar__actions {
    grid-column: 3;
    justify-self: end;
    flex-direction: row;
    margin-top: 0;
  }

  body.layout-sidebar .sidebar__actions .cta-button,
  body.layout-sidebar .sidebar__actions .ghost-button {
    width: auto;
  }

  .setup-grid {
    grid-template-columns: 1fr;
  }

  .player-door {
    min-height: 300px;
  }

  .board {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
  }


  .character-card {
    border-radius: 14px;
    border-width: 1.5px;
  }

  .card-front {
    border-radius: 14px;
  }

  .card-name {
    padding: 5px 6px;
    font-size: 0.78rem;
  }

  .character-card.closed::after {
    border-radius: 14px;
  }

  .screen.active#setupScreen {
    min-height: auto;
    align-content: start;
  }
}

@media (min-width: 981px) and (max-height: 880px) {
  body {
    padding: 8px;
  }

  body.layout-sidebar .app-shell {
    gap: 8px;
  }

  body.layout-sidebar .sidebar {
    max-width: 160px;
    gap: 10px;
  }

  .board {
    gap: 8px;
  }


  .card-name {
    padding: 4px 6px;
    font-size: 0.75rem;
  }

  .character-card {
    border-radius: 14px;
  }

  .card-front {
    border-radius: 14px;
  }

  .character-card.closed::after {
    border-radius: 14px;
  }
}

@media (max-width: 980px) and (orientation: landscape) {
  body {
    padding: 6px;
  }

  body.layout-sidebar .app-shell {
    gap: 4px;
  }

  body.layout-sidebar .sidebar {
    padding: 4px 12px;
  }

  .board {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 10px;
    max-width: min(100%, calc((100dvh - 100px) / 5 * 6 + 50px));
    margin-inline: auto;
  }

  .card-name {
    padding: 3px 4px;
    font-size: 0.7rem;
  }

  .character-card {
    border-radius: 12px;
    border-width: 1px;
  }

  .card-front {
    border-radius: 12px;
  }

  .character-card.closed::after {
    border-radius: 12px;
  }

  .end-turn-fab {
    padding: 10px 16px 10px 12px;
    font-size: 0.9rem;
  }

  .end-turn-fab svg {
    width: 18px;
    height: 18px;
  }
}

@media (max-width: 640px) {
  body {
    padding: 8px;
  }

  .app-shell {
    min-height: calc(100dvh - 16px);
    gap: 8px;
  }

  .board {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }


  .character-card {
    border-radius: 10px;
    border-width: 1px;
  }

  .card-front {
    border-radius: 10px;
  }

  .card-name {
    font-size: 0.72rem;
    padding: 4px 5px;
  }

  .character-card.closed::after {
    border-radius: 10px;
  }

  .sidebar__subtitle {
    font-size: 0.8rem;
  }
}

/* Update banner */
.update-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px 20px;
  background: var(--ink);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 500;
  z-index: 9999;
  transform: translateY(100%);
  transition: transform 0.3s ease;
}

.update-banner.visible {
  transform: translateY(0);
}

.update-banner button {
  background: #ffb703;
  color: var(--ink);
  border: none;
  border-radius: 8px;
  padding: 8px 18px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}
