/* 
  File: styles.css
  Purpose: Global stylesheet for Word Equation web app
  Optimized for performance and mobile responsiveness
*/

/* Default: Light Theme */
:root {
  --bg: #f9f9f9;
  --card: #ffffff;
  --text: #222222;
  --muted: #666666;
  --accent: #22c55e;
  --warn: #ef4444;
  --border: #cccccc;
  --cell-size: 48px;
  --cell-gap: 8px;
  --key-height: 48px;
  --key-min-width: 40px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header, footer {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px 16px;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

h1, h2, h3 { margin: 0 0 12px; }

.btn {
  display: inline-block;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #e5e5e5;
  color: #222;
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
  transition: background 150ms ease, transform 100ms ease;
  touch-action: manipulation;
  user-select: none;
}

.btn:hover { background: #d4d4d4; }
.btn:active { 
  transform: scale(0.97);
}
.btn-accent { 
  background: var(--accent); 
  color: #072; 
  border-color: #16a34a; 
}
.btn-warn { 
  background: #ffe5e5; 
  border-color: #ff9999; 
  color: #7f1d1d; 
}

.grid {
  display: grid;
  gap: var(--cell-gap);
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 20px;
  background: #ffffff;
}

.cell.empty {
  background: transparent;
  border: none;
}

.shake {
  animation: shake 300ms ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
  75% { transform: translateX(-2px); }
}

.warning {
  color: var(--warn);
  font-size: 14px;
  min-height: 18px;
}

.guess-list {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-height: 40vh;
  overflow-y: auto;
  border-top: 1px dashed var(--border);
  margin-top: 12px;
  padding-top: 12px;
}

.input-row {
  display: grid;
  grid-template-columns: repeat(5, var(--cell-size));
  gap: var(--cell-gap);
  align-items: center;
  justify-content: center;
}

.guess-row {
  display: grid;
  grid-template-columns: repeat(5, var(--cell-size));
  gap: var(--cell-gap);
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

.attempt-badge.success {
  background-color: var(--accent);
  color: #fff;
  font-weight: bold;
  padding: 6px 10px;
  border-radius: 8px;
  text-align: center;
  min-width: var(--cell-size);
  height: var(--cell-size);
  display: grid;
  place-items: center;
  font-size: 20px;
  border: none;
}

@keyframes badge-pop {
  0% { transform: scale(1); opacity: 0.5; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(1); }
}

.attempt-badge.success.pop {
  animation: badge-pop 300ms ease-out;
}

.keyboard {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  margin-top: 24px;
  padding: 0 4px;
}

.k-row {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: nowrap;
}

.key {
  min-width: var(--key-min-width);
  height: var(--key-height);
  font-size: 16px;
  padding: 0 8px;
  border-radius: 6px;
  border: 1px solid #ccc;
  background-color: #f2f2f2;
  cursor: pointer;
  transition: background 150ms ease;
  touch-action: manipulation;
  user-select: none;
  font-weight: 600;
}

.key:hover {
  background-color: #e0e0e0;
}

.key:active {
  background-color: #d0d0d0;
  transform: scale(0.95);
}

.key:disabled {
  opacity: 0.5;
  cursor: default;
}

.modal-backdrop {
  position: fixed; 
  inset: 0; 
  background: rgba(0,0,0,0.5);
  display: none; 
  align-items: center; 
  justify-content: center; 
  z-index: 1000;
  padding: 16px;
}

.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 560px; 
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
}

.modal h3 {
  margin-top: 0;
  font-size: 20px;
  color: var(--text);
}

.stats-section {
  display: block;
  padding: 10px 0 6px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
}

.stat-row:last-child { border-bottom: none; }
.stat-label { color: var(--muted); font-weight: 600; }
.stat-value { font-weight: 800; font-size: 1.05rem; }
.stat-small { font-size: 0.9rem; color: var(--muted); }

.win-dist {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.dist-badge {
  background: linear-gradient(180deg, rgba(34,197,94,0.12), rgba(34,197,94,0.06));
  color: var(--accent);
  border: 1px solid rgba(34,197,94,0.18);
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.9rem;
}

.modal hr.sep {
  border: none; 
  height: 1px; 
  background: linear-gradient(to right, transparent, var(--border), transparent);
  margin: 12px 0;
}

.ad-slot {
  background: #ffffff;
  border: 1px dashed var(--border);
  padding: 8px;
  border-radius: 12px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

a { color: #1d4ed8; }
a:hover { color: #2563eb; }

input, textarea, select {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text);
  font-size: 16px; /* Prevents zoom on iOS */
}

label { display: block; margin: 8px 0 4px; }
.form-row { margin-bottom: 12px; }

.game-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 24px;
}

.title {
  text-align: center;
  font-size: 32px;
  margin-bottom: 16px;
}

.letter-row {
  display: grid;
  grid-template-columns: repeat(5, var(--cell-size));
  gap: var(--cell-gap);
  align-items: center;
  justify-content: center;
}

.guess-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
}

.nav-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 12px;
}

@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

.cell.filled {
  animation: pop 150ms ease-out;
}

/* Dark Mode */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --card: #111827;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --accent: #22c55e;
    --warn: #ef4444;
    --border: #1f2937;
  }

  .btn {
    background: #1f2937;
    color: var(--text);
  }

  .btn:hover {
    background: #374151;
  }

  .btn-accent {
    background: var(--accent);
    color: #072;
    border-color: #16a34a;
  }

  .btn-warn {
    background: #7f1d1d;
    border-color: #991b1b;
    color: #fecaca;
  }

  .cell,
  .keyboard,
  .ad-slot,
  input,
  textarea,
  select {
    background: #0b1220;
    color: var(--text);
    border-color: var(--border);
  }

  .key {
    background-color: #1f2937;
    border-color: var(--border);
    color: var(--text);
  }

  .key:hover {
    background-color: #374151;
  }

  .key:active {
    background-color: #4b5563;
  }

  .cell.empty {
    background: transparent;
    border: none;
  }

  .attempt-badge.success {
    background-color: var(--accent);
    color: #fff;
  }

  a {
    color: #93c5fd;
  }

  a:hover {
    color: #bfdbfe;
  }
}

/* Mobile Optimizations */
@media (max-width: 640px) {
  .nav-buttons .btn {
    font-size: 13px;
    padding: 8px 10px;
  }

  .title {
    font-size: 26px;
    margin-bottom: 12px;
  }

  .container {
    padding: 12px;
  }

  .card {
    padding: 12px;
  }

  .modal {
    padding: 16px;
    max-height: 85vh;
  }
}

@media (max-width: 480px) {
  :root {
    --cell-size: 40px;
    --cell-gap: 6px;
    --key-height: 44px;
    --key-min-width: 32px;
  }

  .cell {
    font-size: 18px;
  }

  .attempt-badge.success {
    font-size: 18px;
    padding: 4px 8px;
  }

  .guess-wrapper {
    gap: 12px;
  }

  .key {
    font-size: 14px;
    padding: 0 6px;
  }

  .k-row {
    gap: 4px;
  }

  .keyboard {
    gap: 6px;
  }

  .title {
    font-size: 24px;
  }

  .modal h3 {
    font-size: 18px;
  }

  .stat-value {
    font-size: 1rem;
  }
}

@media (max-width: 360px) {
  :root {
    --cell-size: 36px;
    --cell-gap: 4px;
    --key-height: 40px;
    --key-min-width: 28px;
  }

  .cell {
    font-size: 16px;
  }

  .attempt-badge.success {
    font-size: 16px;
  }

  .guess-wrapper {
    gap: 8px;
  }

  .key {
    font-size: 13px;
    padding: 0 4px;
  }

  .k-row {
    gap: 3px;
  }

  .nav-buttons .btn {
    font-size: 12px;
    padding: 6px 8px;
  }
}

/* Improve touch targets */
@media (hover: none) and (pointer: coarse) {
  .btn {
    min-height: 44px;
  }

  .key {
    min-height: 44px;
  }
}

/* Add this to the END of your existing styles.css file */
/* This fixes the mobile overflow issue without breaking anything */

/* Prevent horizontal overflow on mobile */
body {
  overflow-x: hidden;
}

.container {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

/* Fix card padding on mobile to prevent overflow */
@media (max-width: 640px) {
  .card {
    padding: 8px;
    margin: 0;
  }

  .container {
    padding: 8px;
  }

  /* Make keyboard fit better */
  .keyboard {
    padding: 0 2px;
    margin-top: 16px;
  }

  .k-row {
    gap: 4px;
  }

  .key {
    min-width: 32px;
    height: 44px;
    font-size: 14px;
    padding: 0 4px;
  }

  /* Tighter spacing for game elements */
  .letter-row {
    gap: 6px;
  }

  .guess-wrapper {
    gap: 10px;
    margin-bottom: 8px;
  }

  /* Make nav buttons wrap better and smaller */
  .nav-buttons {
    padding: 0 4px;
  }

  .nav-buttons .btn {
    font-size: 12px;
    padding: 8px 10px;
    min-width: auto;
  }

  /* Reduce title size */
  .title {
    font-size: 24px;
    margin-bottom: 8px;
  }

  /* Make input actions fit better */
  .input-actions {
    margin-top: 8px;
    margin-bottom: 12px;
  }

  .give-up-actions {
    margin-top: 16px !important;
  }
}

/* Extra tight layout for very small screens */
@media (max-width: 380px) {
  .card {
    padding: 6px;
  }

  .container {
    padding: 6px;
  }

  .keyboard {
    padding: 0;
  }

  .k-row {
    gap: 3px;
  }

  .key {
    min-width: 28px;
    height: 40px;
    font-size: 13px;
    padding: 0 3px;
  }

  .letter-row {
    gap: 4px;
  }

  .nav-buttons .btn {
    font-size: 11px;
    padding: 6px 8px;
  }

  .title {
    font-size: 22px;
  }
}