/* ===================== Reset & Base ===================== */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg-1: #0d0b1e;
  --bg-2: #1a1436;
  --surface: #211a42;
  --surface-2: #2a2158;
  --text: #f4f2ff;
  --text-dim: #b6aede;
  --accent: #ffce45;
  --danger: #ff5c6c;

  --police: #3d7bff;
  --police-bg: #10214d;
  --culprit: #ff4d5e;
  --culprit-bg: #4a1420;
  --informant: #2ecc71;
  --informant-bg: #113a26;
  --witness: #f5c518;
  --witness-bg: #4a3d0c;
  --independent: #b26af0;
  --independent-bg: #331c4d;

  --radius-lg: 22px;
  --radius-md: 16px;
  --shadow: 0 10px 30px rgba(0,0,0,0.35);
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(circle at 50% 0%, var(--bg-2), var(--bg-1) 70%);
  color: var(--text);
  font-family: 'IBM Plex Sans Thai', 'Mitr', sans-serif;
  overscroll-behavior: none;
}

h1, h2, h3, .btn {
  font-family: 'Mitr', 'IBM Plex Sans Thai', sans-serif;
}

button {
  font-family: inherit;
  cursor: pointer;
}

.page {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 20px 16px 40px;
  position: relative;
}

/* ===================== Shared elements ===================== */
.back-home {
  display: inline-block;
  margin-bottom: 12px;
  color: var(--text-dim);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.85rem;
}
.back-home:active {
  opacity: 0.7;
}

/* ===================== Screens ===================== */
.screen {
  display: none;
  animation: fadeSlideIn 0.35s ease;
}
.screen.active {
  display: block;
}

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

/* ===================== Shared elements ===================== */
.card {
  background: linear-gradient(160deg, var(--surface), var(--surface-2));
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255,255,255,0.06);
  margin-bottom: 18px;
}

.btn {
  display: block;
  width: 100%;
  border: none;
  border-radius: var(--radius-md);
  padding: 16px 18px;
  font-size: 1.05rem;
  font-weight: 600;
  color: #fff;
  transition: transform 0.12s ease, filter 0.12s ease;
}
.btn:active {
  transform: scale(0.97);
  filter: brightness(0.92);
}
.btn-big {
  padding: 18px;
  font-size: 1.15rem;
}
.btn-primary {
  background: linear-gradient(135deg, #ff8a3d, var(--accent));
  color: #241300;
  box-shadow: 0 8px 20px rgba(255, 206, 69, 0.25);
}
.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.15);
  margin-top: 8px;
}
.btn-action {
  margin-bottom: 12px;
  text-align: left;
}
.btn-unlock {
  background: linear-gradient(135deg, #2f6fed, #3d7bff);
}
.btn-accuse {
  background: linear-gradient(135deg, #d63447, var(--danger));
}
.btn-indep {
  background: linear-gradient(135deg, #7b3fc4, var(--independent));
}

.section-label {
  font-weight: 600;
  margin: 0 0 12px;
  color: var(--text-dim);
}

.info-box {
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin: 14px 0;
  border: 1px solid rgba(255,255,255,0.1);
}
.info-title {
  margin: 0 0 6px;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-dim);
}
.info-text {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
  line-height: 1.4;
}
.info-note {
  margin: 8px 0 0;
  font-size: 0.82rem;
  color: var(--text-dim);
}
.info-note-big {
  font-size: 0.95rem;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.6;
}

/* ===================== Start Screen ===================== */
.start-wrap {
  text-align: center;
  padding-top: 20px;
}
.badge-emoji {
  font-size: 3rem;
  margin-bottom: 6px;
  animation: floatY 2.4s ease-in-out infinite;
}
@keyframes floatY {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
.game-title {
  font-size: 1.8rem;
  line-height: 1.3;
  margin: 6px 0 10px;
}
.game-title span {
  color: var(--accent);
}
.game-subtitle {
  color: var(--text-dim);
  font-size: 0.95rem;
  margin-bottom: 24px;
}
.start-card {
  text-align: left;
}
.count-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.count-btn {
  padding: 14px 0;
  border-radius: 14px;
  border: 2px solid rgba(255,255,255,0.12);
  background: var(--bg-1);
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 700;
}
.count-btn.selected {
  background: linear-gradient(135deg, #ff8a3d, var(--accent));
  color: #241300;
  border-color: transparent;
}
.count-hint {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
  margin: 14px 0 0;
}

/* ===================== Reveal Screen ===================== */
.progress-text {
  text-align: center;
  color: var(--text-dim);
  font-weight: 600;
  margin-bottom: 14px;
}
.reveal-hidden-card {
  text-align: center;
  padding: 40px 20px;
}
.pass-icon {
  font-size: 3rem;
  animation: shake 1.6s ease-in-out infinite;
}
@keyframes shake {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-6deg); }
  75% { transform: rotate(6deg); }
}
.pass-text {
  font-size: 1.2rem;
  margin: 16px 0 4px;
}
.pass-hint {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-bottom: 22px;
}

.role-card {
  animation: flipIn 0.4s ease;
  border-width: 2px;
}
@keyframes flipIn {
  from { opacity: 0; transform: rotateX(-25deg) scale(0.95); }
  to { opacity: 1; transform: rotateX(0) scale(1); }
}
.role-card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.role-emoji {
  font-size: 2.4rem;
}
.role-label {
  margin: 0;
  font-size: 1.5rem;
}
.role-desc {
  color: var(--text-dim);
  margin: 0 0 4px;
  line-height: 1.5;
}
.shout-text {
  text-align: center;
  font-size: 1.8rem;
  font-weight: 700;
  margin: 10px 0 6px;
  animation: pop 0.4s ease;
}
@keyframes pop {
  0% { transform: scale(0.6); opacity: 0; }
  70% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); }
}

/* role color variants */
.role-police { border-color: var(--police); background: linear-gradient(160deg, var(--police-bg), var(--surface-2)); }
.role-police .role-label, .role-police .info-title { color: var(--police); }
.role-culprit { border-color: var(--culprit); background: linear-gradient(160deg, var(--culprit-bg), var(--surface-2)); }
.role-culprit .role-label, .role-culprit .info-title { color: var(--culprit); }
.role-informant { border-color: var(--informant); background: linear-gradient(160deg, var(--informant-bg), var(--surface-2)); }
.role-informant .role-label, .role-informant .info-title { color: var(--informant); }
.role-witness { border-color: var(--witness); background: linear-gradient(160deg, var(--witness-bg), var(--surface-2)); }
.role-witness .role-label, .role-witness .info-title { color: var(--witness); }
.role-independent { border-color: var(--independent); background: linear-gradient(160deg, var(--independent-bg), var(--surface-2)); }
.role-independent .role-label, .role-independent .info-title { color: var(--independent); }

/* ===================== Case / Round Screens ===================== */
.screen-heading {
  text-align: center;
  font-size: 1.3rem;
  margin-bottom: 4px;
}
.screen-sub {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-bottom: 18px;
}
.warn-text {
  color: var(--danger);
  font-weight: 600;
}
.case-wrap, .round-wrap, .grid-select-wrap, .result-wrap, .end-wrap {
  padding-top: 10px;
}
.case-card, .investigation-card {
  text-align: center;
  animation: pop 0.4s ease;
}
.case-card-text, .investigation-card-text {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.5;
  margin: 6px 0 0;
}
.case-info {
  text-align: center;
  color: var(--text-dim);
  margin-bottom: 20px;
}
.round-indicator {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 14px;
}
.round-actions {
  margin-top: 20px;
}

/* ===================== Select Grid (unlock / accuse) ===================== */
.select-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.select-btn {
  padding: 20px 6px;
  border-radius: 16px;
  border: 2px solid rgba(255,255,255,0.14);
  background: var(--surface);
  color: var(--text);
  font-size: 1.15rem;
  font-weight: 700;
}
.select-btn:active {
  background: var(--surface-2);
}

/* ===================== Unlock result ===================== */
.result-wrap {
  padding-top: 30px;
}

/* ===================== End Screen ===================== */
.end-banner {
  text-align: center;
  border-width: 2px;
}
.end-emoji {
  font-size: 3rem;
  margin: 0 0 6px;
}
.end-winner-text {
  margin: 0 0 8px;
  font-size: 1.6rem;
}
.end-reason-text {
  color: var(--text-dim);
  margin: 0 0 10px;
  line-height: 1.5;
}
.end-score-text {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
  margin: 0;
}
.end-roles-card {
  padding: 16px;
}
.end-role-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}
.end-role-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-radius: 12px;
  font-weight: 600;
}

/* ===================== How-to-play page ===================== */
.howto-hero {
  text-align: center;
  padding: 6px 0 22px;
}
.back-link {
  display: inline-block;
  margin-bottom: 14px;
  color: var(--text-dim);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
}
.back-link:active {
  opacity: 0.7;
}
.howto-steps {
  padding-left: 22px;
  margin: 10px 0 0;
  line-height: 1.7;
}
.howto-steps li {
  margin-bottom: 10px;
}
.card h2 {
  font-size: 1.1rem;
  margin: 0 0 4px;
}
.card h2 .muted {
  display: block;
  font-size: 0.78rem;
  font-weight: 400;
  margin-top: 2px;
}
.card > p.muted {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin: 0 0 4px;
}

.card-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}
.mini-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--bg-1);
  border: 1px solid rgba(255,255,255,0.08);
}
.mini-icon {
  font-size: 1.3rem;
  flex-shrink: 0;
  line-height: 1.4;
}
.mini-text {
  font-size: 0.92rem;
  line-height: 1.5;
  font-weight: 500;
}
.mini-text b {
  font-size: 1rem;
}
.center-text {
  text-align: center;
}
.center-text a {
  text-decoration: none;
}

/* ===================== Small screens ===================== */
@media (max-width: 340px) {
  .game-title { font-size: 1.55rem; }
  .count-grid { grid-template-columns: repeat(4, 1fr); gap: 8px; }
}
