:root{
  --card-w: 100px;
  --card-h: 150px;
  --stack-overlap: 30px;
  --bg1: #10202b;
  --bg2: #071018;
  --accent: #0a84ff;
}

*{box-sizing:border-box}
html,body{ height:100%; margin:0; font-family:system-ui,Segoe UI,Roboto,Arial; background:radial-gradient(circle at center,var(--bg1),var(--bg2)); color:#fff; }

.panel{ max-width:1400px; margin:18px auto; padding:16px; background:rgba(0,0,0,0.12); border-radius:10px; box-shadow:0 8px 30px rgba(0,0,0,0.6); }
.hidden{ display:none !important; }

.row{ display:flex; gap:8px; align-items:center; margin:8px 0; }
.centered { justify-content: center; }

input[type="text"], input[type="password"], input[type="number"], input[type="search"]{
  padding:10px 14px; border-radius:8px; border:1px solid rgba(255,255,255,0.1); background:rgba(255,255,255,0.05); color:#fff; font-size:1rem; outline:none; transition: border 0.2s;
}
input:focus { border-color: var(--accent); }

button{ background:var(--accent); color:white; border:none; padding:10px 16px; border-radius:8px; cursor:pointer; font-size:0.95rem; font-weight:600; transition: transform 0.1s, opacity 0.2s; }
button:active{ transform:scale(0.98) }
button:hover { opacity: 0.9; }

.muted{ color:rgba(255,255,255,0.7); }
.small{ font-size:0.9rem; }

.topbar{ display:flex; justify-content:space-between; align-items:flex-start; margin-bottom:8px; }
.top-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.info-row, .controls-row { display: flex; gap: 8px; align-items: center; }

/* Menu / Lobby Styles */
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 20px; }
@media (max-width: 600px) { .mode-grid { grid-template-columns: 1fr; } }

.mode-card {
  background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px; padding: 30px; text-align: center; cursor: pointer;
  transition: transform 0.2s, background 0.2s;
}
.mode-card:hover { transform: translateY(-4px); background: rgba(255,255,255,0.08); border-color: var(--accent); }
.mode-card .icon { font-size: 3rem; margin-bottom: 12px; }
.mode-card h3 { margin: 0 0 8px 0; color: var(--accent); }
.mode-card p { margin: 0; color: #ccc; font-size: 0.9rem; }

.menu-section { animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity:0; transform:translateY(10px); } to { opacity:1; transform:translateY(0); } }

.back-btn { background: transparent; color: #888; padding: 0; margin-bottom: 16px; font-size: 0.9rem; }
.back-btn:hover { color: #fff; background: transparent; }

.control-group { margin: 20px 0; text-align: center; }
.toggle-group { display: flex; gap: 10px; justify-content: center; margin-top: 8px; }
.toggle-btn { background: rgba(255,255,255,0.1); color: #ccc; }
.toggle-btn.active { background: var(--accent); color: #fff; }

.action-btn { width: 100%; max-width: 300px; display: block; margin: 20px auto; padding: 14px; font-size: 1.1rem; }

.big-input { width: 100%; max-width: 400px; text-align: center; font-size: 1.2rem; padding: 12px; }

/* ---------- board layout ---------- */
.game-area{ display:flex; flex-direction:column; gap:4px; align-items:center; margin-top: -10px; }

.card, .borne {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* Board */
.board{
  display:flex;
  gap:16px;
  align-items:center;
  justify-content:center;
  padding:10px;
  flex-wrap:nowrap;
}

/* boundary (borne) */
.borne{
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  position:relative;
  cursor:pointer;
  transition: transform 0.12s ease;
}
.borne:hover{ transform:scale(1.02); }

.borne-core{
  padding:0;
  border-radius:8px;
  transition:border 0.2s ease, box-shadow 0.2s ease;
}
.borne.selected .borne-core{
  border:3px solid yellow;
  box-shadow:0 0 15px rgba(255,255,0,0.6);
}
.borne.won .borne-core{ border:3px solid #00ff80; box-shadow:0 0 18px #00ff80; }
.borne.lost .borne-core{ border:3px solid #ff4040; box-shadow:0 0 18px #ff4040; }

.borne.drop-target .borne-core{ outline:3px dashed #4cf; outline-offset:4px; }

/* stacks */
.stack{ position:relative; width:var(--card-w); height:calc(var(--card-h) + 2*var(--stack-overlap)); }
.stack .card{ position:absolute; width:var(--card-w); height:var(--card-h); border-radius:8px; background-size:cover; background-position:center; box-shadow:0 4px 12px rgba(0,0,0,0.5); }

.stack.player .card:nth-child(1){ bottom:0; }
.stack.player .card:nth-child(2){ bottom:var(--stack-overlap); }
.stack.player .card:nth-child(3){ bottom:calc(var(--stack-overlap)*2); }
.stack.player .card:nth-child(1){ z-index:3; }
.stack.player .card:nth-child(2){ z-index:2; }
.stack.player .card:nth-child(3){ z-index:1; }
.stack.player { margin-top: 1px; }

.stack.opponent{ margin-bottom:1px; transform:rotate(180deg); }
.stack.opponent .card:nth-child(1){ bottom:0; }
.stack.opponent .card:nth-child(2){ bottom:var(--stack-overlap); }
.stack.opponent .card:nth-child(3){ bottom:calc(var(--stack-overlap)*2); }

/* Last played neon effect */
.card.neon-border {
  box-shadow: 0 0 8px #4cf, 0 0 15px #4cf;
  border: 2px solid #4cf;
  /* Removed z-index to avoid stacking issues */
}

.borne-img{ width:var(--card-w); border-radius:8px; margin:1px 0; box-shadow:0 6px 16px rgba(0,0,0,0.6); }

/* hand */
.hand-area{ width:100%; display:flex; justify-content:center; padding:4px 0; padding-bottom: calc(4px + env(safe-area-inset-bottom)); position: relative; }
#scoreboard { position: absolute; left: 10px; bottom: calc(4px + env(safe-area-inset-bottom)); z-index: 20; transform: scale(0.85); transform-origin: bottom left; }
.hand{ display:flex; align-items:flex-end; position:relative; user-select:none; touch-action:none; }
.hand .card{ width:var(--card-w); height:var(--card-h); border-radius:10px; background-size:cover; background-position:center; box-shadow:0 8px 20px rgba(0,0,0,0.6); margin-left:-50px; cursor:grab; transition:transform 0.22s ease, box-shadow 0.22s ease; position:relative; }
.hand .card:first-child{ margin-left:0; }
.hand .card:hover{ transform:translateY(-10px) scale(1.05); }
.hand .card.dragging{ z-index:1000; transform:scale(1.08); box-shadow:0 18px 30px rgba(0,0,0,0.8); }

.placeholder{ width:var(--card-w); height:var(--card-h); border-radius:10px; border:2px dashed rgba(255,255,255,0.08); margin-left:-50px; background:rgba(255,255,255,0.02); }

.controls{ display:flex; gap:8px; align-items:center; margin-top:8px; min-height: 40px; }

.error-msg {
  background: rgba(255, 60, 60, 0.15);
  color: #ff6b6b;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid rgba(255, 60, 60, 0.3);
  font-weight: 500;
  display: inline-block;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* Scoreboard Table */
.scoreboard-container {
  display: flex;
  flex-direction: column;
  background: rgba(0,0,0,0.25);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.85rem;
}
.score-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.score-name {
  width: 80px;
  font-weight: 600;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  text-align: left;
}
.score-cells {
  display: flex;
  gap: 4px;
}
.score-val {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  background: rgba(255,255,255,0.05);
}
.score-val.win {
  background: #00b37e; /* Green highlight */
  color: white;
  font-weight: bold;
}

/* lobby list styling */
.games-container { display:flex; flex-direction:column; gap:8px; margin-top:8px; }
.lobby-row { display:flex; justify-content:space-between; align-items:center; padding:8px; background:rgba(255,255,255,0.03); border-radius:8px; }
.lobby-meta { display:flex; flex-direction:column; gap:2px; }
.join-lobby-btn { background:#0a84ff; color:white; border:none; padding:6px 10px; border-radius:6px; cursor:pointer; }

/* New Topbar Elements */
.circle-btn {
  width: 40px; height: 40px; border-radius: 50%; padding: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; background: rgba(255,255,255,0.1); box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  border: 1px solid rgba(255,255,255,0.15);
  transition: transform 0.1s, background 0.1s;
}
.circle-btn:hover { transform: scale(1.1); background: rgba(255,255,255,0.2); }

.badge {
  background: rgba(255,255,255,0.1); width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-weight: bold;
  border: 1px solid rgba(255,255,255,0.15); font-size: 0.95rem;
}

#turnLabel {
  padding: 8px 16px; background: rgba(255,255,255,0.1); border-radius: 20px;
  border: 1px solid rgba(255,255,255,0.15); font-size: 0.9rem;
  min-width: 100px; text-align: center;
}

/* Stats Grid (Shared) */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 15px; margin-bottom: 30px; margin-top: 10px; }
.stat-card { background: rgba(0,0,0,0.2); padding: 15px; border-radius: 8px; text-align: center; border: 1px solid rgba(255,255,255,0.05); }
.stat-card h4 { margin: 0 0 5px; color: #888; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 1px; }
.stat-card .value { font-size: 1.4em; font-weight: bold; color: white; }

/* === Title Animation === */
.title-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-top: 60px; /* Space from top controls */
    margin-bottom: 30px;
    height: 140px;
    perspective: 1000px;
}

.title-part {
    max-width: 80%;
    width: 280px;
    height: auto;
    opacity: 0; 
    filter: drop-shadow(0 15px 25px rgba(0,0,0,0.6));
    will-change: transform, opacity;
}

.title-schotten {
    z-index: 2;
    margin-bottom: -15px;
    transform: translateY(-800px);
}
.title-totten {
    z-index: 1;
    transform: translateY(-800px);
}

@keyframes stoneDrop {
    0% { transform: translateY(-800px) scale(1.1); opacity: 1; }
    60% { transform: translateY(20px) scale(0.95); }
    75% { transform: translateY(-10px) scale(1.02); }
    100% { transform: translateY(0) scale(1); opacity: 1; }
}

.animate-drop {
    animation: stoneDrop 0.8s cubic-bezier(0.19, 1, 0.22, 1) forwards;
}

.dust-puff {
    position: absolute;
    width: 20px;
    height: 20px;
    background: radial-gradient(circle, rgba(220,220,200,0.6) 0%, transparent 70%);
    border-radius: 50%;
    opacity: 0;
    pointer-events: none;
    z-index: 0;
}

@keyframes puffAnim {
    0% { transform: translate(0, 0) scale(0.5); opacity: 0.8; }
    100% { transform: translate(var(--tx), var(--ty)) scale(3); opacity: 0; }
}

.animate-puff {
    animation: puffAnim 0.8s ease-out forwards;
}

/* === Timeout Vanish Animation === */
@keyframes vanish {
  0% { opacity: 1; transform: scale(1); }
  10% { opacity: 0; transform: scale(0.9); }
  20% { opacity: 1; transform: scale(1); }
  100% { opacity: 1; transform: scale(1); }
}

.borne.vanish-anim .borne-core {
  animation: vanish 1.5s linear 2;
  animation-fill-mode: forwards;
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(4px);
}

.modal-content-styled {
  position: relative;
  background: rgba(16, 32, 43, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 24px 32px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  max-width: 400px;
  width: 90%;
  text-align: center;
  color: #fff;
}

.modal-title {
  margin: 0 0 8px;
  font-size: 1.5rem;
  color: #fff;
}

.modal-text {
  margin: 0 0 20px;
  color: rgba(255, 255, 255, 0.8);
  font-size: 1rem;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

.btn-ghost {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: rgba(255, 255, 255, 0.8);
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
}
.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.5);
  color: #fff;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.4);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: color 0.2s, background 0.2s;
}
.modal-close:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}
