/* ============================================================
   WORDLE TELEGRAM MINI APP — style.css v7
   Light theme (NYT Wordle reference)
   Key heights use explicit !important px — not CSS vars —
   so they survive Telegram webview quirks.
   ============================================================ */

/* ── Design Tokens ─────────────────────────────────────────── */
:root {
  --bg:     #ffffff;
  --surface:#f6f6f6;
  --border: #e0e0e0;
  --text:   #1a1a1b;
  --muted:  #787c7e;

  --tile-empty-border:  #d3d6da;
  --tile-filled-border: #878a8c;
  --tile-bg: #ffffff;

  --green:  #6aaa64;
  --yellow: #c9b458;
  --absent: #787c7e;

  --key-bg:   #d3d6da;
  --key-text: #1a1a1b;

  /* Constrained by BOTH width and height so tiles never overflow */
  --tile-size: min(
    min(62px, calc((100vw - 40px) / 5.3)),
    calc((100dvh - 315px) / 6)
  );
  --tile-gap: 5px;

  --font: 'Libre Franklin', 'Clear Sans', 'Helvetica Neue', Arial, sans-serif;
  --font-serif: 'Playfair Display', Georgia, 'Times New Roman', serif;

  --r-sm: 4px;
  --r-md: 8px;
  --r-lg: 12px;
}

[data-theme="dark"] {
  --bg:     #121213;
  --surface:#272729;
  --border: #3a3a3c;
  --text:   #f8f8f8;
  --muted:  #818384;

  --tile-empty-border:  #3a3a3c;
  --tile-filled-border: #565758;
  --tile-bg: #121213;

  --green:  #538d4e;
  --yellow: #b59f3b;
  --absent: #3a3a3c;

  --key-bg:   #818384;
  --key-text: #ffffff;
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box; margin: 0; padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  height: 100vh; height: 100dvh;
  width: 100vw;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: stretch;
}

/* ── App Shell ──────────────────────────────────────────────── */
#app {
  width: 100%;
  max-width: 500px;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  overflow: hidden;
}

/* ── Header ─────────────────────────────────────────────────── */
.app-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 50px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.header-left,
.header-right {
  display: flex; align-items: center; gap: 6px; min-width: 80px;
}
.header-right { justify-content: flex-end; }
.header-center { display: flex; flex-direction: column; align-items: center; flex: 1; }

.logo {
  font-family: var(--font-serif);
  font-size: 1.75rem; font-weight: 700;
  letter-spacing: 0.02em; color: var(--text); line-height: 1;
}
.mode-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 0.58rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.1em; margin-top: 2px;
}
.mode-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--green); }
.mode-badge.practice .mode-dot { background: var(--yellow); }

.icon-btn {
  background: none; border: none; color: var(--text);
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--r-sm); cursor: pointer;
  opacity: 0.7; transition: opacity 0.15s;
}
.icon-btn:hover  { opacity: 1; }
.icon-btn:active { opacity: 0.45; }

.pill-btn {
  background: rgba(106,170,100,0.12);
  border: 1px solid rgba(106,170,100,0.4);
  color: var(--green);
  font-family: var(--font); font-size: 0.65rem; font-weight: 700;
  padding: 4px 10px; border-radius: 20px;
  cursor: pointer; transition: background 0.15s; white-space: nowrap;
}
.pill-btn:hover  { background: rgba(106,170,100,0.22); }
.pill-btn:active { background: rgba(106,170,100,0.32); }

/* ── SR only ────────────────────────────────────────────────── */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.puzzle-info {
  font-size: 0.7rem; font-weight: 600; color: var(--muted);
  flex-shrink: 0; padding: 2px 0; text-align: center;
}

/* ── Board ──────────────────────────────────────────────────── */
.board-container {
  flex: 1 1 0; min-height: 0;
  display: flex; justify-content: center; align-items: center;
  padding: 4px 0;
  overflow: hidden; /* clips board if it somehow still overflows */
}
.board {
  display: flex; flex-direction: column; gap: var(--tile-gap);
}
.row {
  display: flex; gap: var(--tile-gap);
}
.tile {
  width: var(--tile-size); height: var(--tile-size);
  border: 2px solid var(--tile-empty-border);
  background: var(--tile-bg); border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--tile-size) * 0.52);
  font-weight: 800; text-transform: uppercase; color: var(--text);
  transition: border-color 0.05s;
}
.tile.active  { border-color: var(--tile-filled-border); animation: tilePop 0.1s ease; }
.tile.filled  { border-color: var(--tile-filled-border); }
.tile.correct { background: var(--green)  !important; border-color: var(--green)  !important; color: #fff !important; }
.tile.present { background: var(--yellow) !important; border-color: var(--yellow) !important; color: #fff !important; }
.tile.absent  { background: var(--absent) !important; border-color: var(--absent) !important; color: #fff !important; }

/* ── Tile Animations ────────────────────────────────────────── */
@keyframes tilePop {
  0%  { transform: scale(1); }   50% { transform: scale(1.12); }   100% { transform: scale(1); }
}
.row.shake { animation: rowShake 0.5s ease-in-out; }
@keyframes rowShake {
  0%,100%              { transform: translateX(0); }
  10%,30%,50%,70%,90% { transform: translateX(-5px); }
  20%,40%,60%,80%      { transform: translateX(5px); }
}
.tile.flip { animation: tileFlip 0.55s ease forwards; }
@keyframes tileFlip {
  0%  { transform: rotateX(0deg); }  45% { transform: rotateX(90deg); }
  55% { transform: rotateX(90deg); } 100%{ transform: rotateX(0deg); }
}
.tile.bounce { animation: tileBounce 0.55s ease; }
@keyframes tileBounce {
  0%,20% { transform: translateY(0); }   40% { transform: translateY(-18px); }
  50%    { transform: translateY(0); }   60% { transform: translateY(-9px); }
  80%,100%{ transform: translateY(0); }
}

/* ── Keyboard — MOBILE default ──────────────────────────────── */
.keyboard-container {
  flex-shrink: 0; width: 100%; max-width: 500px;
  margin: 0 auto;
  padding: 6px 8px max(24px, env(safe-area-inset-bottom, 24px));
}
.keyboard { display: flex; flex-direction: column; gap: 8px; }
.keyboard-row {
  display: flex; justify-content: center; gap: 6px;
  touch-action: manipulation;
}
.spacer.half { flex: 0.5; }

.key {
  font-family: var(--font);
  font-size: clamp(0.78rem, 2.4vw, 1rem);
  font-weight: 700; text-transform: uppercase;
  background: var(--key-bg); color: var(--key-text);
  border: none; border-radius: var(--r-sm);
  height: 56px;          /* MOBILE default */
  flex: 1; min-width: 0;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: filter 0.08s;
}
.key:hover  { filter: brightness(0.88); }
.key:active { filter: brightness(0.75); }

.key.wide-key { flex: 1.5; font-size: clamp(0.65rem, 2vw, 0.82rem); padding: 0 2px; }
.key svg { display: block; }
.key.correct { background: var(--green)  !important; color: #fff !important; }
.key.present { background: var(--yellow) !important; color: #fff !important; }
.key.absent  { background: #c0c0c0 !important; color: #fff !important; }

/* ── Keyboard — DESKTOP / PC ────────────────────────────────── */
/* Three independent mechanisms — any one is enough */

/* 1. CSS media query (pointer device) */
@media (hover: hover) and (pointer: fine) {
  .key      { height: 40px !important; font-size: 0.85rem !important; }
  .key.wide-key { font-size: 0.7rem !important; }
  .keyboard { gap: 6px !important; }
  .keyboard-row { gap: 5px !important; }
  .keyboard-container { padding-bottom: 10px !important; }
}

/* 2. JS-set class on <html> (covers all Telegram desktop builds) */
html.is-desktop .key,
html.platform-tdesktop .key,
html.platform-macos .key,
html.platform-web .key,
html.platform-weba .key,
html.platform-webk .key {
  height: 40px !important;
  font-size: 0.85rem !important;
}
html.is-desktop .key.wide-key,
html.platform-tdesktop .key.wide-key,
html.platform-macos .key.wide-key {
  font-size: 0.7rem !important;
}
html.is-desktop .keyboard,
html.platform-tdesktop .keyboard { gap: 6px !important; }

html.is-desktop .keyboard-row,
html.platform-tdesktop .keyboard-row { gap: 5px !important; }

html.is-desktop .keyboard-container,
html.platform-tdesktop .keyboard-container { padding-bottom: 10px !important; }

/* 3. Very compact viewport fallback */
@media (max-height: 560px) {
  :root { --tile-size: clamp(30px, calc((100vh - 195px) / 6.5), 44px); --tile-gap: 4px; }
  .key        { height: 34px !important; font-size: 0.78rem !important; }
  .keyboard   { gap: 4px !important; }
  .keyboard-row { gap: 4px !important; }
  .keyboard-container { padding-bottom: 6px !important; }
}

/* Keyboard disabled state — game over in daily mode */
.keyboard--disabled {
  pointer-events: none;
  opacity: 0.45;
  transition: opacity 0.3s ease;
}

/* ── Toast ──────────────────────────────────────────────────── */
.toast-container {
  position: absolute; top: 14%; left: 50%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; z-index: 100;
}
.toast {
  background: #1a1a1b; color: #fff;
  font-weight: 700; font-size: 0.88rem; padding: 9px 18px;
  border-radius: var(--r-lg); box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  animation: toastFade 1.7s ease forwards;
}
@keyframes toastFade {
  0%  { opacity: 0; transform: translateY(-6px) scale(0.97); }
  12% { opacity: 1; transform: translateY(0) scale(1); }
  80% { opacity: 1; }
  100%{ opacity: 0; transform: translateY(-8px); }
}

/* ── Modals ─────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45); backdrop-filter: blur(4px);
  display: flex; justify-content: center; align-items: center;
  padding: 16px; z-index: 200; animation: overlayIn 0.18s ease;
}
.modal-overlay.hidden { display: none; }
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--r-lg); width: 100%; max-width: 420px;
  max-height: 90vh; overflow-y: auto; padding: 22px 20px;
  box-shadow: 0 12px 36px rgba(0,0,0,0.15);
  position: relative; animation: cardIn 0.2s cubic-bezier(0.16,1,0.3,1);
}
@keyframes cardIn {
  from { transform: scale(0.96) translateY(8px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  font-size: 1.05rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase;
}
.modal-close {
  background: none; border: none; color: var(--muted);
  font-size: 1.6rem; line-height: 1; cursor: pointer; transition: color 0.15s;
}
.modal-close:hover { color: var(--text); }

/* Close button for game over card (absolutely positioned top-right) */
.gameover-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s;
  padding: 4px;
}
.gameover-close:hover { color: var(--text); }

.modal-body { font-size: 0.9rem; line-height: 1.55; color: var(--text); }
.modal-body p { margin-bottom: 10px; }

.example-row { margin: 12px 0; padding: 10px; background: var(--surface); border-radius: var(--r-md); }
.example-tiles { display: flex; gap: 5px; margin-bottom: 7px; }
.example-tiles .tile {
  width: 34px; height: 34px; font-size: 1rem;
  min-width: 34px; min-height: 34px; max-width: 34px; max-height: 34px;
}
.daily-note {
  margin-top: 14px; padding: 9px 11px;
  border-left: 3px solid var(--green);
  background: rgba(106,170,100,0.08);
  border-radius: 0 var(--r-sm) var(--r-sm) 0; font-size: 0.82rem;
}

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 8px; text-align: center; margin: 14px 0; }
.stat-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: 10px 4px; }
.stat-value { font-size: 1.45rem; font-weight: 800; }
.stat-label { font-size: 0.63rem; color: var(--muted); text-transform: uppercase; font-weight: 600; margin-top: 2px; line-height: 1.3; }
.dist-title { font-size: 0.95rem; font-weight: 700; margin: 16px 0 8px; text-transform: uppercase; letter-spacing: 0.06em; }
.distribution-chart { display: flex; flex-direction: column; gap: 5px; margin-bottom: 18px; }
.dist-row { display: flex; align-items: center; gap: 8px; font-size: 0.82rem; font-weight: 700; }
.dist-bar-wrapper { flex: 1; background: var(--surface); border-radius: var(--r-sm); overflow: hidden; height: 20px; }
.dist-bar {
  background: var(--green); height: 100%;
  display: flex; align-items: center; justify-content: flex-end; padding-right: 6px;
  color: #fff; font-size: 0.74rem; font-weight: 800; min-width: 20px;
  transition: width 0.55s cubic-bezier(0.16,1,0.3,1);
}
.modal-actions { display: flex; gap: 10px; justify-content: center; }

/* Game Over */
.gameover-card { text-align: center; }
.gameover-icon { font-size: 2.6rem; margin-bottom: 4px; }
.gameover-card h2 { font-size: 1.5rem; font-weight: 900; margin-bottom: 4px; }
.gameover-card p { color: var(--muted); font-size: 0.9rem; margin-bottom: 12px; }
.word-reveal { font-size: 1.05rem; font-weight: 800; color: var(--green); margin-bottom: 12px; }
.share-preview {
  background: var(--surface); padding: 10px; border-radius: var(--r-md);
  font-size: 1.05rem; line-height: 1.35; margin-bottom: 16px;
  white-space: pre-wrap; font-family: monospace;
}
.gameover-buttons { display: flex; flex-direction: column; gap: 8px; }
.action-btn {
  font-family: var(--font); border: none; border-radius: var(--r-md);
  padding: 13px 18px; font-size: 0.95rem; font-weight: 800;
  cursor: pointer; transition: filter 0.1s, transform 0.1s;
  display: flex; align-items: center; justify-content: center; gap: 7px;
}
.action-btn:hover  { filter: brightness(1.08); }
.action-btn:active { transform: scale(0.97); }
.share-btn { background: var(--green); color: #fff; box-shadow: 0 4px 14px rgba(106,170,100,0.3); }
.secondary-btn { background: var(--surface); border: 1px solid var(--border); color: var(--text); }
