/* ===================== โทนสี (ดึงจากโปสเตอร์) ===================== */
:root {
  --pink: #ff5fa2;
  --pink-soft: #ffd3e6;
  --blue: #38b6ff;
  --blue-soft: #d3efff;
  --mint: #2fcf9e;
  --yellow: #ffd23f;
  --ink: #2a3b5e;
  --paper: #fffdf7;
  --line: #ece6db;
  --shadow: 0 10px 0 rgba(42, 59, 94, 0.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Sarabun", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, var(--pink-soft) 0, transparent 40%),
    radial-gradient(circle at 88% 92%, var(--blue-soft) 0, transparent 42%),
    var(--paper);
  min-height: 100vh;
  padding: 24px 16px;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: "Mali", "Sarabun", sans-serif; }

/* ===================== การสลับหน้า ===================== */
.view { display: none; max-width: 760px; margin: 0 auto; }
.view.is-active { display: block; }

/* ===================== ปุ่ม ===================== */
.btn {
  font-family: "Mali", sans-serif;
  font-weight: 700;
  font-size: 1.05rem;
  border: none;
  border-radius: 16px;
  padding: 14px 22px;
  cursor: pointer;
  color: #fff;
  transition: transform 0.08s ease, filter 0.15s ease;
  width: 100%;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(3px); }
.btn:disabled { background: #c9c4ba; cursor: not-allowed; box-shadow: none; filter: none; }
.btn-primary   { background: var(--pink); box-shadow: 0 5px 0 #d63d80; }
.btn-secondary { background: var(--blue); box-shadow: 0 5px 0 #1f93d6; }
.btn-bingo     { background: var(--mint); box-shadow: 0 5px 0 #1da57c; font-size: 1.3rem; letter-spacing: 1px; }

/* ===================== หน้าแรก ===================== */
.card {
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 28px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
}
.lobby-card { max-width: 560px; margin: 4vh auto 0; }

.brand { display: flex; align-items: center; justify-content: center; gap: 10px; }
.brand h1 {
  font-size: 3rem;
  background: linear-gradient(90deg, var(--pink), var(--blue), var(--mint));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  letter-spacing: 2px;
}
.pill { width: 26px; height: 14px; border-radius: 99px; display: inline-block; }
.pill-a { background: var(--pink); }
.pill-b { background: var(--blue); }
.subtitle { text-align: center; color: var(--blue); font-weight: 600; margin: 4px 0 24px; }

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-weight: 600; margin-bottom: 6px; }
.field input, .field select {
  width: 100%;
  font-family: "Sarabun", sans-serif;
  font-size: 1.05rem;
  padding: 12px 14px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
}
.field input:focus, .field select:focus { outline: 3px solid var(--blue-soft); border-color: var(--blue); }

.lobby-actions { display: grid; gap: 18px; }
.action-block h2 { font-size: 1.15rem; margin-bottom: 12px; }
.divider { text-align: center; position: relative; color: #aaa; }
.divider::before { content: ""; position: absolute; top: 50%; left: 0; right: 0; height: 1px; background: var(--line); }
.divider span { background: #fff; padding: 0 12px; position: relative; }

.msg { margin-top: 16px; text-align: center; min-height: 1.4em; font-weight: 600; color: var(--pink); }

/* ===================== หน้าเกม ===================== */
.game-header {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  justify-content: space-between; margin-bottom: 18px;
}
.room-tag { background: var(--yellow); color: var(--ink); font-weight: 700; padding: 8px 16px; border-radius: 14px; }
.room-tag strong { letter-spacing: 2px; }
.player-list { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; }
.player-list li { background: #fff; border: 2px solid var(--ink); border-radius: 99px; padding: 4px 14px; font-weight: 600; }
.player-list li.is-winner { background: var(--mint); color: #fff; }

.caller {
  background: #fff; border: 3px solid var(--ink); border-radius: 24px;
  padding: 20px; text-align: center; margin-bottom: 18px; box-shadow: var(--shadow);
}
.called-display { margin-bottom: 14px; }
.called-label { display: block; color: var(--blue); font-weight: 600; font-size: 0.9rem; }
#called-title { font-family: "Mali"; font-size: 1.8rem; color: var(--pink); }
.host-note { margin-top: 10px; color: #888; font-size: 0.9rem; min-height: 1.2em; }

.board-wrap { text-align: center; margin-bottom: 18px; }
.board-title { margin-bottom: 12px; }
.board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.cell {
  aspect-ratio: 1 / 1;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 18px;
  padding: 8px;
  display: flex; align-items: center; justify-content: center; text-align: center;
  font-family: "Mali"; font-weight: 700; font-size: 0.95rem;
  cursor: pointer; transition: transform 0.08s, background 0.15s;
}
.cell:hover { transform: scale(1.03); }
.cell.is-callable { box-shadow: 0 0 0 3px var(--yellow); }
.cell.is-marked { background: var(--mint); color: #fff; border-color: #1da57c; }

.called-history h3 { margin-bottom: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips span { background: var(--blue-soft); border-radius: 99px; padding: 4px 12px; font-size: 0.9rem; }

/* ===================== ป้ายผู้ชนะ ===================== */
.overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(42, 59, 94, 0.55);
  align-items: center; justify-content: center; padding: 24px; z-index: 50;
}
.overlay.is-active { display: flex; }
.overlay-card {
  background: #fff; border: 3px solid var(--ink); border-radius: 28px;
  padding: 36px 32px; text-align: center; max-width: 360px; width: 100%;
}
.trophy { font-size: 3.5rem; }
.overlay-card h2 { font-size: 2rem; color: var(--mint); margin: 8px 0; }
#winner-name { font-size: 1.4rem; font-weight: 700; margin-bottom: 22px; }

/* ===================== จอเล็ก ===================== */
@media (max-width: 560px) {
  .brand h1 { font-size: 2.4rem; }
  #called-title { font-size: 1.4rem; }
  .cell { font-size: 0.8rem; border-radius: 14px; }
}

/* ===================== บทบาท: ผู้ดำเนินเกม / ผู้เล่น ===================== */
.role-badge {
  font-family: "Mali", sans-serif; font-weight: 700;
  border-radius: 99px; padding: 6px 16px; color: #fff;
}
#game-view.role-host  .role-badge { background: var(--pink); }
#game-view.role-player .role-badge { background: var(--mint); }

.caller-info {
  background: var(--blue-soft); border-radius: 14px;
  padding: 8px 16px; font-weight: 600; margin-bottom: 12px;
}
.players-heading { font-weight: 700; margin-bottom: 8px; }
#player-count { color: var(--blue); }

.hint { color: #999; font-size: 0.85rem; margin: -6px 0 12px; }

/* ซ่อนตามบทบาท */
#game-view.role-host   .player-only { display: none; }
#game-view.role-player .host-only   { display: none; }

/* ===================== สถิติห้อง ===================== */
.stats { margin-top: 18px; }
.stats h3 { margin-bottom: 10px; }
#stats-content {
  background: #fff; border: 2px solid var(--ink);
  border-radius: 16px; padding: 14px 18px;
}
.stats-total { font-family: "Mali"; font-weight: 700; margin-bottom: 8px; color: var(--pink); }
.stats-row {
  display: flex; justify-content: space-between;
  padding: 5px 0; border-bottom: 1px dashed var(--line);
}
.stats-row:last-child { border-bottom: none; }

/* ===================== ลิงก์ไปหน้ารายงาน ===================== */
.report-link { text-align: center; margin-top: 14px; }
.report-link a { color: var(--blue); font-weight: 600; text-decoration: none; }
.report-link a:hover { text-decoration: underline; }

/* ===================== หน้ารายงาน (report.html) ===================== */
.report { max-width: 760px; margin: 0 auto; }
.report-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
.report-head h1 { font-size: 2rem; }
.back-link { color: var(--blue); font-weight: 600; text-decoration: none; }
.back-link:hover { text-decoration: underline; }

.report-totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 18px; }
.total-box {
  background: #fff; border: 3px solid var(--ink); border-radius: 18px;
  padding: 16px; text-align: center; box-shadow: var(--shadow);
}
.total-box span { display: block; font-family: "Mali"; font-size: 2rem; color: var(--pink); }
.total-box small { color: #777; }

.report-card {
  background: #fff; border: 3px solid var(--ink); border-radius: 22px;
  padding: 20px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.report-card h2 { margin-bottom: 14px; }
.table-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; }
.table-head .btn { width: auto; }

/* กราฟแท่ง */
.bar-row { display: grid; grid-template-columns: 110px 1fr 40px; align-items: center; gap: 10px; margin-bottom: 10px; }
.bar-label { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: var(--blue-soft); border-radius: 99px; height: 22px; overflow: hidden; }
.bar-fill { background: var(--mint); height: 100%; border-radius: 99px; transition: width 0.4s; }
.bar-val { text-align: right; font-weight: 700; }

/* ตาราง */
.report-table { width: 100%; border-collapse: collapse; }
.report-table th, .report-table td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--line); }
.report-table th { color: var(--blue); }
.report-table tr:first-child td { font-weight: 600; }

/* ===================== หน้าแรก: เลือกบทบาท ===================== */
.choose-label { text-align: center; color: #777; margin-bottom: 14px; }
.role-choose { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.role-card {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  text-decoration: none; color: var(--ink);
  border: 3px solid var(--ink); border-radius: 22px;
  padding: 22px 14px; text-align: center; box-shadow: var(--shadow);
  transition: transform 0.08s;
}
.role-card:active { transform: translateY(3px); }
.role-card strong { font-family: "Mali"; font-size: 1.3rem; }
.role-card small { color: #777; }
.role-emoji { font-size: 2.4rem; }
.role-teacher { background: var(--pink-soft); }
.role-student { background: var(--blue-soft); }

@media (max-width: 460px) { .role-choose { grid-template-columns: 1fr; } }

/* ข้อความทักทาย + ปุ่มลิงก์เล็ก */
.welcome { color: var(--mint); font-weight: 700; min-height: 1.2em; margin: -6px 0 12px; }
.link-btn { background: none; border: none; color: var(--blue); font-weight: 600; cursor: pointer; font-family: "Sarabun"; font-size: 1rem; width: auto; }
.link-btn:hover { text-decoration: underline; }
