:root {
  color-scheme: light;
  --bg: #eef2f6;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #111827;
  --muted: #64748b;
  --border: #d5dde8;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --secondary: #334155;
  --success: #15803d;
  --danger: #dc2626;
  --warning-bg: #fff7df;
  --warning-border: #f4c95d;
  --shadow: 0 10px 26px rgba(15, 23, 42, 0.08);
  --shadow-soft: 0 1px 2px rgba(15, 23, 42, 0.06);
  --gold: #f59e0b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    linear-gradient(180deg, #f8fafc 0%, var(--bg) 42%, #e8edf4 100%);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

button:hover {
  background: var(--primary-dark);
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.18);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button.secondary {
  background: var(--secondary);
}

button.ghost {
  background: #ffffff;
  color: var(--primary);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: var(--text);
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.04);
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
  outline: 0;
}

label,
.label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

h1,
h2,
p {
  margin: 0;
}

.app-shell {
  position: relative;
  width: min(1080px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 44px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 48px;
  margin-bottom: 16px;
  padding-right: 0;
}

.topbar h1 {
  font-size: 34px;
  line-height: 1.12;
  font-weight: 900;
}

.topbar p {
  margin-top: 8px;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

#leaveRoomBtn,
#toggleInviteBtn,
#closeRoomBtn {
  width: auto;
  min-height: 38px;
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
  white-space: nowrap;
}

.recovery-chip {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid #c7d2fe;
  border-radius: 8px;
  background: #f5f7ff;
  color: #3730a3;
  font-size: 14px;
  font-weight: 900;
  white-space: nowrap;
  box-shadow: var(--shadow-soft);
}

.topbar-link {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--primary);
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: var(--shadow-soft);
}

.danger-action {
  color: var(--danger) !important;
  border-color: #fecaca !important;
}

.setup-grid,
.room-layout {
  display: grid;
  gap: 16px;
}

.setup-grid {
  grid-template-columns: 1fr;
  max-width: 620px;
  margin: 0 auto;
  align-items: start;
}

.create-panel {
  border-color: #fecaca;
  background: #fff7f7;
}

.create-panel h2 {
  font-size: 22px;
  color: #b91c1c;
}

.create-panel .create-submit {
  background: #dc2626;
}

.create-panel .create-submit:hover {
  background: #b91c1c;
  box-shadow: 0 8px 18px rgba(220, 38, 38, 0.18);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.priority-panel {
  border-color: #b7d7d2;
}

.scroll-panel {
  overflow-x: auto;
}

form.panel {
  display: grid;
  gap: 13px;
}

.join-shortcuts {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: stretch;
}

.join-shortcuts #recentRoomBtn {
  width: auto;
  min-width: 116px;
}

.join-submit-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.join-submit-row #resetJoinFormBtn {
  width: auto;
  min-width: 92px;
}

.join-fields-row {
  display: grid;
  grid-template-columns: minmax(86px, 0.42fr) minmax(0, 1fr) minmax(120px, 0.58fr);
  gap: 12px;
  align-items: end;
}

.join-fields-row > div {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.panel h2 {
  font-size: 22px;
  line-height: 1.2;
  font-weight: 900;
}

.notice {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
  background: #eef6ff;
  color: #153f66;
  font-weight: 700;
}

.notice.warning {
  background: var(--warning-bg);
  border-color: var(--warning-border);
  color: #6f4e00;
}

.admin-entry-link {
  display: block;
  width: max-content;
  margin: 20px auto 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.admin-entry-link:hover {
  color: var(--primary);
}

.app-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 20px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.app-footer .admin-entry-link {
  display: inline;
  width: auto;
  margin: 0;
}

.admin-layout {
  display: grid;
  gap: 16px;
}

.admin-login {
  max-width: 560px;
  margin: 0 auto;
}

.admin-panel {
  display: grid;
  gap: 14px;
}

.admin-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.admin-actions button {
  width: auto;
}

.admin-history-title {
  margin-top: 10px;
}

#adminCloseSelectedBtn {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

#adminCloseSelectedBtn:hover {
  background: #b91c1c;
}

.admin-table-wrap {
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
  font-size: 14px;
}

.admin-history-table {
  min-width: 760px;
}

.admin-history-scores {
  min-width: 520px;
}

.admin-table th,
.admin-table td {
  border-bottom: 1px solid var(--border);
  padding: 11px 10px;
  text-align: left;
  white-space: nowrap;
}

.admin-table th {
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.admin-table input[type="checkbox"] {
  width: 20px;
  min-height: 20px;
  box-shadow: none;
}

.admin-select-all {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.admin-player-count {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.admin-expand-btn {
  display: inline-grid;
  place-items: center;
  width: 28px;
  min-height: 28px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--secondary);
  box-shadow: none;
  font-size: 14px;
  line-height: 1;
}

.admin-player-details-row td {
  background: #f8fafc;
  padding: 10px 12px 14px;
}

.admin-player-list {
  display: grid;
  gap: 8px;
}

.admin-player-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 38px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.admin-player-name-btn {
  width: auto;
  min-height: 30px;
  padding: 0;
  background: transparent;
  color: var(--primary);
  border: 0;
  box-shadow: none;
  font-size: 14px;
  font-weight: 900;
  text-align: left;
}

.admin-player-name-btn:hover {
  background: transparent;
  box-shadow: none;
  text-decoration: underline;
}

.admin-player-code {
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.admin-status {
  font-weight: 900;
}

.admin-status.active {
  color: var(--success);
}

.admin-status.inactive {
  color: var(--danger);
}

#toggleInviteBtn {
  width: auto;
  min-height: 38px;
  padding: 0 12px;
  white-space: nowrap;
}

.invite-panel {
  width: 100%;
}

.room-qr {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
  justify-items: start;
}

.room-qr .label {
  grid-column: 1 / -1;
}

.room-qr a {
  color: var(--primary);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.qr-box {
  width: 116px;
  min-height: 116px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 8px;
}

.qr-box img {
  width: 100px;
  height: 100px;
  display: block;
}

.qr-scanner {
  display: grid;
  gap: 10px;
}

.qr-scanner video {
  width: 100%;
  aspect-ratio: 4 / 3;
  display: block;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #101828;
  object-fit: cover;
}

.scanner-footer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.scanner-footer span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid #edf1f7;
}

.section-title h2 {
  font-size: 19px;
  font-weight: 900;
}

.section-title span {
  color: var(--muted);
  font-weight: 700;
}

.players-list {
  display: grid;
  gap: 10px;
}

.totals-rank {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: stretch;
}

.total-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  min-width: min(100%, 250px);
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-soft);
  box-shadow: var(--shadow-soft);
}

.rank-badge {
  min-width: 42px;
  border-radius: 999px;
  padding: 3px 9px;
  text-align: center;
  background: #e2e8f0;
  color: #344054;
  font-size: 13px;
  font-weight: 900;
}

.rank-badge.leader {
  background: var(--gold);
  color: #fff;
}

.total-name {
  min-width: 0;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.total-score {
  font-size: 24px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.player-row,
.history-row,
.round-player {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  min-height: 48px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--panel-soft);
  box-shadow: var(--shadow-soft);
}

.player-name {
  min-width: 0;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  margin-left: 6px;
  background: #ccfbf1;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
}

.easter-egg {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  width: 34px;
  margin-left: 6px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #b45309;
  font-size: 19px;
  box-shadow: none;
  animation: eggBlink 0.85s ease-in-out infinite;
}

.easter-egg:hover {
  background: #fff7ed;
  box-shadow: none;
  transform: scale(1.12);
}

@keyframes eggBlink {
  0%, 48%, 100% { opacity: 1; }
  50%, 88% { opacity: 0.35; }
}

.score {
  font-variant-numeric: tabular-nums;
  font-weight: 900;
}

.score.positive {
  color: var(--success);
}

.score.negative {
  color: var(--danger);
}

.host-controls,
.loss-form {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.loss-form label {
  color: var(--danger);
  font-size: 18px;
  font-weight: 900;
}

.loss-form input {
  border-color: #fca5a5;
  background: #fff7f7;
  font-size: 18px;
  font-weight: 800;
}

.loss-form input::placeholder {
  color: #b91c1c;
  opacity: 0.72;
  font-weight: 800;
}

.inline-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.host-round-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(110px, 140px) auto;
  gap: 10px;
  align-items: end;
}

.bomb-field {
  display: grid;
  gap: 6px;
}

.bomb-field input {
  text-align: center;
  font-weight: 900;
}

.round-actions,
.history-actions {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.round-actions {
  justify-content: flex-start;
}

.compact-btn,
.table-action-btn {
  width: auto;
  min-height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

.danger-btn {
  color: var(--danger);
  border-color: #fecaca;
}

.table-action-btn {
  background: var(--secondary);
}

.table-action-btn.ghost-action {
  background: #ffffff;
  color: var(--primary);
  border: 1px solid var(--border);
}

.table-action-btn.danger-active-action,
.table-action-btn.ghost-action.danger-active-action {
  background: var(--danger);
  color: #ffffff;
  border-color: var(--danger);
  box-shadow: 0 8px 18px rgba(220, 38, 38, 0.2);
}

.table-action-btn.danger-active-action:hover,
.table-action-btn.ghost-action.danger-active-action:hover {
  background: #b91c1c;
  border-color: #b91c1c;
}

.table-action-btn:disabled,
.table-action-btn.ghost-action:disabled {
  background: #e5e7eb;
  color: #94a3b8;
  border-color: #d8dee8;
  box-shadow: none;
  cursor: not-allowed;
}

.round-label-cell {
  white-space: nowrap;
}

.bomb-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 8px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #fff1f2;
  color: #be123c;
  border: 1px solid #fecdd3;
  font-size: 12px;
  font-weight: 900;
  line-height: 1.2;
}

.round-box {
  display: grid;
  gap: 10px;
}

.round-message {
  color: var(--muted);
  line-height: 1.6;
}

.round-player small,
.history-row small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

.host-submit-btn {
  display: inline-flex;
  margin-top: 6px;
}

.round-host-actions {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

#saveRoundBtn,
#cancelRoundBtn {
  width: 100%;
}

#saveRoundBtn {
  background: var(--success);
}

#cancelRoundBtn {
  background: #ffffff;
  color: var(--danger);
  border: 1px solid #fecaca;
}

#cancelRoundBtn:hover {
  background: #fff1f2;
  box-shadow: 0 8px 18px rgba(220, 38, 38, 0.12);
}

.speech-controls {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.speech-actions,
.voice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.speech-actions button {
  min-width: 120px;
}

.speech-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--secondary);
  font-size: 14px;
  font-weight: 800;
}

.speech-check input {
  width: 18px;
  min-height: 18px;
  box-shadow: none;
}

.voice-row label {
  flex: 0 0 auto;
}

.voice-row select {
  flex: 1 1 220px;
}

.speech-hint,
.speech-status {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.keypad-overlay {
  position: fixed;
  left: 12px;
  bottom: 12px;
  z-index: 1000;
  width: min(280px, calc(100vw - 24px));
  padding: 10px;
  border-radius: 10px;
  background: #111827;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.34);
}

.keypad-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  color: #f8fafc;
  font-size: 13px;
  font-weight: 800;
}

.keypad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.keypad-key,
.keypad-func,
.keypad-done {
  min-height: 42px;
  border-radius: 8px;
  box-shadow: none;
}

.keypad-key {
  padding: 0;
  background: #1f2937;
  color: #fff;
  font-size: 20px;
  font-weight: 900;
}

.keypad-key[data-keypad-action] {
  background: #475569;
  font-size: 14px;
}

.keypad-func {
  min-height: 30px;
  padding: 0 10px;
  background: #334155;
  font-size: 12px;
}

.keypad-done {
  width: 100%;
  margin-top: 8px;
  background: var(--success);
}

.number-modal {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.5);
}

.number-modal-box {
  width: min(360px, 100%);
  display: grid;
  gap: 12px;
  padding: 16px;
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.number-modal-box label {
  color: var(--text);
  font-size: 18px;
  font-weight: 900;
}

.number-modal-box input {
  border-color: var(--primary);
  font-size: 24px;
  font-weight: 900;
  text-align: center;
}

.number-modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.egg-modal {
  position: fixed;
  inset: 0;
  z-index: 1001;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.58);
}

.egg-modal-content {
  position: relative;
  width: min(380px, 100%);
  display: grid;
  gap: 12px;
  padding: 22px 18px 18px;
  border-radius: 12px;
  background: #fff;
  box-shadow: var(--shadow);
}

.egg-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--secondary);
  box-shadow: none;
  font-size: 24px;
  line-height: 1;
}

.egg-player-name {
  padding-right: 36px;
  color: var(--text);
  font-size: 22px;
  font-weight: 900;
}

.egg-message {
  color: var(--secondary);
  font-size: 17px;
  line-height: 1.65;
  font-weight: 800;
}

.history-list {
  display: grid;
  gap: 10px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.score-table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: 13px;
}

.score-table th,
.score-table td {
  border: 1px solid var(--border);
  padding: 8px;
  text-align: center;
  white-space: nowrap;
}

.score-table th {
  background: #f1f5f9;
  color: #344054;
  font-weight: 900;
}

.score-table .summary-row td {
  font-weight: 900;
}

.history-score-pos {
  background: #e8f7ee;
  color: var(--success);
  font-weight: 900;
}

.history-score-neg {
  background: #fdecec;
  color: var(--danger);
  font-weight: 900;
}

.history-score-zero {
  background: #f3f4f6;
  color: #475467;
  font-weight: 800;
}

.trend-canvas {
  width: 100%;
  height: 240px;
  display: block;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfcfe;
}

.scroll-panel .trend-canvas,
.scroll-panel .trend-legend,
.scroll-panel .stats-grid {
  min-width: 560px;
}

.trend-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.trend-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}

.trend-legend-item span:last-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.trend-color {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
}

.stats-grid {
  display: grid;
  grid-template-columns: minmax(220px, 320px) 1fr;
  gap: 18px;
  align-items: start;
}

.stats-grid h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.stats-pie {
  width: 220px;
  height: 220px;
  max-width: 100%;
  display: block;
}

.stats-list {
  color: #344054;
  font-size: 14px;
  line-height: 1.6;
}

.stats-list ul {
  margin: 0;
  padding-left: 18px;
}

.hidden {
  display: none !important;
}

@media (max-width: 720px) {
  body {
    font-size: 16px;
    background: #eef2f6;
  }

  .app-shell {
    width: 100%;
    padding: 12px 10px 28px;
  }

  #leaveRoomBtn,
  #toggleInviteBtn,
  #closeRoomBtn {
    min-height: 40px;
    font-size: 14px;
  }

  .topbar,
  .section-title {
    align-items: flex-start;
  }

  .topbar {
    display: grid;
    grid-template-columns: 1fr;
    min-height: 0;
    margin-bottom: 10px;
    padding-right: 0;
    gap: 8px;
  }

  .topbar-actions {
    gap: 8px;
    justify-content: flex-start;
  }

  .topbar h1 {
    font-size: 26px;
    line-height: 1.12;
    white-space: nowrap;
  }

  .setup-grid,
  .inline-row,
  .host-round-row,
  .scanner-footer {
    grid-template-columns: 1fr;
  }

  .setup-grid,
  .room-layout {
    gap: 10px;
  }

  .room-layout {
    font-size: 16px;
  }

  .setup-grid {
    max-width: none;
  }

  .panel {
    padding: 12px;
    border-radius: 8px;
    box-shadow: 0 1px 5px rgba(15, 23, 42, 0.06);
  }

  .priority-panel {
    padding: 13px;
  }

  .scroll-panel {
    padding: 12px;
  }

  .panel h2,
  .create-panel h2 {
    font-size: 20px;
  }

  label,
  .label {
    font-size: 15px;
  }

  input,
  select,
  button {
    min-height: 46px;
    font-size: 16px;
  }

  .join-fields-row {
    grid-template-columns: minmax(72px, 0.36fr) minmax(0, 1fr) minmax(106px, 0.52fr);
    gap: 10px;
  }

  .room-qr {
    grid-template-columns: 1fr;
  }

  #toggleInviteBtn {
    min-height: 46px;
    padding: 0 10px;
  }

  .section-title {
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 8px;
  }

  .section-title h2 {
    font-size: 20px;
  }

  .section-title span {
    font-size: 14px;
  }

  .total-item,
  .round-player,
  .player-row,
  .history-row {
    min-height: 52px;
    padding: 10px;
    font-size: 16px;
  }

  .total-name,
  .player-name {
    font-size: 16px;
  }

  .total-score {
    font-size: 30px;
  }

  .totals-panel .section-title h2,
  .round-panel .section-title h2 {
    font-size: 24px;
  }

  .totals-panel .section-title span,
  .round-panel .section-title span {
    font-size: 16px;
  }

  .totals-panel .total-item {
    min-width: 100%;
    padding: 13px;
  }

  .round-panel .round-message {
    font-size: 16px;
    font-weight: 700;
  }

  .round-panel .round-player {
    font-size: 16px;
  }

  .round-panel .score {
    font-size: 20px;
  }

  .rank-badge {
    font-size: 15px;
  }

  .badge {
    font-size: 13px;
  }

  .loss-form label {
    font-size: 22px;
  }

  .loss-form input {
    font-size: 22px;
  }

  .compact-btn,
  .table-action-btn {
    min-height: 40px;
    font-size: 15px;
  }

  .score-table {
    min-width: 560px;
    font-size: 14px;
  }

  .score-table th,
  .score-table td {
    padding: 10px 8px;
  }

  .trend-canvas {
    height: 176px;
  }

  .trend-panel,
  .stats-panel {
    overflow-x: visible;
  }

  .trend-panel .trend-canvas,
  .trend-panel .trend-legend,
  .stats-panel .stats-grid {
    min-width: 0;
    width: 100%;
  }

  .trend-legend {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    font-size: 14px;
    line-height: 1.25;
  }

  .trend-legend-item {
    align-items: flex-start;
    gap: 6px;
    padding: 6px 7px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
  }

  .trend-legend-item input {
    width: 16px;
    min-height: 16px;
    margin: 1px 0 0;
    box-shadow: none;
    flex: 0 0 auto;
  }

  .trend-color {
    flex: 0 0 auto;
    margin-top: 4px;
  }

  .stats-list {
    font-size: 15px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .stats-pie {
    width: 156px;
    height: 156px;
    margin: 0 auto 10px;
  }

  .total-item {
    width: 100%;
  }

  button {
    width: 100%;
  }

  #leaveRoomBtn,
  #toggleInviteBtn,
  #closeRoomBtn {
    width: auto;
  }
}

@media (max-width: 380px) {
  .app-shell {
    padding-left: 8px;
    padding-right: 8px;
  }

  .topbar h1 {
    font-size: 27px;
  }

  .join-fields-row {
    grid-template-columns: 1fr;
  }

  .trend-legend {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 11px;
  }

  .priority-panel {
    padding: 13px;
  }
}
