:root {
  --bg-color: #f4f6f8;
  --card-bg: #ffffff;
  --text-color: #1a1a1b;
  --text-muted: #6c757d;
  --border-color: #d3d6da;
  
  --color-green: #538d4e;
  --color-yellow: #b59f3b;
  --color-red: #d32f2f;
  --color-neutral: #e2e8f0;
  
  --btn-hover: #e2e8f0;
  --accent-blue: #1976d2;
  --accent-gradient: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
  background-color: var(--bg-color);
  color: var(--text-color);
  display: flex;
  justify-content: center;
  min-height: 100vh;
}

.app-container {
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 10px;
}

/* Header Ristrutturato & Modernizzato */
.header {
  border-bottom: 2px solid #e9ecef;
  padding-bottom: 12px;
  margin-bottom: 12px;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-badge {
  font-size: 1.3rem;
  background: var(--accent-gradient);
  padding: 4px 8px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #111827;
  text-transform: uppercase;
}

.brand-title .highlight {
  background: linear-gradient(90deg, #2563eb, #3b82f6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.icon-btn {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 50%;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  transition: transform 0.1s ease;
}

.icon-btn:active {
  transform: scale(0.92);
}

.mode-bar {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 10px;
}

.mode-btn {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s ease;
}

.mode-btn.active {
  background: var(--accent-gradient);
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 2px 6px rgba(30, 60, 114, 0.25);
}

/* Game Area */
.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.status-banner {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 600;
}

.surrender-btn {
  background: #fff;
  border: 1px solid var(--color-red);
  color: var(--color-red);
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  transition: background 0.15s ease;
}

.surrender-btn:hover {
  background: #ffebee;
}

.board {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}

.attempt-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.attempt-letters {
  display: flex;
  gap: 4px;
  flex: 1;
}

.letter-btn, .tile-empty {
  width: 18%;
  aspect-ratio: 1;
  max-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: bold;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--card-bg);
  color: var(--text-color);
  cursor: pointer;
  user-select: none;
}

.tile-empty {
  cursor: default;
  background: #ffffff;
  border-color: #e0e0e0;
}

.tile-neutral { 
  background: var(--card-bg); 
  color: var(--text-color);
}
.tile-green { 
  background: var(--color-green); 
  border-color: var(--color-green); 
  color: #ffffff; 
}
.tile-yellow { 
  background: var(--color-yellow); 
  border-color: var(--color-yellow); 
  color: #ffffff; 
}
.tile-red { 
  background: var(--color-red); 
  border-color: var(--color-red); 
  color: #ffffff; 
}

/* Keyframes Animazione Lettere */
.reveal-pop {
  animation: revealPop 0.4s ease-in-out forwards;
}

@keyframes revealPop {
  0% {
    transform: rotateX(0deg) scale(0.9);
  }
  50% {
    transform: rotateX(90deg) scale(1.05);
  }
  100% {
    transform: rotateX(0deg) scale(1);
  }
}

.attempt-scores {
  display: flex;
  gap: 3px;
  font-size: 0.75rem;
}

.score-badge {
  padding: 3px 5px;
  border-radius: 4px;
  font-weight: bold;
}

.bg-green { background: #e8f5e9; color: #2e7d32; }
.bg-yellow { background: #fffde7; color: #f57f17; }
.bg-red { background: #ffebee; color: #c62828; }

/* Form e gestione Errore Inline */
.input-form {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
}

.input-form input {
  flex: 1;
  padding: 10px;
  font-size: 1.1rem;
  text-transform: uppercase;
  text-align: center;
  letter-spacing: 3px;
  border: 2px solid var(--border-color);
  border-radius: 6px;
  background: var(--card-bg);
  color: var(--text-color);
  font-weight: bold;
}

.input-form input:focus {
  outline: none;
  border-color: var(--accent-blue);
}

.input-form button {
  padding: 0 15px;
  font-weight: bold;
  background: var(--accent-blue);
  color: #ffffff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.input-error {
  color: var(--color-red);
  font-size: 0.85rem;
  font-weight: 700;
  text-align: center;
  min-height: 20px;
  margin-bottom: 8px;
}

/* Animazione Shake (scuotimento) per errore */
.shake {
  animation: shake 0.35s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* Keyboard */
.keyboard-section {
  background: var(--card-bg);
  padding: 10px 8px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.keyboard-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.kb-tip {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.kb-mode-btn {
  background: var(--border-color);
  color: var(--text-color);
  border: none;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}

.kb-mode-btn.active-color {
  background: #e91e63;
  color: #ffffff;
}

.keyboard-container {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: 4px;
}

.key-btn {
  flex: 1;
  max-width: 38px;
  height: 42px;
  border: none;
  border-radius: 4px;
  font-weight: bold;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--text-color);
  user-select: none;
}

.key-btn.wide {
  max-width: 58px;
  font-size: 0.7rem;
}

.key-neutral { background: var(--color-neutral); color: var(--text-color); }
.key-green { background: var(--color-green); color: #ffffff; }
.key-yellow { background: var(--color-yellow); color: #ffffff; }
.key-red { background: var(--color-red); color: #ffffff; }

/* Footer */
.footer {
  margin-top: auto;
  padding: 12px 0;
  text-align: center;
}

.coffee-btn {
  color: #d97706;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  transition: opacity 0.2s;
}

.coffee-btn:hover {
  opacity: 0.8;
}

/* Modals */
.modal {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.5);
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal.show {
  display: flex;
}

.modal-content {
  background: var(--card-bg);
  color: var(--text-color);
  padding: 20px;
  border-radius: 10px;
  width: 90%;
  max-width: 400px;
  position: relative;
  box-shadow: 0 4px 15px rgba(0,0,0,0.15);
}

.close-modal {
  position: absolute;
  top: 10px; right: 15px;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
}

.rule-legend {
  margin: 12px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
}

.badge {
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: bold;
  font-size: 0.8rem;
  color: #fff;
}
.badge-green { background: var(--color-green); }
.badge-yellow { background: var(--color-yellow); }
.badge-red { background: var(--color-red); }

.rule-tip {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 15px;
}

.btn-primary {
  width: 100%;
  padding: 10px;
  background: var(--accent-blue);
  color: #ffffff;
  border: none;
  border-radius: 6px;
  font-weight: bold;
  cursor: pointer;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 15px 0;
}

.stat-box {
  background: var(--bg-color);
  padding: 8px;
  border-radius: 6px;
  text-align: center;
  border: 1px solid var(--border-color);
}

.stat-value {
  font-size: 1.2rem;
  font-weight: bold;
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.result-msg {
  padding: 10px;
  border-radius: 6px;
  text-align: center;
  margin-bottom: 10px;
  font-weight: bold;
}

.result-msg.win { background: #e8f5e9; color: #2e7d32; }
.result-msg.lose { background: #ffebee; color: #c62828; }
.hidden { display: none !important; }