/* Mahjong Solitaire Stylesheet
   Tile-based layout with 3D stacked appearance, dark theme.
   Controls the board, tiles, animations, modals, and responsiveness. */

/* === CSS Variables & Tile Sizing ======================== */
:root {
  --tile-w: 48px;
  --tile-h: 64px;
  --tile-depth: 6px;
  --tile-gap: 2px;
  --tile-radius: 5px;
  --tile-bg: #f5f0e8;
  --tile-bg-side: #d4cbb8;
  --tile-border: #b8a88a;
  --tile-text: #2c2c2c;
  --tile-selected-glow: 0 0 0 3px #ffd700, 0 6px 20px rgba(255, 215, 0, 0.4);
  --tile-selected-border: #ffd700;
  --tile-hint-glow: 0 0 0 3px #ff6b6b, 0 6px 20px rgba(255, 107, 107, 0.4);
  --tile-hint-border: #ff6b6b;
  --tile-notfree-opacity: 0.65;
  --tile-hover-brightness: 1.08;
  --match-score: #4caf50;
  --board-pad: 24px;
  --controls-gap: 12px;
}

@media screen and (min-width: 901px) and (max-width: 1200px) {
  :root {
    --tile-w: 44px;
    --tile-h: 58px;
    --tile-depth: 5px;
  }
}

@media screen and (min-width: 601px) and (max-width: 900px) {
  :root {
    --tile-w: 38px;
    --tile-h: 52px;
    --tile-depth: 4px;
  }
}

@media screen and (max-width: 600px) {
  :root {
    --tile-w: 32px;
    --tile-h: 44px;
    --tile-depth: 3px;
  }
}

/* === Controls ============================================= */
.mahjong-controls {
  width: 100%;
  max-width: 750px;
  margin: 0 auto 16px auto;
  padding: 0 4px;
}

.mahjong-controls .controls-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: var(--controls-gap);
}

.mahjong-controls .control-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mahjong-controls .control-label {
  font-size: 0.75rem;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.mahjong-controls .timer-display,
.mahjong-controls .score-display {
  font-size: 1.1rem;
  font-weight: 700;
  color: #ffffff;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.05em;
  background-color: #1a1a1a;
  border: 1px solid #2e2e2e;
  border-radius: 6px;
  padding: 4px 10px;
  min-width: 60px;
  text-align: center;
}

.mahjong-controls .shuffles-display {
  font-size: 1.1rem;
  font-weight: 700;
  color: #ff9800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.05em;
  background-color: #1a1a1a;
  border: 1px solid #2e2e2e;
  border-radius: 6px;
  padding: 4px 10px;
  min-width: 30px;
  text-align: center;
}

.mahjong-controls .shuffles-display.shuffles-zero {
  color: #f44336;
}

.mahjong-controls .btn {
  padding: 8px 16px;
  font-size: 0.85rem;
}

/* === Board Wrapper ======================================== */
.mahjong-board-wrapper {
  width: 100%;
  max-width: 750px;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: visible;
}

.mahjong-board {
  position: relative;
  margin: var(--board-pad);
  /* Size is set dynamically in JS after tiles are placed */
  /* Ensures canvas is behind tiles */
  background-color: transparent;
  touch-action: manipulation;
  /* A faint central emblem to evoke a mahjong table */
  box-shadow:
    0 0 80px rgba(0, 0, 0, 0.6),
    inset 0 0 60px rgba(0, 0, 0, 0.3);
  border-radius: 12px;
  overflow: visible;
}

/* === Tile ================================================= */
.tile {
  position: absolute;
  width: var(--tile-w);
  height: var(--tile-h);
  border-radius: var(--tile-radius);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  /* Tile body: vertical face + depth for 3D */
  background-color: var(--tile-bg);
  /* Side / top darkening for 3D brick look */
  border: 1.5px solid var(--tile-border);
  box-shadow:
    /* top edge depth */
    1px 1px 0 0 var(--tile-bg-side),
    2px 2px 0 0 var(--tile-bg-side),
    /* right edge depth */
    calc(var(--tile-gap) * -1) calc(var(--tile-gap) * -1) 0 0 var(--tile-bg-side),
    /* body */
    1px 2px 6px rgba(0, 0, 0, 0.35);
  /* Center the character */
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  z-index: 1;
  transition: filter 0.15s ease, box-shadow 0.15s ease, opacity 0.2s ease, transform 0.1s ease;
}

.tile .tile-symbol {
  font-size: calc(var(--tile-h) * 0.52);
  line-height: 1;
  text-align: center;
  pointer-events: none;
  display: block;
}

.tile .tile-symbol svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* Remove emoji font-family — tiles now render as SVG */
.tile .tile-symbol {
  font-family: inherit;
}

/* Tile type color accents on bottom edge */
.tile[data-type="character"] { border-bottom-color: #e53935; }
.tile[data-type="bamboo"]    { border-bottom-color: #43a047; }
.tile[data-type="circle"]    { border-bottom-color: #1e88e5; }
.tile[data-type="wind"]      { border-bottom-color: #7b1fa2; }
.tile[data-type="dragon"]    { border-bottom-color: #ff9800; }
.tile[data-type="season"]    { border-bottom-color: #ec407a; }

/* Free tile hover */
.tile:not(.not-free):not(.matched):not(.selected):not(.hint):hover {
  filter: brightness(var(--tile-hover-brightness));
  transform: translateY(-1px);
}

/* Selected tile */
.tile.selected {
  border-color: var(--tile-selected-border);
  box-shadow: var(--tile-selected-glow), 1px 2px 6px rgba(0, 0, 0, 0.35);
  filter: brightness(1.12);
}

/* Hint-highlighted tile */
.tile.hint {
  border-color: var(--tile-hint-border);
  box-shadow: var(--tile-hint-glow), 1px 2px 6px rgba(0, 0, 0, 0.35);
  animation: mahjongHintPulse 1.5s ease-in-out 2;
}

/* Not-free tile (blocked) */
.tile.not-free {
  opacity: var(--tile-notfree-opacity);
  cursor: default;
}

/* Prevent interaction on matched/removing tiles */
.tile.matched {
  pointer-events: none;
}

/* === Animations ============================================ */

/* Pulse for hint */
@keyframes mahjongHintPulse {
  0%, 100% {
    filter: brightness(1.0);
  }
  50% {
    filter: brightness(1.25);
  }
}

/* Match removal animation */
.tile.removing {
  animation: mahjongMatchRemove 0.35s ease-out forwards;
}

@keyframes mahjongMatchRemove {
  0% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.8;
    transform: scale(1.08);
  }
  100% {
    opacity: 0;
    transform: scale(0.5);
  }
}

/* Score popup */
.score-popup {
  position: absolute;
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--match-score);
  pointer-events: none;
  z-index: 9999;
  animation: scoreFloatUp 0.8s ease-out forwards;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
}

@keyframes scoreFloatUp {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-40px) scale(1.3);
  }
}

/* === Status Bar ============================================ */
.status-bar {
  width: 100%;
  max-width: 750px;
  margin: 14px auto 0 auto;
  text-align: center;
  font-size: 0.88rem;
  color: #888;
  min-height: 1.5em;
}

.status-bar.status-info    { color: #888; }
.status-bar.status-error   { color: #f44336; }
.status-bar.status-success { color: #4caf50; }

/* === Victory Modal ========================================== */
.victory-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.victory-modal-overlay[hidden] {
  display: none;
}

.victory-modal {
  position: relative;
  background-color: #1a1a1a;
  border: 1px solid #2e2e2e;
  border-radius: 16px;
  padding: 40px 48px;
  text-align: center;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), 0 0 40px rgba(255, 215, 0, 0.08);
  animation: modalSlideIn 0.35s ease-out;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-24px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.victory-modal-header .victory-icon {
  font-size: 3.2rem;
  margin-bottom: 8px;
}

.victory-modal .victory-title {
  font-size: 1.8rem;
  color: #ffd700;
  margin: 0 0 4px 0;
  font-weight: 700;
}

.victory-modal .victory-subtitle {
  font-size: 1rem;
  color: #aaa;
  margin: 0 0 20px 0;
}

.victory-stats {
  margin: 0 0 24px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.victory-stats .stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #2a2a2a;
}

.victory-stats .stat-label {
  font-size: 0.9rem;
  color: #999;
}

.victory-stats .stat-value {
  font-size: 1rem;
  font-weight: 600;
  color: #ffffff;
}

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

.victory-modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: transparent;
  border: none;
  color: #999;
  font-size: 1.4rem;
  cursor: pointer;
  transition: color 0.2s ease, transform 0.15s ease;
  border-radius: 50%;
  line-height: 1;
}

.victory-modal-close:hover {
  color: #ffffff;
  transform: scale(1.1);
}

/* === No Moves Modal ======================================== */
.nomoves-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.nomoves-modal-overlay[hidden] {
  display: none;
}

.nomoves-modal {
  position: relative;
  background-color: #1a1a1a;
  border: 1px solid #2e2e2e;
  border-radius: 16px;
  padding: 40px 48px;
  text-align: center;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  animation: modalSlideIn 0.35s ease-out;
}

.nomoves-modal-header .nomoves-icon {
  font-size: 3rem;
  margin-bottom: 8px;
}

.nomoves-modal .nomoves-title {
  font-size: 1.5rem;
  color: #ff9800;
  margin: 0 0 4px 0;
  font-weight: 700;
}

.nomoves-modal .nomoves-subtitle {
  font-size: 0.95rem;
  color: #aaa;
  margin: 0 0 24px 0;
}

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

.nomoves-modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: transparent;
  border: none;
  color: #999;
  font-size: 1.4rem;
  cursor: pointer;
  transition: color 0.2s ease, transform 0.15s ease;
  border-radius: 50%;
  line-height: 1;
}

.nomoves-modal-close:hover {
  color: #ffffff;
  transform: scale(1.1);
}

/* === Responsive ============================================ */

@media screen and (max-width: 768px) {
  .mahjong-controls .control-group {
    gap: 4px;
  }

  .mahjong-controls .btn {
    padding: 7px 12px;
    font-size: 0.8rem;
  }

  .mahjong-controls .control-label {
    font-size: 0.68rem;
  }
}

@media screen and (max-width: 480px) {
  .mahjong-controls {
    padding: 0;
  }

  .mahjong-controls .controls-row {
    gap: 8px;
  }

  .mahjong-controls .timer-display,
  .mahjong-controls .score-display,
  .mahjong-controls .shuffles-display {
    font-size: 0.95rem;
    padding: 3px 8px;
  }

  .mahjong-controls .btn {
    padding: 6px 10px;
    font-size: 0.75rem;
  }
}
