/* Tetra Master Online - main stylesheet
   ------------------------------------------------------------------
   Sections
   1) Reset & base
   2) Layout containers
   3) Board
   4) Side columns
   5) Hands
   6) Panels (board tiles)
   7) Buttons
   8) Card visual layers (shared)
   9) Dialog
   10) Utilities
-------------------------------------------------------------------*/

/* 1) Reset & base --------------------------------------------------------- */
:root {
  --bg: #0f0f12;
  --text: #e8e8ea;
  --muted: #a5a5aa;
  --accent: #ffcc66;
  --panel-outline-player: rgba(255, 80, 80, .6);
  --panel-outline-cpu: rgba(80, 140, 255, .6);
  --button-bg: #2a2a31;
  --button-text: #fff;
  --button-bg-hover: #3a3a45;
  --dialog-bg: #1c1c22;
  --dialog-border-top: #5a6068;
  --dialog-border-right: #2c2f35;
  --dialog-border-bottom: #2c2f35;
  --dialog-border-left: #5a6068;
  --shadow: 0 1px 2px rgba(0,0,0,.35);
}

/* Classic FF9 theme */
:root[data-theme="classic"]{
  --bg: #1a1510;
  --text: #f0e6d6;
  --muted: #d0c4b2;
  --accent: #d4a44a;
  --panel-outline-player: rgba(210, 120, 80, .7);
  --panel-outline-cpu: rgba(100, 130, 210, .7);
  --button-bg: #3b2f27;
  --button-text: #f0e6d6;
  --button-bg-hover: #4a3a30;
  --dialog-bg: #2b231e;
  --dialog-border-top: #7b6a5a;
  --dialog-border-right: #40352c;
  --dialog-border-bottom: #40352c;
  --dialog-border-left: #7b6a5a;
}

/* Retro/pixel theme */
:root[data-theme="retro"]{
  --bg: #0b0b0b;
  --text: #e0ffe0;
  --muted: #a0d0a0;
  --accent: #8aff8a;
  --panel-outline-player: rgba(140, 255, 140, .8);
  --panel-outline-cpu: rgba(140, 200, 255, .8);
  --button-bg: #161616;
  --button-text: #e0ffe0;
  --button-bg-hover: #1e1e1e;
  --dialog-bg: #101010;
  --dialog-border-top: #3a3a3a;
  --dialog-border-right: #0e0e0e;
  --dialog-border-bottom: #0e0e0e;
  --dialog-border-left: #3a3a3a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
body { padding: 16px; }

/* 2) Layout containers ---------------------------------------------------- */
.site-wrapper { width: 740px; margin: 0 auto; }
.board-row { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 24px; color: var(--text); }
.board-row > #card_mat { flex: 0 0 408px; }
.board-row > .side-info { flex: 0 0 120px; }

/* 3) Board --------------------------------------------------------------- */
#card_mat {
  background: url(../assets/board/tm_card_mat.png) no-repeat;
  display: grid;
  grid-template-columns: repeat(4, 25%);
  grid-template-rows: repeat(4, 25%);
  width: 408px;
  height: 496px;
  margin-bottom: 24px;
  overflow: visible; /* avoid cropping inner absolute layers */
}

/* 4) Side columns -------------------------------------------------------- */
.side-info { width: 120px; text-align: center; color: var(--muted); }
.side-info .label { font-size: 12px; opacity: 0.8; margin-bottom: 6px; }
.side-info .count { background: linear-gradient(180deg, rgba(51,51,51,.85), rgba(30,30,30,.85)); border: 2px solid #444; border-radius: 10px; padding: 10px 0; font-size: 22px; font-weight: 800; box-shadow: 0 2px 6px rgba(0,0,0,.25) inset; }

/* 5) Hands --------------------------------------------------------------- */
.hand { display: flex; flex-direction: column; align-items: center; gap: 10px; }
/* Use same geometry as board tiles */
.hand-card { position: relative; width: 102px; height: 124px; border-radius: 10px; box-shadow: 0 1px 2px rgba(0,0,0,.35); overflow: hidden; }
.hand-card.used { opacity: .35; filter: grayscale(0.2); }
/* Only the back image for CPU uses its own tag */
.hand-card .card-back { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
/* Selected card in hand */
.hand-card.is-selected { outline: 3px solid #ffcc66; outline-offset: -3px; box-shadow: 0 0 0 3px rgba(255, 220, 120, .5) inset; }
/* Selected card visual (light green filter) */
.hand-card.is-selected::after { content:''; position:absolute; inset:0; background: rgba(80, 200, 120, 0.22); pointer-events:none; }
.hand-card.is-selected::after { background: rgba(80, 200, 120, 0.35); }




/* 6) Panels (board tiles) ----------------------------------------------- */
.panel { background: none; cursor: pointer; position: relative; overflow: hidden; }
span { width: 100%; height: 100%; position: absolute; transition: all .2s; }
.panel:hover span { background: skyblue; opacity: .55; }
.panel.selected { background: none; box-shadow: 0 0 0 2px var(--panel-outline-player) inset; }
.panel.cpu_selected { background: none; box-shadow: 0 0 0 2px var(--panel-outline-cpu) inset; }
.marked { background-color: #dddddd; }
.selected { background-color: #aaaaaa; }

/* 7) Buttons ------------------------------------------------------------- */
#submit { border: none; border-radius: 8px; font-weight: 700; display: block; width: 50%; padding: 12px 0; margin: 0 auto; background: var(--button-bg); color: var(--button-text); box-shadow: var(--shadow); }
#submit:hover { background: var(--button-bg-hover); opacity: 1; }
#submit:disabled { opacity: .5; }
#new_game { border: none; border-radius: 8px; font-weight: 700; display: inline-block; padding: 10px 14px; background: var(--button-bg); color: var(--button-text); box-shadow: var(--shadow); }
#new_game:hover { background: var(--button-bg-hover); opacity: 1; }
#submit:disabled:hover { cursor: default; opacity: 1; }
#submit:hover { cursor: pointer; opacity: .5; }
/* CPU turn subtle overlay */
body.cpu-turn #card_mat .panel { cursor: not-allowed; }
body.cpu-turn #card_mat .panel:hover span { background: #ccc; opacity: .25; }
body.cpu-turn #dialog_box p { opacity: .85; }


/* 8) Card visual layers (shared by board and hands) --------------------- */
.card-bg { position: absolute; inset: 0; background-position: center; background-size: cover; background-repeat: no-repeat; z-index: 0; pointer-events: none; }
.card-image { position: absolute; inset: 0; background-size: cover; background-position: center; z-index: 1; }
.card-frame { position: absolute; inset: 0; background-position: center; background-size: cover; background-repeat: no-repeat; z-index: 2; pointer-events: none; }
.arrow-layer { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.arrow-img { position: absolute; width: 20px; height: 20px; object-fit: contain; display: block; }
/* Edge sizes */
.arrow-img.N, .arrow-img.S, .arrow-img.E, .arrow-img.W { width: 24px; height: 24px; }
/* Edge positions */
.arrow-img.N  { top: 0; left: 50%; transform: translateX(-50%) translateY(-2px); }
.arrow-img.S  { bottom: 0; left: 50%; transform: translateX(-50%) translateY( 2px); }
.arrow-img.E  { right: 0; top: 50%; transform: translateY(-50%) translateX( 2px); }
.arrow-img.W  { left: 0; top: 50%; transform: translateY(-50%) translateX(-2px); }
/* Corners */
.arrow-img.NE, .arrow-img.NW, .arrow-img.SE, .arrow-img.SW { width: 20px; height: 20px; }
.arrow-img.NE { top: 4px; right: 4px; }
.arrow-img.NW { top: 4px; left: 4px; }
.arrow-img.SE { bottom: 4px; right: 4px; }
.arrow-img.SW { bottom: 4px; left: 4px; }
.stats-bar { position: absolute; left: 4px; right: 4px; bottom: 20px; height: 18px; background: rgba(0,0,0,.65); color: #fff; font-size: 12px; line-height: 18px; text-align: center; border-radius: 4px; font-weight: 800; letter-spacing: 1px; z-index: 4; }

/* 9) Dialog -------------------------------------------------------------- */
#dialog_box { background: var(--dialog-bg); border: 4px solid; border-top-color: var(--dialog-border-top); border-right-color: var(--dialog-border-right); border-bottom-color: var(--dialog-border-bottom); border-left-color: var(--dialog-border-left); width: 100%; min-height: 120px; padding: 16px 20px; clear: both; border-radius: 10px; box-shadow: var(--shadow); }
#dialog_box p { color: var(--text); font-size: 1.1rem; text-align: center; }

/* 10) Utilities ---------------------------------------------------------- */
/* Back to menu button - styled like game buttons */
.back-to-menu {
  position: fixed;
  top: 16px;
  left: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  background: var(--button-bg);
  color: var(--button-text);
  text-decoration: none;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,0.15);
  box-shadow: var(--shadow), 0 2px 8px rgba(0,0,0,0.3);
  transition: all 0.15s ease;
  z-index: 100;
  cursor: pointer;
}

.back-to-menu:hover {
  background: var(--button-bg-hover);
  border-color: var(--accent);
  transform: scale(1.02);
}

.back-to-menu:active {
  transform: scale(0.98);
}

.back-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.back-text {
  line-height: 1;
}

/* Grid block image inside a panel */
.grid-block { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 5; }

/* Capture animation (accentuated) */
.panel.capture-anim { animation: captureFlash 0.55s cubic-bezier(.2,.8,.2,1); will-change: transform, box-shadow; }
@keyframes captureFlash {
  0%   { box-shadow: 0 0 0 0 rgba(255, 240, 150, 0);    transform: scale(1); }
  20%  { box-shadow: 0 0 22px 12px rgba(255, 240, 150, .75); transform: scale(1.06); }
  45%  { box-shadow: 0 0 16px 8px  rgba(255, 240, 150, .55); transform: scale(1.03); }
  70%  { box-shadow: 0 0 10px 4px  rgba(255, 240, 150, .35); transform: scale(1.015); }
  100% { box-shadow: 0 0 0 0 rgba(255, 240, 150, 0);    transform: scale(1); }
}




/* ==========================================================================
   MOBILE LAYOUT - PAGE DE JEU UNIQUEMENT
   ========================================================================== */
@media (max-width: 920px){

  /* Site wrapper - uniquement sur la page de jeu */
  .site-wrapper {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
  }

  /* ===== BOUTON MENU - même style que menu principal ===== */
  .back-to-menu {
    position: fixed !important;
    top: 12px !important;
    left: 12px !important;
    right: 12px !important;
    width: auto !important;
    height: auto !important;
    padding: 18px 24px !important;
    margin: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 12px !important;
    font-size: 1.1rem !important;
    font-weight: 600 !important;
    letter-spacing: 0.5px !important;
    border-radius: 14px !important;
    background: transparent !important;
    color: var(--text) !important;
    text-decoration: none !important;
    border: 2px solid rgba(255, 255, 255, 0.15) !important;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3) !important;
    z-index: 9999 !important;
    transition: all 0.2s ease !important;
  }
  .back-to-menu:hover {
    background: rgba(255, 255, 255, 0.05) !important;
    border-color: rgba(255, 204, 102, 0.4) !important;
  }
  .back-icon { font-size: 1.3rem !important; }
  .back-text { display: inline !important; }

  /* ===== ZONE DE JEU - sous le bouton ===== */
  .board-row {
    width: 100% !important;
    height: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: space-evenly !important;
    padding: 80px 8px 8px 8px !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }

  /* CPU Hand - 15% */
  .board-row > .side-info:first-child {
    order: 1 !important;
    width: 100% !important;
    height: 15% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  /* Board - 55% */
  .board-row > #card_mat {
    order: 2 !important;
    height: 55% !important;
    width: auto !important;
    aspect-ratio: 408 / 496 !important;
    background-size: contain !important;
    background-position: center !important;
    background-repeat: no-repeat !important;
  }

  /* Player Hand - 15% */
  .board-row > .side-info:last-child {
    order: 3 !important;
    width: 100% !important;
    height: 15% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  /* Hands */
  .hand {
    display: flex !important;
    flex-direction: row !important;
    justify-content: center !important;
    align-items: center !important;
    gap: 2vw !important;
    padding: 0 !important;
    width: 100% !important;
    height: 100% !important;
  }

  /* Cartes - 18% de la largeur écran */
  .hand-card {
    width: 17vw !important;
    max-width: 80px !important;
    height: auto !important;
    aspect-ratio: 51 / 62 !important;
  }

  /* Labels cachés */
  .side-info .label { display: none !important; }

  /* ===== CACHER DIALOG ET CONTROLS ===== */
  #dialog_box { display: none !important; }
  #controls { display: none !important; }
}



/* Mobile hand sizing uses dynamic calc to fit 5 cards; fixed-size overrides removed. */
