﻿/* ==========================================================================
   PAGE BASIS
   ========================================================================= */
html,
body {
  margin: 0;
  padding: 0;
  font-family: Arial, sans-serif;
  background: #0a4d2c;
  background-image: radial-gradient(#11633b 20%, #0a4d2c 80%);
  overflow-x: hidden;
  text-align: center;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding: 8px;
  box-sizing: border-box;
}

/* ==========================================================================
   HEADER COMPONENT (Desktop Flex Bar Layout)
   ========================================================================= */
header {
  background: white;
  border-radius: 10px;
  padding: 12px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
  margin-bottom: 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
}

.header-buttons {
  display: flex;
  gap: 8px;
}

.back-link,
.help-btn {
  display: inline-block;
  height: 34px;
  line-height: 34px;
  width: 85px;
  text-decoration: none;
  border-radius: 8px;
  background: #333;
  color: white;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  border: none;
  transition:
    transform 0.2s,
    background-color 0.2s;
  text-align: center;
}

.help-btn {
  background: #555;
}

.back-link:hover,
.help-btn:hover {
  transform: scale(1.03);
  background-color: #444;
}

.title-area h1 {
  margin: 0;
  font-size: 24px;
  color: #333;
  text-align: center;
}

.logo {
  width: 55px;
  height: auto;
}

/* ==========================================================================
   FREECELL BOARD MATRIX LAYOUT (Top Slots)
   ========================================================================= */
.table-grid {
  display: flex;
  justify-content: space-between;
  max-width: 950px;
  margin: 0 auto 15px auto;
  padding: 0 2px;
  gap: 15px;
}

.zone {
  display: flex;
  gap: 4px;
  flex: 1;
}

.slot {
  flex: 1;
  max-width: 100px;
  aspect-ratio: 100 / 145;
  border: 2px dashed rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  position: relative;
  background: rgba(0, 0, 0, 0.15);
  box-sizing: border-box;
}

.suit-watermark {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: rgba(255, 255, 255, 0.15);
  user-select: none;
}

/* ==========================================================================
   CASCADING PLAYING ROWS
   ========================================================================= */
.cascade-row {
  display: flex;
  justify-content: space-between;
  max-width: 950px;
  margin: 10px auto 0 auto;
  padding: 0 2px;
  gap: 4px;
}

.column {
  flex: 1;
  max-width: 100px;
  height: 520px;
  position: relative;
  border-radius: 8px;
  box-sizing: border-box;
  background: rgba(255, 255, 255, 0.02);
}

.card-container {
  position: absolute;
  width: 100%;
  aspect-ratio: 100 / 145;
}

/* ==========================================================================
   PLAYING CARD ASSETS
   ========================================================================= */
.card-img {
  width: 100%;
  height: 100%;
  object-fit: fill;
  border-radius: 6px;
  background-color: #ffffff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  user-select: none;
  box-sizing: border-box;
  border: 1px solid #c8cbcf;
  display: block;
  touch-action: none;
  -webkit-touch-callout: none;
}

.card-img.selected-card {
  border: 2px solid #ffeb3b !important;
  box-shadow: 0 0 12px #ffeb3b !important;
  transform: translateY(-4px);
}

@keyframes invalid-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-6px);
  }
  40% {
    transform: translateX(6px);
  }
  60% {
    transform: translateX(-4px);
  }
  80% {
    transform: translateX(4px);
  }
}

.card-img.invalid-shake {
  animation: invalid-shake 0.3s;
  border-color: #e53935 !important;
}

.autocomplete-banner {
  display: none;
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 1500;
  background: white;
  color: #222;
  padding: 10px 16px;
  border-radius: 10px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  align-items: center;
  gap: 12px;
}

.autocomplete-banner.visible {
  display: flex;
}

.autocomplete-banner button {
  border: none;
  border-radius: 8px;
  padding: 6px 14px;
  font-weight: bold;
  cursor: pointer;
}

.autocomplete-banner .autocomplete-confirm {
  background: #2e7d32;
  color: white;
}

.autocomplete-banner .autocomplete-dismiss {
  background: #ccc;
  color: #222;
}

.slot.drag-over,
.column.drag-over {
  border-color: #90ee90 !important;
  background-color: rgba(144, 238, 144, 0.2) !important;
}

/* ==========================================================================
   MODAL RULES BOX
   ========================================================================= */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  z-index: 2000;
  justify-content: center;
  align-items: center;
}

.modal-box {
  background: white;
  color: #333;
  padding: 25px;
  border-radius: 12px;
  max-width: 500px;
  width: 90%;
  text-align: left;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  max-height: 80vh;
  overflow-y: auto;
}

/* ==========================================================================
   MOBILE INTERACTION LAYOUT (Clean 2-Row Layout with visible Logo)
   ========================================================================= */
@media (max-width: 700px) {
  body {
    padding: 4px;
  }

  /* Convert header to a strict 2x2 structural matrix grid */
  header {
    display: grid;
    grid-template-columns: 1fr auto; /* Title expands, logo stays locked right */
    padding: 10px;
    margin-bottom: 12px;
    gap: 10px;
    align-items: center;
  }

  /* Row 1, Column 1: Left-aligned title text */
  .title-area {
    grid-column: 1;
    grid-row: 1;
    text-align: left;
    width: auto;
    margin-bottom: 0;
  }

  .title-area h1 {
    font-size: 20px;
  }

  /* Row 1, Column 2: Logo visible on right hand side */
  .logo {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    grid-column: 2;
    grid-row: 1;
    width: 40px;
    height: auto;
  }

  /* Row 2: Spans full width underneath title and logo */
  .header-buttons {
    grid-column: 1 / span 2;
    grid-row: 2;
    display: flex;
    width: 100%;
    gap: 8px;
    justify-content: center;
  }

  .back-link,
  .help-btn {
    flex: 1;
    max-width: 150px;
    height: 34px;
    line-height: 34px;
    font-size: 12px;
  }

  /* Scaling grids compact */
  .table-grid {
    gap: 6px;
    margin-bottom: 10px;
  }

  .column {
    height: 380px;
  }
}
