/* ── Desktop: alarga o app SOMENTE durante a partida ── */
@media (min-width: 640px) {
  #app.playing {
    max-width: min(560px, calc((100dvh - 160px) * 320 / 356));
  }
}

/* ── Layout overrides (same pattern as memory) ── */
body {
  overflow-y: auto !important;
  height: auto !important;
}

#app {
  height: auto !important;
  min-height: 100dvh;
}

.screen {
  flex: none !important;
  min-height: 100dvh;
}

#start-screen,
#game-screen,
#result-screen {
  height: 100dvh !important;
  overflow: hidden !important;
}

.footer-m3 {
  position: sticky;
  bottom: 0;
  background-color: var(--m3-background);
  z-index: 10;
}

/* ── Start screen ── */
.selection-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2.5rem;
}

/* ── Game screen ── */
.game-content {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.game-status {
  font-size: 13px;
  color: var(--m3-on-surface-variant, #888);
  text-align: center;
  min-height: 1.2em;
  margin: 0;
  letter-spacing: .03em;
  flex-shrink: 0;
}

/* Tabuleiro: ocupa o máximo da largura disponível mantendo o aspect ratio.
   min() garante que a altura não ultrapasse o espaço restante na tela. */
#bwrap {
  position: relative;
  width: min(100%, calc((100dvh - 180px) * 320 / 356));
  aspect-ratio: 320 / 356;
  flex-shrink: 0;
}

#bwrap canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.bottom-controls {
  width: 100%;
  padding-inline: 1rem;
  padding-block: clamp(0.5rem, 2vh, 1rem);
  padding-bottom: calc(clamp(0.5rem, 2vh, 1rem) + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.btn-tertiary {
  background: transparent;
  border: none;
  font-family: var(--font-main);
  font-size: 1rem;
  font-weight: 500;
  color: var(--m3-on-surface-variant, #c5c6d0);
  cursor: pointer;
  padding: 0.5rem;
  transition: transform 0.2s, opacity 0.2s;
}

.btn-tertiary:active { transform: scale(0.95); opacity: 0.8; }

/* ── Guide overlay ── */
.guide-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}

.guide-overlay.open {
  display: flex;
  animation: guideIn .18s ease-out;
}

@keyframes guideIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.guide-modal {
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 400px;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: guideScaleIn .2s cubic-bezier(.32, 1, .6, 1);
}

@keyframes guideScaleIn {
  from { transform: scale(.95); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

.guide-modal-header {
  padding: 1rem 1rem .75rem;
  border-bottom: 1px solid #f0f0f0;
  flex-shrink: 0;
}

.guide-modal-title {
  font-size: 14px;
  font-weight: 600;
  color: #222;
  text-align: center;
  margin: 0 0 4px;
}

.guide-modal-subtitle {
  font-size: 11px;
  color: #999;
  text-align: center;
  line-height: 1.4;
  margin: 0;
}

.guide-modal-body {
  overflow-y: auto;
  flex: 1;
  padding: .5rem .9rem;
}

.guide-modal-footer {
  padding: .75rem 1rem;
  border-top: 1px solid #f0f0f0;
  flex-shrink: 0;
}

.guide-close-btn {
  width: 100%;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  color: #555;
}

/* ── Piece cards ── */
.piece-card {
  padding: .75rem 0;
  border-bottom: 1px solid #f0f0f0;
}

.piece-card:last-child {
  border-bottom: none;
}

.piece-title {
  font-size: 13px;
  font-weight: 600;
  color: #222;
  text-align: center;
  margin-bottom: .6rem;
}

.piece-sides {
  display: flex;
  gap: .5rem;
  margin-bottom: .6rem;
}

.piece-side {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: .5rem .25rem;
  background: #fafafa;
  border-radius: 8px;
}

.side-label {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.side-label-han { color: #b83232; }
.side-label-chu { color: #2a2a2a; }

.piece-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 14px;
  color: #fff;
  margin: .1rem 0;
}

.piece-icon-red { background: #b83232; }
.piece-icon-blk { background: #2a2a2a; }

.piece-char    { font-size: 12px; font-weight: 600; color: #333; }
.piece-pinyin  { font-size: 10px; color: #aaa; }
.piece-meaning { font-size: 10.5px; color: #666; font-style: italic; }

.piece-desc,
.piece-tip {
  font-size: 11.5px;
  color: #555;
  line-height: 1.6;
  padding: 0 .25rem;
  margin: 0 0 .3rem;
}

.piece-desc b { color: #333; font-weight: 600; }
.piece-tip  b { color: #b8860b; font-weight: 600; }

/* ── Result screen ── */
.result-content {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding-block: 2rem;
}

.end-content-header {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 0 1rem;
}

.stats-card {
  background-color: #d9dff6;
  border-radius: 1.75rem;
  padding: 1.0625rem 2.125rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
}

.stats-card-title {
  font-size: 1.5rem;
  font-weight: 500;
  color: #151b2c;
  text-align: center;
  line-height: 2rem;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  color: #151b2c;
}

.stat-row span {
  font-size: 1rem;
  font-weight: 500;
}

.stat-row-value {
  font-size: 1.5rem;
}

.stats-divider {
  width: 100%;
  height: 1px;
  background-color: rgba(21, 27, 44, 0.2);
  margin: 0.25rem 0;
}

.result-footer {
  padding: clamp(0.5rem, 2vh, 1rem) 1rem;
  padding-bottom: calc(clamp(0.5rem, 2vh, 1rem) + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  flex-shrink: 0;
}
