/* =====================================================
   LearnEuchre — Stylesheet
   ===================================================== */

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

:root {
  --green:        #2d6a4f;
  --green-dark:   #1b4332;
  --green-light:  #40916c;
  --felt:         #1e5631;
  --gold:         #f4a261;
  --gold-dark:    #e76f51;
  --cream:        #fefae0;
  --text-light:   #fefae0;
  --text-dark:    #1a1a2e;
  --card-bg:      #ffffff;
  --card-border:  #cccccc;
  --shadow:       0 4px 16px rgba(0,0,0,0.35);
  --radius:       8px;
  --red:          #d62828;
  --trump-color:  #f4d35e;
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--green-dark);
  color: var(--text-light);
  overflow: hidden;
}

/* ---------- Screens ---------- */
.screen { display: none; height: 100vh; height: 100dvh; width: 100vw; position: fixed; inset: 0; }
.screen.active { display: flex; }

/* ---------- Start Screen ---------- */
#screen-start {
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, var(--green) 0%, var(--green-dark) 80%);
}

.start-content {
  display: grid;
  gap: 1rem;
  width: min(94vw, 560px);
  max-height: 94vh;
  max-height: 94dvh;
  overflow-y: auto;
}

.start-card {
  background: rgba(0,0,0,0.45);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 16px;
  padding: 3rem 4rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow);
}

.ad-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  padding: 0.65rem;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 16px;
  background: rgba(0,0,0,0.35);
  box-shadow: var(--shadow);
}

.ad-label {
  margin-bottom: 0.35rem;
  color: rgba(254,250,224,0.6);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-align: center;
  text-transform: uppercase;
}

.ad-card .adsbygoogle {
  min-height: 250px;
  border-radius: 8px;
  background: rgba(254,250,224,0.08);
}

.start-card h1 {
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--trump-color);
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

.tagline { font-size: 1.1rem; opacity: 0.8; }

/* ---------- Rules Screen ---------- */
#screen-rules {
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  background: var(--green-dark);
  overflow-y: auto;
  padding: 2rem 1rem;
}

.rules-container {
  max-width: 680px;
  width: 100%;
  background: rgba(0,0,0,0.35);
  border-radius: 12px;
  padding: 2rem;
  box-shadow: var(--shadow);
}

.rules-container h2 {
  font-size: 1.8rem;
  color: var(--trump-color);
  margin-bottom: 1.5rem;
  text-align: center;
}

.rules-content h3 {
  font-size: 1.1rem;
  color: var(--gold);
  margin-top: 1.2rem;
  margin-bottom: 0.4rem;
}

.rules-content p, .rules-content ol, .rules-content li {
  font-size: 0.95rem;
  line-height: 1.6;
  opacity: 0.92;
}

.rules-content ol { padding-left: 1.4rem; }

.rules-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.6rem 0;
  font-size: 0.9rem;
}
.rules-table th, .rules-table td {
  border: 1px solid rgba(255,255,255,0.2);
  padding: 0.4rem 0.7rem;
  text-align: left;
}
.rules-table th { background: rgba(255,255,255,0.1); color: var(--gold); }

/* ---------- Buttons ---------- */
.btn {
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  padding: 0.6rem 1.4rem;
  font-size: 0.95rem;
  font-weight: 600;
  transition: transform 0.1s, filter 0.1s;
}
.btn:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn:active { transform: translateY(0); filter: brightness(0.95); }

.btn-primary  { background: var(--gold); color: var(--text-dark); }
.btn-secondary { background: rgba(255,255,255,0.15); color: var(--text-light); border: 1px solid rgba(255,255,255,0.3); }
.btn-danger   { background: var(--red); color: #fff; }
.btn-hint     { background: transparent; border: 1px solid rgba(244,162,97,0.45); color: var(--gold); font-size: 0.82rem; opacity: 0.85; }
.btn-hint:hover { background: rgba(244,162,97,0.15); opacity: 1; }
.btn-lg       { padding: 0.85rem 2.2rem; font-size: 1.1rem; }
.btn-sm       { padding: 0.35rem 0.9rem; font-size: 0.85rem; }

/* ---------- Game Screen ---------- */
#screen-game {
  flex-direction: column;
  background: var(--felt);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* Score Bar */
.score-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0,0,0,0.4);
  padding: 0.5rem 1.5rem;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.score-team {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 100px;
}
.team-label { font-size: 0.75rem; opacity: 0.7; text-transform: uppercase; letter-spacing: 1px; }
.team-score { font-size: 2rem; font-weight: 800; color: var(--trump-color); line-height: 1; }

.trump-display {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--trump-color);
  letter-spacing: 1px;
  text-align: center;
}

/* Game body — table + right sidebar */
.game-body {
  flex: 1;
  display: flex;
  flex-direction: row;
  overflow: hidden;
}

/* Table */
.table {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem;
  overflow: hidden;
}

/* Player Areas */
.player-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.player-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.75;
  background: rgba(0,0,0,0.3);
  padding: 2px 10px;
  border-radius: 10px;
}

.play-indicator {
  font-size: 0.75rem;
  color: var(--trump-color);
  height: 1.1em;
  font-style: italic;
}

/* Middle row layout */
.middle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  flex: 1;
  max-height: 260px;
  gap: 0.5rem;
  padding: 0 0.5rem;
}

.player-left, .player-right {
  flex-direction: column;
  align-items: center;
  width: 90px;
}

/* Hands */
.hand { display: flex; align-items: center; justify-content: center; }

/* Keep empty hand slots from collapsing so the table doesn't shift */
.hand-bottom { min-height: 112px; }
.hand-top    { min-height: 90px; }
.hand-left, .hand-right { min-width: 64px; }

/* Horizontal hands (top/bottom) */
.hand-top, .hand-bottom {
  flex-direction: row;
  flex-wrap: nowrap;
  gap: -8px;
}

/* Vertical hands (left/right) — rotated */
.hand-left, .hand-right {
  flex-direction: column;
  gap: -8px;
}

/* ---------- Cards ---------- */
.card {
  width: 80px;
  height: 112px;
  border-radius: 6px;
  position: relative;
  box-shadow: 1px 1px 4px rgba(0,0,0,0.3);
  user-select: none;
  transition: transform 0.15s, box-shadow 0.15s;
  flex-shrink: 0;
  overflow: hidden;
  background: #fff; /* visible briefly before SVG renders */
}

/* playing-card web component fills the card container */
.card playing-card {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
}

.card playing-card img {
  width: 100%;
  height: 100%;
  display: block;
  /* kill the native image-drag ghost — real dragging is handled by .card */
  -webkit-user-drag: none;
}

/* Playable card in human's hand */
.card.playable {
  cursor: pointer;
  border-color: var(--gold);
}
.card.playable:hover {
  transform: translateY(-10px);
  box-shadow: 0 8px 20px rgba(0,0,0,0.5);
  z-index: 10;
}

/* Selected / highlighted */
.card.selected { transform: translateY(-14px); border-color: var(--gold-dark); box-shadow: 0 10px 24px rgba(244,162,97,0.6); }

/* Card that can't legally be played this trick — click explains why */
.card.illegal { cursor: not-allowed; }

/* Discard mode — red "throw away" styling, distinct from playable gold */
.card.discardable {
  cursor: pointer;
  outline: 2px solid var(--red);
  outline-offset: -2px;
}
.card.discardable:hover {
  transform: translateY(-10px);
  box-shadow: 0 8px 20px rgba(214, 40, 40, 0.6);
  z-index: 10;
}

/* Pressed card settles instantly — the hover raise must not slide the card
   out from under a click already in progress */
.card.playable:active,
.card.discardable:active {
  transform: translateY(-4px);
  transition: none;
}

.play-indicator.warn-hint {
  color: var(--red);
  font-weight: 700;
  font-style: normal;
  font-size: 0.95rem;
}

/* Trump indicator badge on card */
.card.trump-card::after {
  content: '★';
  position: absolute;
  top: 2px;
  right: 3px;
  font-size: 0.55rem;
  color: var(--gold);
  z-index: 1;
}

/* Overlap in hand */
.hand-bottom .card + .card,
.hand-top .card + .card { margin-left: -28px; }

/* Smaller face-down cards for AI hands */
.hand-top .card,
.hand-left .card,
.hand-right .card { width: 64px; height: 90px; }

.hand-left .card + .card,
.hand-right .card + .card { margin-top: -44px; }

/* ---------- Play Area ---------- */
.play-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.played-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.played-card-slot {
  width: 84px;
  height: 116px;
  border: 1px dashed rgba(255,255,255,0.2);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.played-card-slot .card { width: 80px; height: 112px; cursor: default; }

/* Your slot invites the drop while a card is being dragged; solid while hovered */
.played-card-slot.drop-armed {
  border-color: var(--gold);
}
.played-card-slot.drop-hover {
  border: 1px solid var(--gold);
  background: rgba(244, 162, 97, 0.15);
  box-shadow: 0 0 14px rgba(244, 162, 97, 0.45);
}

.trick-count {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--trump-color);
  opacity: 1;
  text-align: center;
  min-width: 72px;
  line-height: 1.5;
  background: rgba(0,0,0,0.45);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  padding: 4px 8px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}

/* ---------- Action Panel (right sidebar) ---------- */
.action-panel {
  background: rgba(0,0,0,0.4);
  border-left: 1px solid rgba(255,255,255,0.1);
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.75rem;
  width: 210px;
  flex-shrink: 0;
  overflow: hidden;
}

.message-text {
  font-size: 0.9rem;
  flex: 1;
  opacity: 0.95;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding-right: 0.6rem;
}

.message-text p {
  margin: 0;
  line-height: 1.4;
}

.message-text p:last-child {
  font-weight: 600;
  opacity: 1;
}

.message-text p:not(:last-child) {
  opacity: 0.6;
}

/* New log entries flash a highlight for ~1s before the next action */
.message-text p.msg-new {
  animation: msg-flash 1s ease-out;
  border-radius: 4px;
  padding: 0 4px;
  margin: 0 -4px;
}

@keyframes msg-flash {
  0%   { color: var(--trump-color); background: rgba(244, 212, 94, 0.28); opacity: 1; }
  55%  { color: var(--trump-color); background: rgba(244, 212, 94, 0.15); }
  100% { color: var(--text-light); background: transparent; }
}

.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.action-buttons .btn {
  width: 100%;
}

.hint-sep {
  border: none;
  border-top: 1px solid rgba(255,255,255,0.12);
  margin: 0.15rem 0;
}

/* ---------- Advice modal ---------- */
.advice-content {
  text-align: left;
  line-height: 1.7;
  font-size: 0.92rem;
}

/* ---------- Game log modal ---------- */
.game-log {
  text-align: left;
  font-size: 0.85rem;
  line-height: 1.5;
}

.game-log p {
  margin: 0 0 0.15rem;
}

.game-log-entry {
  display: flex;
  gap: 0.6rem;
  align-items: baseline;
}

.game-log-divider {
  display: block;
  text-align: center;
  font-weight: 700;
  color: var(--trump-color);
  border-top: 1px solid rgba(255,255,255,0.2);
  margin-top: 0.6rem;
  padding-top: 0.4rem;
}

.game-log-divider:first-child {
  border-top: none;
  margin-top: 0;
  padding-top: 0;
}

.game-log-hand {
  flex-shrink: 0;
  min-width: 7.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

/* Miniature card inline in text — white face, red or black pip */
.mini-card {
  display: inline-block;
  background: var(--card-bg);
  border-radius: 3px;
  padding: 0 0.24em;
  font-weight: 700;
  font-size: 0.95em;
  line-height: 1.4;
  box-shadow: 0 1px 2px rgba(0,0,0,0.4);
}
.mini-card .pip { font-size: 1.25em; line-height: 1; }
.mini-card.red   { color: var(--red); }
.mini-card.black { color: var(--text-dark); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: #1b3a2f;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 12px;
  padding: 2rem;
  max-width: 400px;
  width: 90%;
  max-height: 85vh;
  max-height: 85dvh;
  box-shadow: var(--shadow);
  text-align: center;
  display: flex;
  flex-direction: column;
}

.modal-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--trump-color);
  margin-bottom: 0.8rem;
  flex-shrink: 0;
}

.modal-body {
  font-size: 0.95rem;
  line-height: 1.6;
  margin-bottom: 1.4rem;
  opacity: 0.9;
  overflow-y: auto;
  flex-shrink: 1;
  min-height: 0;
  padding-right: 0.8rem;
  margin-right: -0.8rem;
}

.modal > .ad-card {
  margin-top: 1.2rem;
  flex-shrink: 0;
}

.modal-actions {
  display: flex;
  gap: 0.7rem;
  justify-content: center;
  flex-wrap: wrap;
  flex-shrink: 0;
}

/* ---------- Suit symbols ---------- */

.suit-spades   .card-suit::before { content: '♠'; }
.suit-hearts   .card-suit::before { content: '♥'; }
.suit-diamonds .card-suit::before { content: '♦'; }
.suit-clubs    .card-suit::before { content: '♣'; }

/* ---------- Small screens ---------- */

/* Narrow screens: move the action panel under the table as a bottom bar so
   the buttons are reachable and the sidebar stops eating the table's width */
@media (max-width: 640px) {
  .game-body { flex-direction: column; }

  .action-panel {
    width: 100%;
    border-left: none;
    border-top: 1px solid rgba(255,255,255,0.1);
    padding: 0.4rem 0.6rem;
    padding-bottom: max(0.4rem, env(safe-area-inset-bottom));
    gap: 0.35rem;
    justify-content: flex-end;
    max-height: 32%;
    flex-shrink: 0;
  }
  .message-text {
    flex: 0 1 auto;
    min-height: 0;
    max-height: 3.2em;
    font-size: 0.78rem;
    padding-right: 0.3rem;
  }
  .action-buttons { flex-direction: row; flex-wrap: wrap; gap: 0.35rem; }
  .action-buttons .btn { width: auto; flex: 1 1 auto; }
  .action-buttons .hint-sep { flex-basis: 100%; margin: 0; }
}

/* Compact sizing whenever either dimension is tight — phones in portrait or
   landscape, and short desktop windows. The middle row is allowed to shrink
   so the player's hand and the action buttons are never clipped away. */
@media (max-width: 640px), (max-height: 600px) {
  .score-bar { padding: 0.3rem 0.8rem; }
  .score-team { min-width: 64px; }
  .team-score { font-size: 1.3rem; }
  .trump-display { font-size: 0.85rem; }

  .table { padding: 0.25rem; }
  .player-area { gap: 2px; }
  .player-label { font-size: 0.62rem; padding: 1px 8px; }
  .play-indicator { font-size: 0.68rem; height: 1em; }

  .card { width: 52px; height: 72px; }
  .hand-top .card,
  .hand-left .card,
  .hand-right .card { width: 40px; height: 56px; }

  .hand-bottom .card + .card,
  .hand-top .card + .card { margin-left: -18px; }
  .hand-left .card + .card,
  .hand-right .card + .card { margin-top: -30px; }

  .hand-bottom { min-height: 72px; }
  .hand-top    { min-height: 56px; }
  .hand-left, .hand-right { min-width: 44px; }

  .player-left, .player-right { width: 50px; }
  .middle-row { max-height: none; min-height: 0; padding: 0 0.2rem; gap: 0.25rem; }
  .play-area { min-height: 0; }
  .play-area > .played-card-slot { margin: -6px 0; }
  .played-card-slot { width: 52px; height: 72px; min-height: 0; }
  .played-card-slot .card { width: 48px; height: 66px; }
  .trick-count { font-size: 0.75rem; min-width: 50px; padding: 2px 5px; }
}

/* ---------- Utility ---------- */
.hidden { display: none !important; }
