/* ============================================================
   NUMERICLE — style.css
   Mobile-first clean white design
   ============================================================ */

/* ---- Reset & Base ---- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: #ffffff;
  color: #1a1a1b;
  display: flex;
  flex-direction: column;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
}

/* ---- App Shell ---- */
#app {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 0 14px;
}

/* ============================================================
   HEADER
   ============================================================ */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 2px 12px;
  border-bottom: 1px solid #e0e0e0;
  margin-bottom: 14px;
  position: relative;
}

.header-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex: 1;
}

.game-title {
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 5px;
  color: #1a1a1b;
  line-height: 1;
}

.puzzle-meta {
  font-size: 12px;
  color: #787c7e;
  font-weight: 500;
  letter-spacing: 0.2px;
}

.streak-display {
  font-size: 15px;
  font-weight: 700;
  color: #d97706;
  line-height: 1;
}

.streak-display strong {
  font-weight: 900;
}

.icon-btn {
  background: none;
  border: 2px solid transparent;
  cursor: pointer;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 800;
  color: #1a1a1b;
  border-radius: 8px;
  transition: background 0.15s;
  flex-shrink: 0;
}
.icon-btn:hover { background: #f4f4f5; }
.icon-btn svg { pointer-events: none; }

/* ============================================================
   MAIN LAYOUT
   ============================================================ */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 13px;
  padding-bottom: 28px;
}

/* ============================================================
   TARGET ZONE
   ============================================================ */
.target-zone {
  text-align: center;
  padding: 8px 0 2px;
}

.target-display {
  display: inline-block;
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 2px;
  color: #1a1a1b;
  min-height: 44px;
  transition: color 0.3s;
}

.target-win  { color: #538d4e !important; }
.target-lose { color: #c0392b !important; }

.target-hint {
  font-size: 13px;
  color: #b8b8b8;
  font-weight: 500;
  margin-top: 4px;
}

.equation-hint {
  font-size: 13px;
  color: #b8b8b8;
  font-weight: 500;
  text-align: center;
}

/* ============================================================
   EQUATION ROW
   ============================================================ */
.equation-row {
  background: #f9f9fa;
  border: 2px solid #e0e0e0;
  border-radius: 12px;
  padding: 12px 12px 10px;
  min-height: 86px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.equation-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  min-height: 44px;
  align-items: center;
  width: 100%;
}

.equation-placeholder {
  color: #b8b8b8;
  font-size: 13px;
  text-align: center;
  font-weight: 500;
  pointer-events: none;
}

.equation-result {
  font-size: 20px;
  font-weight: 800;
  color: #1a1a1b;
  min-height: 26px;
  visibility: hidden;
  letter-spacing: 0.5px;
}

.equation-error {
  font-size: 13px;
  color: #c0392b;
  font-weight: 600;
  min-height: 18px;
  text-align: center;
  display: none;
}

/* ============================================================
   TILES — Base Styles
   ============================================================ */
.tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  border: none;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  user-select: none;
  transition: transform 0.1s, opacity 0.2s, background 0.15s;
  -webkit-user-select: none;
}
.tile:active:not(:disabled) { transform: scale(0.91); }

/* Number bank tiles */
.num-tile {
  background: #1a1a1b;
  color: #ffffff;
  border-radius: 10px;
  font-size: 20px;
  font-weight: 800;
  min-width: 50px;
  height: 54px;
  padding: 0 10px;
  flex: 1;
  max-width: 74px;
}
.num-tile:hover:not(:disabled) { background: #3a3a3b; }
.num-tile.used {
  background: #d3d6da;
  color: #9a9a9a;
  cursor: not-allowed;
  opacity: 0.6;
  border: 2px dashed #c0c0c0;
}

/* Operator tiles */
.op-tile {
  background: #ffffff;
  color: #1a1a1b;
  border: 2px solid #d3d6da;
  border-radius: 10px;
  font-size: 22px;
  font-weight: 700;
  width: 52px;
  height: 52px;
}
.op-tile:hover { background: #f4f4f5; border-color: #b0b0b0; }

/* Equation display tiles */
.eq-tile {
  border-radius: 8px;
  font-size: 17px;
  font-weight: 700;
  min-width: 38px;
  height: 42px;
  padding: 0 10px;
  cursor: pointer;
}
.eq-tile:hover { opacity: 0.7; }

.eq-num {
  background: #1a1a1b;
  color: #ffffff;
}
.eq-op {
  background: #f0f0f0;
  color: #1a1a1b;
  border: 1.5px solid #d3d6da;
}

/* ============================================================
   TILE BANKS
   ============================================================ */
.tile-bank {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.number-bank { gap: 8px; }

.operator-bank {
  gap: 6px;
  flex-wrap: wrap;
}

/* ============================================================
   CONTROL BUTTONS
   ============================================================ */
.controls {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.btn {
  border: none;
  border-radius: 10px;
  font-family: 'Inter', sans-serif;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  letter-spacing: 0.3px;
}
.btn:active { transform: scale(0.96); }

.btn-secondary {
  background: #d3d6da;
  color: #1a1a1b;
  padding: 13px 18px;
  font-size: 14px;
  flex: 1;
  max-width: 115px;
}
.btn-secondary:hover { background: #bfc3c8; }

.btn-primary {
  background: #1a1a1b;
  color: #ffffff;
  padding: 13px 32px;
  font-size: 16px;
  flex: 1.6;
  max-width: 165px;
}
.btn-primary:hover { background: #3d3d3e; }

/* ============================================================
   GUESS HISTORY
   ============================================================ */
.guess-history {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f9f9fa;
  border: 1px solid #e4e4e4;
  border-radius: 10px;
  padding: 10px 12px;
  gap: 10px;
}

.history-eq {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  flex-wrap: wrap;
  min-width: 0;
}

.history-expr {
  font-size: 14px;
  font-weight: 600;
  color: #1a1a1b;
  word-break: break-word;
}

.history-result {
  font-size: 14px;
  font-weight: 800;
  color: #538d4e;
  white-space: nowrap;
}

/* ============================================================
   FEEDBACK TILES
   ============================================================ */
.feedback-tile {
  width: 46px;
  height: 46px;
  min-width: 46px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 900;
  color: #ffffff;
  flex-shrink: 0;
  line-height: 1;
}

.feedback-tile.green  { background: #538d4e; }
.feedback-tile.orange { background: #c9a227; }
.feedback-tile.red    { background: #c0392b; }

/* ============================================================
   FOOTER
   ============================================================ */
footer {
  text-align: center;
  padding: 18px 0;
  color: #9a9a9a;
  font-size: 13px;
  border-top: 1px solid #f0f0f0;
  margin-top: auto;
}

footer a {
  color: #787c7e;
  text-decoration: none;
  border-bottom: 1px solid #d3d6da;
  transition: color 0.15s;
}
footer a:hover { color: #1a1a1b; }

/* ============================================================
   MODALS
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.52);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
  animation: fade-in 0.15s ease;
}
.modal-overlay.hidden { display: none; }

.modal-card {
  background: #ffffff;
  border-radius: 16px;
  padding: 28px 22px 24px;
  max-width: 440px;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  position: relative;
  animation: slide-up 0.2s ease;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: none;
  border: none;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  color: #9a9a9a;
  padding: 4px 6px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}
.modal-close:hover { color: #1a1a1b; background: #f4f4f5; }

.modal-card h2 {
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 16px;
  letter-spacing: 0.3px;
}

.modal-card h3 {
  font-size: 15px;
  font-weight: 700;
  margin: 18px 0 10px;
  color: #3a3a3c;
}

.modal-card p {
  font-size: 14px;
  line-height: 1.65;
  margin-bottom: 10px;
  color: #3a3a3c;
}

.modal-card ul {
  font-size: 14px;
  line-height: 1.8;
  padding-left: 18px;
  color: #3a3a3c;
  margin-bottom: 10px;
}

.modal-card code {
  background: #f4f4f5;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 13px;
  font-family: 'Courier New', monospace;
}

/* ============================================================
   HELP MODAL — Tile Legend
   ============================================================ */
.tile-legend {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: #3a3a3c;
}

.legend-row .feedback-tile {
  width: 40px;
  height: 40px;
  min-width: 40px;
  font-size: 20px;
  flex-shrink: 0;
}

/* ============================================================
   STATS MODAL
   ============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}

.stat-item {
  text-align: center;
  padding: 12px 4px 10px;
  background: #f9f9fa;
  border-radius: 10px;
}

.stat-number {
  font-size: 30px;
  font-weight: 900;
  color: #1a1a1b;
  line-height: 1;
}

.stat-label {
  font-size: 9px;
  font-weight: 700;
  color: #787c7e;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-top: 5px;
}

.guess-dist {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.dist-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dist-label {
  font-size: 13px;
  font-weight: 800;
  width: 16px;
  text-align: center;
  flex-shrink: 0;
}

.dist-bar-wrap {
  flex: 1;
  min-width: 0;
}

.dist-bar {
  background: #787c7e;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 8px 4px 0;
  border-radius: 4px;
  min-width: 26px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  transition: width 0.5s ease;
}

.dist-bar-current { background: #538d4e; }
.dist-bar-fail    { background: #c0392b; }

/* ============================================================
   COMPLETION MODAL
   ============================================================ */
.complete-title {
  font-size: 22px;
  font-weight: 900;
  text-align: center;
  margin-bottom: 12px;
  letter-spacing: 0.3px;
}

.win-title  { color: #538d4e; }
.lose-title { color: #c0392b; }

.complete-target {
  text-align: center;
  margin-bottom: 16px;
}

.target-big {
  font-size: 56px;
  font-weight: 900;
  color: #1a1a1b;
  line-height: 1;
  letter-spacing: -1px;
}

.complete-history {
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.complete-pct {
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: #787c7e;
  margin-bottom: 12px;
  min-height: 20px;
}

.complete-streaks {
  display: flex;
  justify-content: center;
  gap: 28px;
  font-size: 14px;
  color: #3a3a3c;
  margin-bottom: 16px;
}

.complete-streaks strong {
  font-weight: 900;
  color: #d97706;
}

.btn-share {
  background: #538d4e;
  color: #ffffff;
  padding: 14px 0;
  width: 100%;
  font-size: 17px;
  border-radius: 10px;
  margin-bottom: 8px;
  letter-spacing: 0.3px;
}
.btn-share:hover { background: #466f3f; }

.share-confirm {
  text-align: center;
  color: #538d4e;
  font-size: 14px;
  font-weight: 700;
  min-height: 22px;
  margin-bottom: 6px;
}
.share-confirm.hidden { visibility: hidden; }

.promo-text {
  text-align: center;
  font-size: 13px;
  color: #9a9a9a;
  margin-bottom: 18px;
  font-style: italic;
}

.countdown-section {
  text-align: center;
  border-top: 1px solid #e8e8e8;
  padding-top: 18px;
}

.countdown-label {
  font-size: 11px;
  color: #9a9a9a;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 5px;
  font-weight: 600;
}

.countdown-timer {
  font-size: 30px;
  font-weight: 900;
  color: #1a1a1b;
  font-variant-numeric: tabular-nums;
  letter-spacing: 3px;
}

/* ============================================================
   CONFETTI
   ============================================================ */
.confetti-piece {
  position: fixed;
  top: -12px;
  z-index: 9999;
  pointer-events: none;
  animation: confetti-fall linear forwards;
}

/* ============================================================
   ANIMATIONS
   ============================================================ */

/* Shake — used on target ???  and equation row */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  12%  { transform: translateX(-7px); }
  25%  { transform: translateX(7px); }
  38%  { transform: translateX(-5px); }
  52%  { transform: translateX(5px); }
  66%  { transform: translateX(-3px); }
  80%  { transform: translateX(3px); }
}
.shake { animation: shake 0.42s ease-in-out; }

/* Snap-in — tile added to equation */
@keyframes snap-in {
  0%   { transform: scale(0.55); opacity: 0.4; }
  65%  { transform: scale(1.18); }
  100% { transform: scale(1);    opacity: 1; }
}
.snap-in { animation: snap-in 0.24s cubic-bezier(0.34, 1.56, 0.64, 1); }

/* Tile reveal — feedback tile after shake */
@keyframes tile-reveal {
  0%   { transform: scale(0.3) rotateY(-90deg); opacity: 0; }
  55%  { transform: scale(1.12) rotateY(0deg); opacity: 1; }
  100% { transform: scale(1) rotateY(0deg); opacity: 1; }
}
.tile-reveal { animation: tile-reveal 0.38s cubic-bezier(0.34, 1.56, 0.64, 1); }

/* New history row slide-in */
@keyframes new-row {
  0%   { opacity: 0; transform: translateY(10px); }
  100% { opacity: 1; transform: translateY(0); }
}
.new-row { animation: new-row 0.28s ease-out; }

/* Tile remove */
@keyframes tile-remove {
  0%   { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.65); }
}
.removing { animation: tile-remove 0.2s ease-in forwards; }

/* Target pop on win */
@keyframes target-pop {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.22); }
  65%  { transform: scale(0.95); }
  100% { transform: scale(1); }
}
.target-pop { animation: target-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1); }

/* Modal fade-in */
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Modal slide-up */
@keyframes slide-up {
  from { transform: translateY(20px); opacity: 0.5; }
  to   { transform: translateY(0);    opacity: 1;   }
}

/* Confetti fall */
@keyframes confetti-fall {
  0%   { transform: translateY(0)     rotate(0deg);   opacity: 1; }
  85%  { opacity: 1; }
  100% { transform: translateY(105vh) rotate(740deg); opacity: 0; }
}

/* ============================================================
   MISC
   ============================================================ */
body.modal-open { overflow: hidden; }

/* No-puzzle message */
.no-puzzle-msg {
  text-align: center;
  color: #787c7e;
  font-size: 16px;
  font-weight: 600;
  padding: 40px 20px;
}
