/* ========== Layout principale ========== */
.app-layout {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 0;
  min-height: 100vh;
}
@media (max-width: 880px) {
  .app-layout { grid-template-columns: 1fr; }
}

.app-main {
  max-width: 1280px;
  padding: 24px clamp(16px, 3vw, 32px) 120px;
  min-width: 0;
}

.top-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.01em;
}
.brand-mark {
  width: 34px; height: 34px;
  border-radius: 10px;
  background:
    repeating-linear-gradient(135deg, #1f1710 0 6px, transparent 6px 12px),
    var(--mustard);
  border: 1.5px solid var(--ink);
  box-shadow: 0 2px 0 var(--ink);
  display: grid; place-items: center;
}
.brand-mark::after {
  content: "★";
  font-size: 16px;
  color: #fff8e7;
  text-shadow: 0 1px 0 #0005;
}

.top-user {
  display: flex;
  align-items: center;
  gap: 10px;
}
.current-user {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff8e7;
  border: 1.5px solid var(--ink);
  border-radius: 12px;
  padding: 6px 8px 6px 10px;
  box-shadow: 0 2px 0 #1f17101a;
}
.logout-btn {
  width: 28px; height: 28px;
  border-radius: 6px;
  background: #00000010;
  color: var(--ink);
  font-weight: 700;
}
.logout-btn:hover { background: var(--dice-red); color: #fff; }

/* ========== Badge Dock ========== */
.badge-dock {
  position: sticky;
  top: 0;
  height: 100vh;
  background: #1f1710;
  color: #fff8e7;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-right: 1.5px solid #0005;
  z-index: 2;
}
.badge-dock-title {
  font-size: 11px;
  letter-spacing: 3px;
  color: var(--mustard);
  font-weight: 700;
}
.badge-dock-sub {
  font-size: 12px;
  color: #fff8e7aa;
  line-height: 1.4;
  margin-bottom: 4px;
}
.badge-dock-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 8px;
}
.badge-dock-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px;
  border-radius: 12px;
  transition: background .15s;
}
.badge-dock-item:hover { background: #ffffff08; }
.badge-dock-name {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  color: #fff8e7;
}
.badge-dock-hint {
  margin-top: auto;
  font-size: 10px;
  color: var(--mustard);
  letter-spacing: 1.5px;
  border-top: 1px dashed #fff8e722;
  padding-top: 12px;
  line-height: 1.4;
}

.badge {
  user-select: none;
  transition: transform .15s;
  display: inline-block;
}
.badge:active { cursor: grabbing; transform: scale(.95); }
.badge:hover { transform: translateY(-2px) rotate(-3deg); }

@media (max-width: 880px) {
  .badge-dock {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    top: auto;
    height: auto;
    flex-direction: row;
    padding: 10px 14px;
    overflow-x: auto;
    align-items: center;
    gap: 8px;
    border-top: 1.5px solid #0005;
    border-right: none;
    box-shadow: 0 -10px 30px #0006;
  }
  .badge-dock-title, .badge-dock-sub, .badge-dock-hint { display: none; }
  .badge-dock-list {
    flex-direction: row;
    margin-top: 0;
    gap: 8px;
  }
  .badge-dock-item { padding: 4px; }
  .badge-dock-name { display: none; }
  .app-main { padding-bottom: 120px; }
}

/* ========== Pool bar ========== */
.pool-bar {
  background: #fff8e7;
  border: 1.5px solid var(--ink);
  border-radius: 20px;
  padding: 22px 26px;
  box-shadow: var(--shadow-pop);
  margin-bottom: 20px;
  position: relative;
  overflow: hidden;
}
.pool-bar::before {
  content: "";
  position: absolute; inset: 0;
  background: radial-gradient(500px 200px at 100% 0%, #d9a21b22, transparent 70%);
  pointer-events: none;
}
.pool-bar-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 20px;
  align-items: end;
  position: relative;
  margin-bottom: 18px;
}
@media (max-width: 680px) { .pool-bar-head { grid-template-columns: 1fr; } }
.pool-bar-eyebrow {
  font-size: 10px;
  color: var(--ink-mute);
  letter-spacing: 2px;
  margin-bottom: 4px;
}
.pool-bar-title {
  font-size: clamp(26px, 3.5vw, 40px);
  margin: 0;
  line-height: 1;
  letter-spacing: -0.01em;
}
.pool-bar-sub {
  font-size: 13px;
  color: var(--ink-soft);
  margin: 6px 0 0;
}
.pool-bar-kv {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.tile-kv {
  background: var(--chip-bg);
  border: 1.5px solid var(--chip-edge);
  border-radius: 10px;
  padding: 6px 12px;
  min-width: 90px;
}
.tile-k {
  font-size: 9px;
  letter-spacing: 1.5px;
  color: var(--ink-mute);
}
.tile-v { font-size: 13px; font-weight: 600; }

.pool-slots {
  display: grid;
  grid-template-columns: repeat(12, 1fr) auto;
  gap: 6px;
  align-items: center;
  position: relative;
}
@media (max-width: 680px) {
  .pool-slots {
    grid-template-columns: repeat(12, 1fr);
  }
  .pool-progress-num { grid-column: 1 / -1; text-align: left !important; }
}
.pool-slot2 {
  aspect-ratio: 1;
  background: var(--board-paper-2);
  border: 1.5px dashed #c7b48a;
  border-radius: 8px;
  display: grid;
  place-items: center;
  min-height: 30px;
}
.pool-slot2.filled {
  background: linear-gradient(180deg, #fff2c4, #ffe79a);
  border: 1.5px solid var(--gold-deep);
  animation: pop-in .5s cubic-bezier(.2,.9,.3,1.3);
}
.pool-slot2.target {
  border-style: solid;
  border-color: var(--ink);
}
.pool-slot2.target.filled::before {
  content: "";
  position: absolute; inset: -3px;
  border-radius: 11px;
  border: 2px solid var(--gold);
  pointer-events: none;
}
.pool-slot-flag { font-size: 14px; }
.pool-progress-num {
  padding-left: 16px;
  font-size: 32px;
  line-height: 1;
  font-weight: 700;
  text-align: right;
  white-space: nowrap;
}

/* ========== Section title ========== */
.section-title {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 24px 0 14px;
  flex-wrap: wrap;
}
.section-title h2 {
  font-family: var(--font-display);
  font-size: 24px;
  margin: 0;
  font-weight: 600;
}
.section-title .mono {
  font-size: 10px;
  color: var(--ink-mute);
  letter-spacing: 2px;
}

/* ========== Users grid ========== */
.users-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.user-card-wrap { position: relative; }

.user-card {
  background: #fff8e7;
  border: 1.5px solid var(--ink);
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 2px 0 #1f17101a, 0 8px 20px -10px #1f171022;
  transition: transform .15s, box-shadow .15s;
  position: relative;
}
.user-card:hover { transform: translateY(-2px); box-shadow: 0 3px 0 #1f17101a, 0 14px 30px -12px #1f171033; }

.user-card--me {
  border-color: var(--felt-green);
  box-shadow: 0 3px 0 var(--felt-green), 0 14px 30px -12px #3f7a4d55;
  background: linear-gradient(180deg, #fff8e7, #eef5ea);
}

.user-card--won {
  background:
    radial-gradient(300px 150px at 100% 0%, #ffe79a 0%, transparent 70%),
    #fff8e7;
  border-color: var(--gold-deep);
  box-shadow: 0 3px 0 var(--gold-deep), 0 14px 30px -12px #a97a1055;
}
.user-card--won.user-card--me {
  border-color: var(--gold-deep);
  box-shadow: 0 3px 0 var(--gold-deep), 0 0 0 3px #3f7a4d55, 0 14px 30px -12px #a97a1055;
}
.user-card-medal {
  position: absolute;
  top: -14px; right: 10px;
  animation: pop-in .6s cubic-bezier(.2,.9,.3,1.3);
  z-index: 2;
}
.user-card-me-tag {
  position: absolute;
  top: -10px; left: 12px;
  background: var(--felt-green);
  color: #fff;
  font-size: 9px;
  letter-spacing: 2px;
  padding: 3px 8px;
  border-radius: 4px;
  font-weight: 700;
  box-shadow: 0 2px 0 #1f17101a;
  border: 1.5px solid var(--ink);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}
.user-card--shake { animation: shake .4s ease-in-out; }

.user-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.user-card-id { flex: 1; min-width: 0; }
.user-card-name {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-card-meta {
  font-size: 10px;
  color: var(--ink-mute);
  letter-spacing: 1.2px;
  margin-top: 2px;
}
.user-card--won .user-card-meta {
  color: #5a3f05;
  font-weight: 700;
}

.user-card-admin {
  display: flex;
  gap: 4px;
}
.user-card-admin button {
  width: 26px; height: 26px;
  background: #fff;
  border: 1.5px solid var(--chip-edge);
  border-radius: 6px;
  font-size: 11px;
  color: var(--ink-soft);
}
.user-card-admin button:hover {
  background: var(--ink);
  color: #fff8e7;
  border-color: var(--ink);
}

/* ========== Slots ========== */
.slot-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.slot {
  aspect-ratio: 1;
  background: #f2e9d6;
  border: 1.5px dashed #c7b48a;
  border-radius: 12px;
  display: grid;
  place-items: center;
  transition: all .15s;
  min-height: 52px;
  position: relative;
}
.slot--empty .slot-ghost {
  font-size: 10px;
  color: var(--ink-mute);
  letter-spacing: 1.5px;
  opacity: 0.6;
}
.slot--filled {
  border: 1.5px solid var(--slot-color);
  border-style: solid;
  background: color-mix(in oklab, var(--slot-color) 10%, #fff8e7);
  cursor: pointer;
}
.slot--filled:hover {
  background: color-mix(in oklab, var(--slot-color) 18%, #fff8e7);
}
.slot--over {
  border-color: var(--slot-color);
  border-style: solid;
  background: color-mix(in oklab, var(--slot-color) 15%, #fff8e7);
  transform: scale(1.05);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--slot-color) 30%, transparent);
}
.slot--target {
  border-color: var(--slot-color);
  background: color-mix(in oklab, var(--slot-color) 8%, #fff8e7);
  animation: pulse-target 1.2s ease-in-out infinite;
}
@keyframes pulse-target {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in oklab, var(--slot-color) 30%, transparent); }
  50% { box-shadow: 0 0 0 6px color-mix(in oklab, var(--slot-color) 10%, transparent); }
}

/* ========== Login ========== */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 40px 20px;
  position: relative;
  z-index: 1;
}
.login-card {
  background: #fff8e7;
  border: 1.5px solid var(--ink);
  border-radius: 22px;
  padding: 36px;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-pop);
  position: relative;
}
.login-stripe {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 8px;
  background: linear-gradient(90deg, #c8352a, #d9a21b, #3f7a4d, #2b4b8f, #7a3b6a);
  border-radius: 22px 22px 0 0;
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0 24px;
}
.login-title {
  font-size: 32px;
  margin: 0 0 8px;
  line-height: 1;
  letter-spacing: -0.01em;
}
.login-sub {
  font-size: 14px;
  color: var(--ink-soft);
  margin: 0 0 24px;
  line-height: 1.5;
}
.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-label {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.login-label .mono {
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--ink-mute);
}
.login-input {
  background: #fff;
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 14px;
  outline: none;
}
.login-input:focus {
  box-shadow: 0 0 0 3px #3f7a4d33;
}
.login-error {
  background: #f5d4d1;
  color: #5a1510;
  padding: 10px 12px;
  border: 1.5px solid var(--dice-red);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
}
.login-hint {
  margin-top: 22px;
  padding: 14px;
  background: #f2e9d6;
  border: 1.5px dashed var(--chip-edge);
  border-radius: 10px;
}
.login-hint-title {
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--ink-mute);
  margin-bottom: 8px;
}
.login-hint-grid {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
}
.login-hint-foot {
  margin-top: 8px;
  font-size: 10px;
  color: var(--ink-mute);
  letter-spacing: 1px;
}
.login-decor {
  position: fixed;
  bottom: 20px; right: 20px;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  opacity: 0.5;
  pointer-events: none;
  z-index: 0;
}
@media (max-width: 500px) { .login-decor { display: none; } }

/* ========== Modal ========== */
.modal-backdrop {
  position: fixed; inset: 0;
  background: #1f171099;
  backdrop-filter: blur(3px);
  display: grid; place-items: center;
  z-index: 100;
  padding: 20px;
  animation: fade-in .2s;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  background: #fff8e7;
  border: 1.5px solid var(--ink);
  border-radius: 18px;
  padding: 28px;
  width: 100%;
  max-width: 540px;
  box-shadow: 0 20px 60px -10px #000a;
  position: relative;
  animation: pop-in .35s cubic-bezier(.2,.9,.3,1.3);
  max-height: 90vh;
  overflow-y: auto;
}
.modal-stripe {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 8px;
  background: var(--exam-color, var(--mustard));
  border-radius: 18px 18px 0 0;
}
.modal-close {
  position: absolute;
  top: 14px; right: 14px;
  width: 32px; height: 32px;
  border-radius: 8px;
  color: var(--ink-mute);
  font-weight: 700;
}
.modal-close:hover { background: #00000010; color: var(--ink); }

.modal-head {
  display: flex; gap: 14px;
  margin-bottom: 20px;
  padding-top: 6px;
  align-items: center;
}
.modal-eyebrow {
  font-size: 10px;
  color: var(--ink-mute);
  letter-spacing: 2px;
  margin-bottom: 4px;
}
.modal-title {
  font-size: 22px;
  line-height: 1.1;
  margin: 0;
}

.modal-body { display: flex; flex-direction: column; gap: 14px; }
.modal-label { display: flex; flex-direction: column; gap: 6px; }
.modal-label .mono {
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--ink-mute);
}
.modal-input {
  background: #fff;
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
}
.modal-input:focus {
  border-color: var(--felt-green);
  box-shadow: 0 0 0 3px #3f7a4d33;
}
.modal-readonly {
  font-size: 12px;
  color: var(--ink-soft);
  letter-spacing: 1px;
}
.modal-existing {
  display: inline-block;
  padding: 10px 12px;
  background: #f2e9d6;
  border: 1.5px solid var(--chip-edge);
  border-radius: 10px;
  color: var(--royal-blue);
  text-decoration: none;
  font-size: 12px;
  word-break: break-all;
}
.modal-existing:hover { background: #eae0c2; }

.modal-actions {
  display: flex; gap: 10px;
  margin-top: 20px;
  align-items: center;
  flex-wrap: wrap;
}

/* ========== Admin panel ========== */
.admin-panel { max-width: 620px; }
.admin-badge {
  width: 48px; height: 48px;
  background: #1f1710;
  color: var(--mustard);
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 24px;
  border: 1.5px solid var(--ink);
}
.admin-section {
  margin-top: 20px;
  padding: 16px;
  background: #f2e9d6;
  border: 1.5px dashed #c7b48a;
  border-radius: 12px;
}
.admin-section-title {
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--ink-mute);
  margin-bottom: 12px;
}
.admin-create-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.admin-create-row .modal-input { flex: 1; min-width: 160px; }
.admin-hint-small {
  font-size: 10px;
  color: var(--ink-mute);
  letter-spacing: 1px;
  margin-top: 8px;
}
.admin-user-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
}
.admin-user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff8e7;
  border: 1px solid var(--chip-edge);
  border-radius: 10px;
  padding: 8px 10px;
}

.reveal-card {
  background: linear-gradient(180deg, #fff2c4, #ffe79a);
  border: 1.5px solid var(--gold-deep);
  border-radius: 16px;
  padding: 24px;
  max-width: 400px;
  box-shadow: 0 20px 60px -10px #000a;
  animation: pop-in .35s cubic-bezier(.2,.9,.3,1.3);
}
.reveal-kv {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: #fff;
  border: 1.5px solid var(--gold-deep);
  border-radius: 10px;
  margin-bottom: 8px;
}
.reveal-k {
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--ink-mute);
}
.reveal-v {
  font-weight: 700;
  font-size: 14px;
  color: var(--ink);
}

/* ========== Confetti ========== */
.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 200;
  overflow: hidden;
}
.confetti-piece {
  position: absolute;
  top: 0;
  border-radius: 2px;
  animation: confetti-fall linear forwards;
}

.win-glow {
  background: linear-gradient(90deg, #d9a21b, #e07a1f, #d9a21b);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shimmer 2.5s linear infinite;
}

@media print {
  .badge-dock, .confetti-layer, .modal-backdrop { display: none !important; }
  body { background: white; }
  body::before { display: none; }
}
