/* ==========================================================================
   Farkle — Medieval Tavern Theme (Kingdom Come: Deliverance inspired)
   ========================================================================== */

/* --- Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=MedievalSharp&family=Crimson+Text:ital,wght@0,400;0,600;0,700;1,400&display=swap');

/* --- CSS Custom Properties --- */
:root {
  /* Wood */
  --wood-dark: #2c1810;
  --wood-mid: #3d2317;
  --wood-light: #5a3a28;
  --wood-grain: #4a2e1c;

  /* Parchment */
  --parchment: #d4b896;
  --parchment-dark: #c4a67a;
  --parchment-light: #e8d5b7;
  --parchment-edge: #b8976a;

  /* Leather */
  --leather: #8b6914;
  --leather-dark: #6b4e12;
  --leather-pressed: #5a4010;

  /* Ink & Text */
  --ink: #1a1008;
  --ink-light: #3d2e1a;
  --text-light: #e8d5b7;
  --text-muted: #a89070;

  /* Accents */
  --gold: #c9a84c;
  --gold-bright: #e0c060;
  --blood: #8b1a1a;
  --blood-bright: #a82020;
  --steel: #7a8b8b;
  --steel-light: #9aabab;

  /* Spacing */
  --radius-sm: 3px;
  --radius-md: 6px;
  --radius-lg: 10px;

  /* Shadows */
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
  --shadow-inset: inset 0 2px 6px rgba(0, 0, 0, 0.25);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  min-height: 100vh;
  height: 100%;
}

body {
  font-family: 'Crimson Text', Georgia, 'Times New Roman', serif;
  color: var(--ink);
  line-height: 1.6;
  margin: 0;
  padding: 0;
  min-height: 100vh;
  height: 100%;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
  font-family: 'MedievalSharp', Georgia, serif;
  line-height: 1.2;
  color: var(--ink);
}

a {
  color: var(--leather);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--gold);
}

img {
  max-width: 100%;
  height: auto;
}

/* --- 1. Medieval Background --- */
.medieval-bg {
  background:
    repeating-linear-gradient(
      87deg,
      transparent,
      transparent 3px,
      rgba(0, 0, 0, 0.03) 3px,
      rgba(0, 0, 0, 0.03) 6px
    ),
    repeating-linear-gradient(
      92deg,
      transparent,
      transparent 5px,
      rgba(0, 0, 0, 0.02) 5px,
      rgba(0, 0, 0, 0.02) 7px
    ),
    linear-gradient(
      180deg,
      var(--wood-dark) 0%,
      var(--wood-mid) 30%,
      var(--wood-grain) 50%,
      var(--wood-mid) 70%,
      var(--wood-dark) 100%
    );
  background-color: var(--wood-dark);
  min-height: 100vh;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- 2. Parchment Card --- */
.parchment {
  background:
    linear-gradient(
      135deg,
      var(--parchment-light) 0%,
      var(--parchment) 40%,
      var(--parchment-dark) 100%
    );
  border: 2px solid var(--parchment-edge);
  border-radius: var(--radius-md);
  box-shadow:
    var(--shadow-md),
    inset 0 1px 0 rgba(255, 255, 255, 0.15),
    inset 0 0 20px rgba(0, 0, 0, 0.05);
  padding: 1.5rem;
  position: relative;
  animation: cardAppear 0.4s ease-out;
}

.parchment::before {
  content: '';
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(160, 130, 90, 0.3);
  border-radius: calc(var(--radius-md) - 2px);
  pointer-events: none;
}

@keyframes cardAppear {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* --- 3. Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: 'MedievalSharp', Georgia, serif;
  font-size: 1rem;
  padding: 0.6rem 1.4rem;
  border: 2px solid var(--leather-dark);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition:
    background var(--transition-fast),
    transform var(--transition-fast),
    box-shadow var(--transition-fast);
  background:
    linear-gradient(
      180deg,
      var(--leather) 0%,
      var(--leather-dark) 100%
    );
  color: var(--parchment-light);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  box-shadow:
    var(--shadow-sm),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  user-select: none;
  text-decoration: none;
  line-height: 1.2;
}

.btn:hover {
  background:
    linear-gradient(
      180deg,
      #9d7a1a 0%,
      var(--leather) 100%
    );
  transform: translateY(-1px);
  box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255, 255, 255, 0.15);
  color: #fff;
}

.btn:active {
  transform: translateY(1px);
  background:
    linear-gradient(
      180deg,
      var(--leather-dark) 0%,
      var(--leather-pressed) 100%
    );
  box-shadow: var(--shadow-inset);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background:
    linear-gradient(
      180deg,
      var(--gold) 0%,
      #a88a30 100%
    );
  border-color: #8a7028;
  color: var(--ink);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.2);
}

.btn-primary:hover {
  background:
    linear-gradient(
      180deg,
      var(--gold-bright) 0%,
      var(--gold) 100%
    );
  color: var(--ink);
}

.btn-primary:active {
  background:
    linear-gradient(
      180deg,
      #a88a30 0%,
      #8a7028 100%
    );
}

.btn-danger {
  background:
    linear-gradient(
      180deg,
      var(--blood-bright) 0%,
      var(--blood) 100%
    );
  border-color: #6a1010;
  color: var(--parchment-light);
}

.btn-danger:hover {
  background:
    linear-gradient(
      180deg,
      #c02828 0%,
      var(--blood-bright) 100%
    );
}

.btn-danger:active {
  background:
    linear-gradient(
      180deg,
      var(--blood) 0%,
      #6a1010 100%
    );
}

.btn-sm {
  font-size: 0.85rem;
  padding: 0.35rem 0.9rem;
}

.btn-lg {
  font-size: 1.15rem;
  padding: 0.8rem 2rem;
}

/* --- 4. Auth Layout --- */
.auth-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem 1rem;
}

.auth-card {
  width: 100%;
  max-width: 420px;
}

.auth-card .medieval-title {
  text-align: center;
  margin-bottom: 1.5rem;
}

.auth-card .btn {
  width: 100%;
  margin-top: 0.5rem;
}

.auth-footer {
  text-align: center;
  margin-top: 1.2rem;
  font-size: 0.95rem;
  color: var(--ink-light);
}

.auth-link {
  text-align: center;
  margin-top: 1.2rem;
}

/* OAuth Buttons */
.auth-divider {
  display: flex;
  align-items: center;
  margin: 1.5rem 0;
  gap: 1rem;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--ink-light, #8b7d6b);
  opacity: 0.4;
}

.auth-divider span {
  font-size: 0.9rem;
  color: var(--ink-light, #8b7d6b);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.oauth-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.btn-oauth {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 0.7rem 1.2rem;
  border: 2px solid transparent;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
}

.btn-oauth:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.btn-oauth:active {
  transform: translateY(0);
}

.btn-oauth--google {
  background: #ffffff;
  color: #3c4043;
  border-color: #dadce0;
}

.btn-oauth--google:hover {
  background: #f8f9fa;
  border-color: #c1c1c1;
}

.btn-oauth--discord {
  background: #5865F2;
  color: #ffffff;
  border-color: #5865F2;
}

.btn-oauth--discord:hover {
  background: #4752c4;
  border-color: #4752c4;
}

.oauth-icon {
  flex-shrink: 0;
  vertical-align: middle;
}

/* Linked Accounts (Profile) */
.linked-accounts {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.linked-account-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: rgba(0,0,0,0.03);
  border-radius: 6px;
}

.linked-account-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.linked-account-provider {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 600;
}

.linked-account-status {
  font-size: 0.85rem;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
}

.linked-account-status--linked {
  background: rgba(52, 168, 83, 0.15);
  color: #1e7e34;
}

.linked-account-status--not-linked {
  background: rgba(0,0,0,0.06);
  color: var(--ink-light, #8b7d6b);
}

.btn--small {
  padding: 0.3rem 0.8rem;
  font-size: 0.85rem;
}

/* --- 5. Form Elements --- */
.form-group {
  margin-bottom: 1.1rem;
}

.form-group label {
  display: block;
  font-family: 'MedievalSharp', Georgia, serif;
  font-size: 0.95rem;
  color: var(--ink-light);
  margin-bottom: 0.3rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
textarea,
select {
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-family: 'Crimson Text', Georgia, serif;
  font-size: 1rem;
  color: var(--ink);
  background: var(--parchment-light);
  border: 2px solid var(--parchment-edge);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-inset);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--gold);
  box-shadow: var(--shadow-inset), 0 0 0 2px rgba(201, 168, 76, 0.25);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
  font-style: italic;
}

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%233d2e1a' stroke-width='2' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}

/* --- 6. Alerts --- */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.95rem;
  border-left: 4px solid var(--gold);
  background: rgba(201, 168, 76, 0.12);
  color: var(--ink);
}

.alert-error {
  border-left-color: var(--blood);
  background: rgba(139, 26, 26, 0.1);
  color: var(--blood);
}

.alert-success {
  border-left-color: #4a7a3a;
  background: rgba(74, 122, 58, 0.1);
  color: #3a6a2a;
}

/* --- 7. Lobby Layout --- */
.lobby-container {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr 300px;
  gap: 1.2rem;
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.5rem;
}

.lobby-section-title {
  font-family: 'MedievalSharp', Georgia, serif;
  font-size: 1.2rem;
  color: var(--ink);
  border-bottom: 2px solid var(--parchment-edge);
  padding-bottom: 0.4rem;
  margin-bottom: 1rem;
}

.game-list {
  list-style: none;
}

.game-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0;
  border-bottom: 1px solid rgba(160, 130, 90, 0.3);
}

.game-list-item:last-child {
  border-bottom: none;
}

/* --- 8. Game Page Layout --- */
.game-container {
  flex: 1;
  display: grid;
  grid-template-columns: 220px 1fr 220px;
  grid-template-rows: 1fr auto;
  gap: 0.75rem;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 0.75rem;
  height: calc(100vh - 60px);
  max-height: calc(100vh - 60px);
  overflow: hidden;
  grid-template-areas:
    "p1     canvas  chat"
    "p1     ctrl    chat";
}

/* --- 9. Player Panel --- */
.player-panel {
  padding: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.player-panel--left  { grid-area: p1; }
.player-panel--right { grid-area: p2; }

.player-panel .player-name {
  font-family: 'MedievalSharp', Georgia, serif;
  font-size: 1.15rem;
  color: var(--ink);
}

.player-panel .player-score {
  font-family: 'MedievalSharp', Georgia, serif;
  font-size: 2rem;
  font-weight: 700;
  color: var(--blood);
  line-height: 1;
}

.player-panel .player-score-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.player-panel .player-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid var(--parchment-edge);
  box-shadow: var(--shadow-sm);
  object-fit: cover;
}

.player-panel .player-level {
  display: inline-block;
  background: var(--gold);
  color: var(--ink);
  font-family: 'MedievalSharp', Georgia, serif;
  font-size: 0.75rem;
  padding: 0.1rem 0.5rem;
  border-radius: 10px;
}

/* --- 10. Game Controls --- */
.game-controls {
  grid-area: ctrl;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1rem;
}

.game-controls .btn {
  min-width: 140px;
}

.canvas-area {
  grid-area: canvas;
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background:
    repeating-linear-gradient(
      85deg,
      transparent,
      transparent 4px,
      rgba(0, 0, 0, 0.02) 4px,
      rgba(0, 0, 0, 0.02) 8px
    ),
    linear-gradient(160deg, var(--wood-light) 0%, var(--wood-mid) 100%);
  border: 3px solid var(--wood-grain);
  box-shadow: var(--shadow-inset), var(--shadow-lg);
  min-height: 0;
}

.canvas-area canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* --- 11. Chat Panel --- */
.chat-panel {
  grid-area: chat;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 2rem);
}

.chat-panel .chat-header {
  font-family: 'MedievalSharp', Georgia, serif;
  font-size: 1rem;
  padding: 0.6rem 0.8rem;
  border-bottom: 2px solid var(--parchment-edge);
  color: var(--ink);
}

.chat-panel .chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  scrollbar-width: thin;
  scrollbar-color: var(--parchment-edge) transparent;
}

.chat-message {
  font-size: 0.9rem;
  line-height: 1.4;
}

.chat-message .chat-author {
  font-weight: 700;
  color: var(--leather-dark);
}

.chat-message .chat-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-left: 0.3rem;
}

.chat-panel .chat-input-area {
  display: flex;
  gap: 0.4rem;
  padding: 0.6rem;
  border-top: 2px solid var(--parchment-edge);
}

.chat-input-area input {
  flex: 1;
  font-size: 0.9rem;
  padding: 0.4rem 0.6rem;
}

.chat-input-area .btn {
  font-size: 0.85rem;
  padding: 0.4rem 0.8rem;
}

/* --- 12. Medieval Title --- */
.medieval-title {
  font-family: 'MedievalSharp', Georgia, serif;
  font-size: 2.2rem;
  color: var(--ink);
  text-shadow: 1px 1px 0 rgba(200, 170, 100, 0.3);
  letter-spacing: 0.02em;
  position: relative;
  display: inline-block;
}

.medieval-title::after {
  content: '';
  display: block;
  width: 60%;
  height: 2px;
  margin: 0.3rem auto 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    var(--gold) 30%,
    var(--gold) 70%,
    transparent 100%
  );
}

.medieval-title--light {
  color: var(--parchment-light);
  text-shadow: 1px 2px 4px rgba(0, 0, 0, 0.6);
}

.medieval-title--light::after {
  background: linear-gradient(
    90deg,
    transparent 0%,
    var(--gold) 30%,
    var(--gold) 70%,
    transparent 100%
  );
}

/* --- 13. NPC Card --- */
.npc-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  transition:
    border-color var(--transition-fast),
    background var(--transition-fast),
    transform var(--transition-fast);
}

.npc-card:hover {
  border-color: var(--gold);
  background: rgba(201, 168, 76, 0.08);
  transform: translateX(4px);
}

.npc-card.selected {
  border-color: var(--gold);
  background: rgba(201, 168, 76, 0.15);
}

.npc-card .npc-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px solid var(--parchment-edge);
  object-fit: cover;
  flex-shrink: 0;
}

.npc-card .npc-name {
  font-family: 'MedievalSharp', Georgia, serif;
  font-size: 1.1rem;
  color: var(--ink);
}

.npc-card .npc-style {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
}

.npc-card .npc-difficulty {
  display: flex;
  gap: 3px;
  margin-top: 0.2rem;
}

.npc-card .npc-difficulty span {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--parchment-edge);
}

.npc-card .npc-difficulty span.filled {
  background: var(--gold);
}

/* --- 14. Dice Score Display --- */
.dice-score-display {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'MedievalSharp', Georgia, serif;
  font-size: 3rem;
  color: var(--gold-bright);
  text-shadow:
    0 0 10px rgba(201, 168, 76, 0.5),
    0 2px 4px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  z-index: 10;
  animation: scorePop 0.6s ease-out;
}

@keyframes scorePop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.5);
  }
  60% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.15);
  }
  100% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

/* --- 15. Overlays --- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 10, 5, 0.8);
  z-index: 100;
  animation: overlayIn 0.3s ease-out;
}

@keyframes overlayIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.overlay-content {
  text-align: center;
  padding: 2.5rem 3rem;
  animation: cardAppear 0.4s ease-out;
}

.overlay-title {
  font-family: 'MedievalSharp', Georgia, serif;
  font-size: 2.8rem;
  margin-bottom: 0.5rem;
}

.overlay-subtitle {
  font-size: 1.15rem;
  margin-bottom: 1.5rem;
}

.overlay--farkle .overlay-title {
  color: var(--blood-bright);
  text-shadow: 0 2px 8px rgba(139, 26, 26, 0.4);
}

.overlay--hotdice .overlay-title {
  color: var(--gold-bright);
  text-shadow: 0 0 16px rgba(201, 168, 76, 0.6);
}

.overlay--win .overlay-title {
  color: var(--gold-bright);
  text-shadow: 0 0 20px rgba(224, 192, 96, 0.5);
  font-size: 3.5rem;
}

.overlay--lose .overlay-title {
  color: var(--steel-light);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

/* --- 16. Profile Card --- */
.profile-card {
  text-align: center;
  padding: 2rem;
}

.profile-card .profile-avatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: 3px solid var(--gold);
  box-shadow: var(--shadow-md);
  object-fit: cover;
  margin-bottom: 1rem;
}

.profile-card .profile-name {
  font-family: 'MedievalSharp', Georgia, serif;
  font-size: 1.5rem;
  color: var(--ink);
}

.profile-card .profile-level {
  display: inline-block;
  background: linear-gradient(180deg, var(--gold) 0%, #a88a30 100%);
  color: var(--ink);
  font-family: 'MedievalSharp', Georgia, serif;
  font-size: 0.85rem;
  padding: 0.15rem 0.75rem;
  border-radius: 12px;
  margin-top: 0.3rem;
}

.profile-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.8rem;
  margin-top: 1.5rem;
}

.profile-stat {
  text-align: center;
}

.profile-stat .stat-value {
  font-family: 'MedievalSharp', Georgia, serif;
  font-size: 1.5rem;
  color: var(--blood);
  display: block;
}

.profile-stat .stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* --- 16b. Profile Page --- */
.profile-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.2rem;
  max-width: 900px;
  margin: 0 auto;
  padding: 1.5rem;
}

.profile-container > .profile-card {
  grid-column: 1 / -1;
}

.profile-avatar-placeholder {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: 3px solid var(--gold);
  box-shadow: var(--shadow-md);
  margin: 0 auto 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  background: var(--parchment-dark);
  color: var(--ink-light);
}

.profile-level-badge {
  display: inline-block;
  background: linear-gradient(180deg, var(--gold) 0%, #a88a30 100%);
  color: var(--ink);
  font-family: 'MedievalSharp', Georgia, serif;
  font-size: 1rem;
  padding: 0.2rem 1rem;
  border-radius: 14px;
  margin-top: 0.4rem;
}

.profile-peak-level {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
  font-style: italic;
}

.xp-bar-container {
  max-width: 320px;
  margin: 0 auto;
}

.xp-bar {
  width: 100%;
  height: 12px;
  background: var(--parchment-dark);
  border-radius: 6px;
  border: 1px solid var(--parchment-edge);
  overflow: hidden;
  box-shadow: var(--shadow-inset);
}

.xp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gold) 0%, var(--gold-bright) 100%);
  border-radius: 6px;
  transition: width 0.5s ease;
}

.xp-bar-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 0.25rem;
}

.dice-loadout {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  justify-content: center;
}

.dice-slot {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-md);
  border: 2px solid var(--parchment-edge);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  text-align: center;
  background: var(--parchment-light);
  padding: 0.2rem;
}

.dice-slot--common { border-color: var(--steel); }
.dice-slot--uncommon { border-color: #4a9a4a; }
.dice-slot--rare { border-color: #4a7abf; }
.dice-slot--epic { border-color: #9a4abf; }
.dice-slot--legendary { border-color: var(--gold-bright); box-shadow: 0 0 8px rgba(224, 192, 96, 0.4); }

/* --- 16c. Settings Page --- */
.settings-container {
  max-width: 500px;
  margin: 2rem auto;
  padding: 0 1rem;
}

@media (max-width: 768px) {
  .profile-container {
    grid-template-columns: 1fr;
    padding: 1rem;
  }
}

@media (max-width: 480px) {
  .profile-container {
    padding: 0.75rem;
  }

  .profile-avatar-placeholder {
    width: 72px;
    height: 72px;
    font-size: 2rem;
  }
}

/* --- Utility Classes --- */
.text-center { text-align: center; }
.text-gold   { color: var(--gold); }
.text-blood  { color: var(--blood); }
.text-steel  { color: var(--steel); }
.text-light  { color: var(--text-light); }
.text-muted  { color: var(--text-muted); }

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

.d-flex    { display: flex; }
.gap-1     { gap: 0.5rem; }
.gap-2     { gap: 1rem; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

/* --- Navbar / Header --- */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1.5rem;
  background:
    linear-gradient(
      180deg,
      rgba(44, 24, 16, 0.95) 0%,
      rgba(61, 35, 23, 0.95) 100%
    );
  border-bottom: 2px solid var(--wood-grain);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.site-header .site-logo {
  font-family: 'MedievalSharp', Georgia, serif;
  font-size: 1.4rem;
  color: var(--gold);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.site-header nav {
  display: flex;
  gap: 1.2rem;
}

.site-header nav a {
  color: var(--parchment);
  font-family: 'MedievalSharp', Georgia, serif;
  font-size: 0.95rem;
  transition: color var(--transition-fast);
}

.site-header nav a:hover {
  color: var(--gold);
}

/* --- Online Status Indicator --- */
.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.2);
}

.status-dot--online  { background: #5a9a3a; }
.status-dot--ingame  { background: var(--gold); }
.status-dot--offline { background: var(--steel); }

/* --- Friends Panel --- */
.friends-panel {
  min-height: 200px;
  max-height: 500px;
  display: flex;
  flex-direction: column;
}

.friends-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--parchment-edge);
  margin-bottom: 0.8rem;
}

.friends-tab {
  font-family: 'MedievalSharp', Georgia, serif;
  font-size: 0.85rem;
  padding: 0.35rem 0.7rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color var(--transition-fast), border-color var(--transition-fast);
  position: relative;
}

.friends-tab:hover {
  color: var(--ink);
}

.friends-tab--active {
  color: var(--ink);
  border-bottom-color: var(--gold);
}

.friends-badge {
  display: inline-block;
  background: var(--gold);
  color: var(--ink);
  font-family: 'Crimson Text', Georgia, serif;
  font-size: 0.7rem;
  padding: 0 0.35rem;
  border-radius: 8px;
  min-width: 16px;
  text-align: center;
  line-height: 1.4;
  margin-left: 0.2rem;
}

.friends-tab-content {
  overflow-y: auto;
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: var(--parchment-edge) transparent;
}

.friends-subtitle {
  font-family: 'MedievalSharp', Georgia, serif;
  font-size: 0.9rem;
  color: var(--ink-light);
  margin-bottom: 0.4rem;
}

.friends-search-box {
  display: flex;
  gap: 0.4rem;
}

.friends-search-box input {
  flex: 1;
  font-size: 0.9rem;
  padding: 0.4rem 0.6rem;
}

/* --- Friends List Items --- */
.friend-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid rgba(160, 130, 90, 0.2);
}

.friend-item:last-child {
  border-bottom: none;
}

.friend-item .friend-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--parchment-edge);
}

.friend-info {
  flex: 1;
  min-width: 0;
}

.friend-name {
  display: block;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.friend-name:hover {
  color: var(--gold);
}

.friend-level {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.friend-actions {
  display: flex;
  gap: 0.3rem;
  flex-shrink: 0;
}

/* --- Friend Status Dot --- */
.friend-status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.2);
  flex-shrink: 0;
}

.friend-status-dot--online {
  background: #5a9a3a;
  box-shadow: 0 0 4px rgba(90, 154, 58, 0.5);
}

.friend-status-dot--offline {
  background: var(--steel);
}

.friend-status-dot--in_game {
  background: var(--gold);
  box-shadow: 0 0 4px rgba(201, 168, 76, 0.5);
}

/* --- Profile Friend Actions --- */
.profile-friend-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}

/* --- Lobby with friends panel (4 columns) --- */
.lobby-container--with-friends {
  grid-template-columns: 1fr 1fr 260px 300px;
}

@media (max-width: 1100px) {
  .lobby-container--with-friends {
    grid-template-columns: 1fr 1fr 300px;
  }

  .lobby-container--with-friends .friends-panel {
    grid-column: 1 / -1;
    max-height: 300px;
  }
}

@media (max-width: 768px) {
  .lobby-container--with-friends {
    grid-template-columns: 1fr 1fr;
  }

  .lobby-container--with-friends .friends-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 480px) {
  .lobby-container--with-friends {
    grid-template-columns: 1fr;
  }
}

/* --- Scrollbar Styling --- */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: rgba(44, 24, 16, 0.3);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: var(--parchment-edge);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--parchment-dark);
}

/* --- 17. Responsive: Tablet (768px) --- */
@media (max-width: 768px) {
  .lobby-container {
    grid-template-columns: 1fr 1fr;
    padding: 1rem;
  }

  .lobby-container > :nth-child(3) {
    grid-column: 1 / -1;
  }

  .game-container {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "p1     p1"
      "canvas canvas"
      "ctrl   ctrl"
      "chat   chat";
  }

  .player-panel {
    flex-direction: row;
    align-items: center;
    gap: 1rem;
  }

  .chat-panel {
    max-height: 300px;
  }

  .medieval-title {
    font-size: 1.8rem;
  }

  .overlay-title {
    font-size: 2.2rem;
  }
}

/* --- 17. Responsive: Mobile (480px) --- */
@media (max-width: 480px) {
  html {
    font-size: 15px;
  }

  .lobby-container {
    grid-template-columns: 1fr;
    gap: 1rem;
    padding: 0.75rem;
  }

  .game-container {
    grid-template-columns: 1fr;
    grid-template-areas:
      "p1"
      "canvas"
      "ctrl"
      "chat";
    padding: 0.5rem;
    gap: 0.75rem;
  }

  .game-controls {
    flex-wrap: wrap;
  }

  .game-controls .btn {
    min-width: 0;
    flex: 1;
  }

  .canvas-area {
    min-height: 280px;
  }

  .chat-panel {
    max-height: 250px;
    border-radius: var(--radius-md);
  }

  .auth-card {
    padding: 1rem;
  }

  .parchment {
    padding: 1rem;
  }

  .medieval-title {
    font-size: 1.5rem;
  }

  .overlay-title {
    font-size: 1.8rem;
  }

  .overlay--win .overlay-title {
    font-size: 2.2rem;
  }

  .profile-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .site-header {
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
  }

  .site-header nav {
    gap: 0.8rem;
    flex-wrap: wrap;
    justify-content: center;
  }

  .dice-score-display {
    font-size: 2rem;
  }
}

/* --- 18. Animations --- */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

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

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.05); }
}

@keyframes shimmer {
  0%   { background-position: -200% center; }
  100% { background-position: 200% center; }
}

.anim-fade-in  { animation: fadeIn 0.3s ease-out; }
.anim-slide-up { animation: slideUp 0.4s ease-out; }
.anim-pulse    { animation: pulse 1.5s ease-in-out infinite; }

.gold-shimmer {
  background: linear-gradient(
    90deg,
    var(--gold) 0%,
    var(--gold-bright) 40%,
    #fff 50%,
    var(--gold-bright) 60%,
    var(--gold) 100%
  );
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shimmer 3s linear infinite;
}

/* --- 19. Chat Tabs --- */
.chat-tabs {
  display: flex;
  gap: 0;
}

.chat-tab {
  font-family: 'MedievalSharp', Georgia, serif;
  font-size: 0.85rem;
  padding: 0.35rem 0.8rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color var(--transition-fast), border-color var(--transition-fast);
}

.chat-tab:hover {
  color: var(--ink);
}

.chat-tab--active {
  color: var(--ink);
  border-bottom-color: var(--gold);
}

/* --- 20. Lobby Right Column --- */
.lobby-right-col {
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

.lobby-right-col .chat-panel {
  grid-area: unset;
  min-height: 300px;
  max-height: 400px;
}

/* --- 21. Game Chat Overlay --- */
.game-chat-toggle {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 90;
  box-shadow: var(--shadow-md);
}

.game-chat-toggle.active {
  background: var(--gold);
  border-color: #8a7028;
  color: var(--ink);
}

.game-chat-overlay {
  position: fixed;
  inset: 0;
  z-index: 95;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  background: rgba(20, 10, 5, 0.4);
  padding: 1rem;
  animation: overlayIn 0.2s ease-out;
}

.game-chat-overlay-inner {
  width: 360px;
  max-width: 100%;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
}

.game-chat-overlay-inner .chat-panel {
  grid-area: unset;
  max-height: 70vh;
  min-height: 300px;
}

@media (max-width: 768px) {
  .game-chat-overlay-inner {
    width: 100%;
    max-height: 60vh;
  }

  .lobby-right-col .chat-panel {
    min-height: 200px;
    max-height: 300px;
  }
}

@media (max-width: 480px) {
  .game-chat-toggle {
    bottom: 0.5rem;
    right: 0.5rem;
  }

  .game-chat-overlay {
    padding: 0.5rem;
  }

  .game-chat-overlay-inner {
    max-height: 55vh;
  }
}

/* ==========================================================================
   Matchmaking / PvP
   ========================================================================== */

.matchmaking-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid var(--parchment-edge);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: mm-spin 0.8s linear infinite;
}

@keyframes mm-spin {
  to { transform: rotate(360deg); }
}

#matchmaking-status {
  padding: 0.8rem;
  background: var(--parchment-dark);
  border-radius: 6px;
  border: 1px solid var(--parchment-edge);
}

#invite-link-box {
  padding: 0.8rem;
  background: var(--parchment-dark);
  border-radius: 6px;
  border: 1px solid var(--parchment-edge);
}

#invite-link-box .form-control,
#waiting-invite-link {
  background: var(--parchment-light);
  border: 1px solid var(--parchment-edge);
  padding: 0.4rem 0.6rem;
  font-family: monospace;
  color: var(--ink);
}

/* ==========================================================================
   Admin Panel
   ========================================================================== */

.admin-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* Stats Grid */
.admin-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.admin-stat-card {
  text-align: center;
  padding: 1.2rem 1rem;
}

.admin-stat-value {
  font-family: 'MedievalSharp', Georgia, serif;
  font-size: 2.2rem;
  color: var(--blood);
  line-height: 1;
  margin-bottom: 0.3rem;
}

.admin-stat-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Two-column layout */
.admin-two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.2rem;
}

/* Admin Tables */
.admin-table-wrap {
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.admin-table th,
.admin-table td {
  padding: 0.5rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid rgba(160, 130, 90, 0.25);
}

.admin-table th {
  font-family: 'MedievalSharp', Georgia, serif;
  font-size: 0.85rem;
  color: var(--ink-light);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 2px solid var(--parchment-edge);
}

.admin-table tbody tr:hover {
  background: rgba(201, 168, 76, 0.06);
}

.admin-row-inactive {
  opacity: 0.55;
}

/* Badges */
.admin-badge {
  display: inline-block;
  font-family: 'MedievalSharp', Georgia, serif;
  font-size: 0.75rem;
  padding: 0.1rem 0.5rem;
  border-radius: 10px;
  line-height: 1.4;
}

.admin-badge--chat_timeout {
  background: rgba(201, 168, 76, 0.2);
  color: #8a7028;
  border: 1px solid rgba(201, 168, 76, 0.4);
}

.admin-badge--chat_ban {
  background: rgba(139, 26, 26, 0.15);
  color: var(--blood-bright);
  border: 1px solid rgba(139, 26, 26, 0.3);
}

.admin-badge--game_ban {
  background: rgba(139, 26, 26, 0.25);
  color: var(--blood);
  border: 1px solid rgba(139, 26, 26, 0.4);
}

.admin-badge--admin {
  background: rgba(201, 168, 76, 0.3);
  color: var(--ink);
  border: 1px solid var(--gold);
}

/* Report Items */
.admin-report-item {
  padding: 0.8rem 0;
  border-bottom: 1px solid rgba(160, 130, 90, 0.25);
}

.admin-report-item:last-child {
  border-bottom: none;
}

.admin-report-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 0.3rem;
}

.admin-report-message {
  background: rgba(0, 0, 0, 0.04);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--parchment-edge);
  margin: 0.4rem 0;
  font-size: 0.9rem;
  word-break: break-word;
}

.admin-report-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-top: 0.4rem;
}

/* User action buttons row */
.admin-user-actions {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}

/* Pagination */
.admin-pagination {
  display: flex;
  gap: 0.3rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* Responsive */
@media (max-width: 768px) {
  .admin-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .admin-two-col {
    grid-template-columns: 1fr;
  }

  .admin-table {
    font-size: 0.8rem;
  }

  .admin-table th,
  .admin-table td {
    padding: 0.4rem;
  }
}

@media (max-width: 480px) {
  .admin-stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
  }

  .admin-container {
    padding: 0.75rem;
  }

  .admin-stat-value {
    font-size: 1.6rem;
  }

  .admin-report-actions {
    flex-direction: column;
  }

  .admin-user-actions {
    flex-direction: column;
  }
}
