/* ══════════════════════════════════════════════════════════════════════════
   L.A.M.A. – Global styles
   ══════════════════════════════════════════════════════════════════════════ */

/* ── Custom properties ──────────────────────────────────────────────────── */
:root {
  --bg:           #1a1a2e;
  --surface:      #16213e;
  --surface-2:    #0f3460;
  --accent:       #e94560;
  --accent-hover: #c73652;
  --success:      #4ecca3;
  --warning:      #f5a623;
  --text:         #eaeaea;
  --text-muted:   #8892a4;
  --border:       rgba(255,255,255,.08);
  --radius:       12px;
  --radius-card:  10px;
  --shadow:       0 4px 24px rgba(0,0,0,.4);

  /* Card sprite sheet dimensions */
  --card-w:       106px;
  --card-h:       160px;
  --sprite-total: 848px;   /* 8 × 106 */

  /* Scaled-down card for table view */
  --card-mini-scale: 0.55;
  --card-mini-w:  calc(var(--card-w) * var(--card-mini-scale));
  --card-mini-h:  calc(var(--card-h) * var(--card-mini-scale));
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body               { height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  user-select: none;
  touch-action: manipulation;
}

/* ── Views ──────────────────────────────────────────────────────────────── */
.view {
  display: none;
  flex-direction: column;
  width: 100%;
  height: 100%;
  position: fixed;
  inset: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.view.active { display: flex; }

/* ════════════════════════════════════════════════════════════════════════ */
/* LANDING                                                                  */
/* ════════════════════════════════════════════════════════════════════════ */
#view-landing {
  justify-content: center;
  align-items: center;
  gap: 32px;
  padding: 24px;
  background: radial-gradient(ellipse at 50% 0%, #0f3460 0%, var(--bg) 70%);
}

.landing-hero { text-align: center; }
.logo-text {
  font-size: clamp(3rem, 12vw, 5rem);
  font-weight: 900;
  letter-spacing: .1em;
  background: linear-gradient(135deg, #e94560, #f5a623, #4ecca3);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.logo-text.small { font-size: 1.4rem; }
.logo-sub { color: var(--text-muted); font-size: .9rem; margin-top: 4px; letter-spacing: .05em; }

.card-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow);
}

.field-group { display: flex; flex-direction: column; gap: 6px; }
.field-group label { font-size: .8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }

input[type="text"] {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  padding: 12px 14px;
  outline: none;
  width: 100%;
  transition: border-color .2s;
}
input[type="text"]:focus { border-color: var(--accent); }
input[type="text"]::placeholder { color: var(--text-muted); }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 13px 20px;
  border-radius: 8px;
  border: none;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s, opacity .15s;
  touch-action: manipulation;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.wide { width: 100%; }

.btn-primary   { background: var(--accent);    color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: #1a4a80; }

.btn-accent    { background: var(--success); color: #1a1a2e; }
.btn-accent:hover:not(:disabled) { background: #3ab88f; }

.btn-danger    { background: #7b1d1d; color: #ffb3b3; border: 1px solid #c0392b; }
.btn-danger:hover:not(:disabled) { background: #a22626; }

.btn-ghost {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: .85rem;
  padding: 6px 10px;
  border-radius: 6px;
  transition: color .15s, background .15s;
}
.btn-ghost:hover { color: var(--text); background: var(--border); }
.btn-ghost.small { font-size: .75rem; }

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  width: 40px;
  height: 40px;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
.icon-btn:hover { background: var(--border); }

.toggle-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 1rem;
  cursor: pointer;
  transition: all .15s;
}
.toggle-btn.active { background: var(--surface-2); color: var(--text); border-color: var(--accent); }

.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }
.btn-col { display: flex; flex-direction: column; gap: 10px; padding: 16px 24px; }

.error-msg { color: var(--accent); font-size: .85rem; text-align: center; }
.hint-text  { color: var(--text-muted); font-size: .85rem; text-align: center; padding: 8px; }
.label-small { font-size: .75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }

/* ════════════════════════════════════════════════════════════════════════ */
/* LOBBY                                                                    */
/* ════════════════════════════════════════════════════════════════════════ */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.page-header h2 { font-size: 1.1rem; font-weight: 700; }

.lobby-code-block {
  text-align: center;
  padding: 24px 20px 16px;
  border-bottom: 1px solid var(--border);
}
.code-display {
  font-size: clamp(2rem, 10vw, 3rem);
  font-weight: 900;
  letter-spacing: .25em;
  color: var(--success);
  font-family: 'Courier New', monospace;
  margin: 8px 0;
}

.player-list {
  flex: 1;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.player-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  animation: slideIn .2s ease;
}
.player-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .9rem;
  flex-shrink: 0;
}
.player-name    { font-weight: 600; flex: 1; }
.player-badge   { font-size: .7rem; color: var(--text-muted); background: var(--surface-2); padding: 2px 8px; border-radius: 12px; }
.player-badge.host { color: var(--warning); }

#lobby-host-actions { padding: 16px 20px; }

@keyframes slideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ════════════════════════════════════════════════════════════════════════ */
/* CARD SPRITE                                                              */
/* ════════════════════════════════════════════════════════════════════════ */
.card {
  width: var(--card-w);
  height: var(--card-h);
  background-image: url('/assets/cards.webp');
  background-repeat: no-repeat;
  background-size: var(--sprite-total) var(--card-h);
  border-radius: var(--radius-card);
  box-shadow: 0 2px 8px rgba(0,0,0,.5);
  flex-shrink: 0;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s;
}

/* Sprite positions – sheet order: back(0) 1(1) 2(2) 3(3) 4(4) 5(5) 6(6) lama(7) */
.card-back  { background-position: calc(0 * -106px) 0; cursor: default; }
.card-1     { background-position: calc(1 * -106px) 0; }
.card-2     { background-position: calc(2 * -106px) 0; }
.card-3     { background-position: calc(3 * -106px) 0; }
.card-4     { background-position: calc(4 * -106px) 0; }
.card-5     { background-position: calc(5 * -106px) 0; }
.card-6     { background-position: calc(6 * -106px) 0; }
.card-lama  { background-position: calc(7 * -106px) 0; }

/* Mini cards for table view */
.card.mini {
  width:  var(--card-mini-w);
  height: var(--card-mini-h);
  background-size: calc(var(--sprite-total) * var(--card-mini-scale))
                   calc(var(--card-h)       * var(--card-mini-scale));
  border-radius: 6px;
}
/* Recalculate mini positions */
.card.mini.card-back { background-position: calc(0 * var(--card-mini-w) * -1) 0; }
.card.mini.card-1    { background-position: calc(1 * var(--card-mini-w) * -1) 0; }
.card.mini.card-2    { background-position: calc(2 * var(--card-mini-w) * -1) 0; }
.card.mini.card-3    { background-position: calc(3 * var(--card-mini-w) * -1) 0; }
.card.mini.card-4    { background-position: calc(4 * var(--card-mini-w) * -1) 0; }
.card.mini.card-5    { background-position: calc(5 * var(--card-mini-w) * -1) 0; }
.card.mini.card-6    { background-position: calc(6 * var(--card-mini-w) * -1) 0; }
.card.mini.card-lama { background-position: calc(7 * var(--card-mini-w) * -1) 0; }

/* ════════════════════════════════════════════════════════════════════════ */
/* PLAYING VIEW – HAND                                                      */
/* ════════════════════════════════════════════════════════════════════════ */
#view-playing {
  background: #111827;
  overflow: hidden;
}

/* Status bar */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}
.status-left { display: flex; align-items: center; gap: 10px; }
.status-right { display: flex; align-items: center; gap: 8px; }

.turn-badge {
  display: inline-flex;
  align-items: center;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: .8rem;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--text-muted);
  transition: background .3s, color .3s;
}
.turn-badge.your-turn {
  background: var(--success);
  color: #0a1a14;
  animation: pulse 1.5s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(78,204,163,.4); }
  50%       { box-shadow: 0 0 0 8px rgba(78,204,163,0); }
}

/* Last action */
.last-action-bar {
  padding: 6px 16px;
  background: rgba(0,0,0,.3);
  font-size: .78rem;
  color: var(--text-muted);
  text-align: center;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

/* Stacks */
.play-area {
  padding: 16px;
  flex-shrink: 0;
  display: flex;
  justify-content: center;
}
.stack-area {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  justify-content: center;
}
.stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  position: relative;
}
.stack-count {
  font-size: .75rem;
  color: var(--text-muted);
  background: rgba(0,0,0,.4);
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
}
.stack-label {
  font-size: .7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.closed-stack .card { cursor: default; }

/* Action buttons */
.action-bar {
  display: flex;
  gap: 12px;
  padding: 8px 16px;
  flex-shrink: 0;
}
.action-bar .btn { flex: 1; padding: 11px; font-size: .9rem; }

/* Hand */
.hand-wrapper {
  flex: 1;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 8px 16px 0;
}
.hand-container {
  position: relative;
  width: var(--card-w);
}

/* Individual cards in hand */
.hand-card {
  position: absolute;
  left: 0;
  transition: top .25s ease, opacity .25s, box-shadow .2s;
}
.hand-card.playable {
  box-shadow: 0 0 0 2px var(--success), 0 4px 16px rgba(78,204,163,.4);
}
.hand-card.playable:hover,
.hand-card.playable:active {
  transform: translateX(-4px) scale(1.04);
  box-shadow: 0 0 0 3px var(--success), 0 8px 24px rgba(78,204,163,.5);
  z-index: 100 !important;
}
.hand-card.not-playable {
  opacity: .55;
  filter: brightness(.7);
  cursor: default;
  pointer-events: none;
}
.hand-card.not-playable-own-turn {
  /* on your turn but can't play this card */
  opacity: .6;
  filter: brightness(.6);
  cursor: default;
  pointer-events: none;
}
.hand-card.waiting {
  /* not your turn */
  opacity: .9;
  cursor: default;
  pointer-events: none;
}

/* ── Scores slide-in panel ──────────────────────────────────────────── */
.scores-panel {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}
.scores-panel.open {
  opacity: 1;
  pointer-events: all;
}
.scores-panel-inner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 480px;
  padding: 0 0 env(safe-area-inset-bottom, 16px);
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(.32,.72,0,1);
}
.scores-panel.open .scores-panel-inner { transform: translateY(0); }
.scores-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.scores-panel-header h3 { font-size: 1rem; font-weight: 700; }

.scores-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
.scores-table th {
  text-align: left;
  padding: 8px 20px;
  color: var(--text-muted);
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
}
.scores-table td {
  padding: 10px 20px;
  border-bottom: 1px solid rgba(255,255,255,.04);
}
.scores-table tr:last-child td { border-bottom: none; }
.scores-table td:nth-child(2),
.scores-table td:nth-child(3) { text-align: right; }
.scores-table td.highlight { color: var(--success); font-weight: 700; }
.scores-table.big td { padding: 12px 20px; font-size: 1rem; }

/* ════════════════════════════════════════════════════════════════════════ */
/* TABLE OVERVIEW VIEW                                                      */
/* ════════════════════════════════════════════════════════════════════════ */
#view-table {
  overflow: hidden;
  background: #0d1117;
}

.table-toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.table-code-display {
  font-family: monospace;
  font-size: .9rem;
  letter-spacing: .15em;
  color: var(--success);
  font-weight: 700;
}
.view-toggle { display: flex; gap: 4px; margin-left: auto; }

.table-scores-compact {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  font-size: .75rem;
}
.score-chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px;
  white-space: nowrap;
}
.score-chip.current-turn { border-color: var(--success); color: var(--success); }

/* Helicopter / table surface */
.heli-view, .pov-view { flex: 1; position: relative; overflow: hidden; }

.table-surface {
  width: 100%;
  height: 100%;
  position: relative;
}

.table-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.table-stacks {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: center;
}
.table-stacks.pov { gap: 24px; }
.table-action {
  font-size: .75rem;
  color: var(--text-muted);
  text-align: center;
  max-width: 200px;
  min-height: 18px;
}

/* Player zones (helicopter) */
.player-zone {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transform-origin: center center;
}
.player-zone-name {
  font-size: .7rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  background: rgba(0,0,0,.6);
  padding: 2px 8px;
  border-radius: 10px;
}
.player-zone-name.current { color: var(--success); }
.player-zone-name.quit    { color: var(--text-muted); text-decoration: line-through; }
.player-zone-cards {
  display: flex;
  gap: -4px;
}
.player-zone-card-back {
  width: var(--card-mini-w);
  height: var(--card-mini-h);
  background-image: url('/assets/cards.webp');
  background-repeat: no-repeat;
  background-size: calc(var(--sprite-total) * var(--card-mini-scale))
                   calc(var(--card-h)       * var(--card-mini-scale));
  background-position: 0 0;
  border-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,.5);
  margin-left: -12px;
}
.player-zone-card-back:first-child { margin-left: 0; }
.player-zone-count {
  font-size: .7rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* POV view */
.pov-view {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 12px;
  gap: 12px;
}
.pov-others {
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
  flex: 1;
  flex-wrap: wrap;
  gap: 8px;
}
.pov-center { display: flex; justify-content: center; align-items: center; flex-shrink: 0; }
.pov-self {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  flex-shrink: 0;
  padding-bottom: 8px;
}
.pov-player {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.pov-player-name {
  font-size: .7rem;
  color: var(--text-muted);
  text-align: center;
  white-space: nowrap;
}
.pov-player-name.current { color: var(--success); font-weight: 700; }

/* ════════════════════════════════════════════════════════════════════════ */
/* ROUND END VIEW                                                           */
/* ════════════════════════════════════════════════════════════════════════ */
#view-round-end {
  justify-content: flex-start;
  padding-top: 0;
}
.round-end-content { flex: 1; overflow-y: auto; padding: 0 0 16px; }

/* ════════════════════════════════════════════════════════════════════════ */
/* TOAST                                                                    */
/* ════════════════════════════════════════════════════════════════════════ */
.toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 10px 20px;
  font-size: .85rem;
  color: var(--text);
  box-shadow: var(--shadow);
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  white-space: nowrap;
  z-index: 999;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.error { border-color: var(--accent); color: var(--accent); }
.toast.success { border-color: var(--success); color: var(--success); }

/* ════════════════════════════════════════════════════════════════════════ */
/* RESPONSIVE / ORIENTATION                                                 */
/* ════════════════════════════════════════════════════════════════════════ */
@media (orientation: landscape) and (max-height: 500px) {
  /* Landscape phone: compact layout */
  .play-area    { padding: 8px; }
  .action-bar   { padding: 4px 12px; }
  .status-bar   { padding: 8px 14px; }
}

@media (min-width: 768px) {
  /* Tablet / desktop: table view is default */
  #view-playing .hand-wrapper { align-items: flex-start; padding-top: 0; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
