*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: #FFF8F2;
  color: #3D1800;
  font-family: 'League Gothic', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
}

/* ── HEADER ── */
#header {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  padding: 8px 16px;
  background: #FFF8F2;
  border-bottom: 1px solid rgba(61,24,0,0.08);
  flex-shrink: 0;
}

.header-target {
  font-size: 52px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -1px;
  text-align: center;
  font-family: 'League Gothic', sans-serif;
  background: linear-gradient(to bottom, #ff9e4f 0%, #a83800 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0px 2px 4px rgba(0,0,0,0.12));
}

.icon-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1.5px solid rgba(61,24,0,0.15);
  background: transparent;
  color: rgba(61,24,0,0.6);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.streak-badge {
  font-size: 14px;
  font-weight: 700;
  color: #f59e0b;
  text-align: right;
}

/* ── MAIN ── */
#game-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12px 16px 10px;
  gap: 10px;
  overflow: hidden;
  background: #FFF8F2;
}

/* ── FOOTER ── */
#footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 10px 16px 12px;
  background: #FFF8F2;
  border-top: 1px solid rgba(61,24,0,0.08);
  flex-shrink: 0;
}

.footer-logo {
  width: 32px;
  height: 32px;
  object-fit: cover;
  border-radius: 8px;
}

.footer-tagline {
  text-align: center;
  font-size: 11px;
  font-style: italic;
  font-family: Georgia, 'Times New Roman', serif;
  color: rgba(61,24,0,0.55);
  line-height: 1.45;
  padding: 0 16px;
}

.footer-attribution {
  text-align: center;
  font-size: 9px;
  color: rgba(61,24,0,0.35);
  letter-spacing: 0.2px;
}

#clear-btn:disabled { opacity: 0.25; cursor: not-allowed; }

/* NUMBERS */
.numbers-grid {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
  align-items: center;
}

.number-btn {
  flex: 1;
  min-width: 0;
  height: 66px;
  padding: 0 4px;
  border-radius: 16px;
  border: 1.5px solid rgba(61,24,0,0.12);
  background: #FFF8F2;
  font-size: clamp(20px, 5.5vw, 28px);
  font-weight: 900;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}
.number-btn:active {
  transform: scale(0.94);
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.number-btn.selected {
  background: linear-gradient(to bottom, #7A3810 0%, #2E0C00 100%);
  box-shadow: 0 8px 32px rgba(74,33,6,0.20), 0 2px 8px rgba(74,33,6,0.12);
}

.tile-num {
  background: linear-gradient(to bottom, #D4893A 0%, #3D1000 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1;
  font-size: clamp(26px, 7vw, 36px);
  filter: drop-shadow(0px 2px 3px rgba(0,0,0,0.12));
}
.number-btn.selected .tile-num {
  background: none;
  -webkit-text-fill-color: #fff;
}

/* INPUT */
.input-section {
  border-radius: 16px;
  margin-top: 10px;
}

.calc-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: #FFF8F2;
  border-radius: 16px;
  padding: 12px;
  border: 1.5px solid rgba(61,24,0,0.12);
}

.num-slot {
  width: 52px; height: 52px;
  border-radius: 12px;
  border: 2px solid rgba(61,24,0,0.18);
  background: transparent;
  color: rgba(61,24,0,0.35);
  font-size: 36px;
  font-family: 'League Gothic', sans-serif;
  font-weight: 400;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}
.num-slot.filled {
  border-color: #C4622A;
  color: #C4622A !important;
  background: rgba(196, 98, 42, 0.10);
}

.op-cycle-btn {
  width: 52px; height: 52px;
  flex-shrink: 0;
  border-radius: 12px;
  border: 2px solid #F76800;
  background: rgba(247, 104, 0, 0.08);
  color: #F76800;
  font-size: 30px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.12s, transform 0.1s;
}
.op-cycle-btn:active { transform: scale(0.9); background: rgba(247,104,0,0.2); }

@keyframes calcSink {
  0%   { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(64px) scale(0.97); }
}
.calc-row.sinking {
  animation: calcSink 0.28s ease-in forwards;
  pointer-events: none;
}

@keyframes attemptSlide {
  from { opacity: 0; transform: translateY(-64px); }
  to   { opacity: 1; transform: translateY(0); }
}
.attempt-row.attempt-new {
  animation: attemptSlide 0.3s ease-out;
}

.go-btn {
  width: 52px; height: 52px;
  border-radius: 12px;
  border: none;
  background: #F76800;
  color: #fff;
  font-size: 26px;
  font-weight: 900;
  cursor: pointer;
  transition: all 0.12s;
  flex-shrink: 0;
}
.go-btn:disabled { opacity: 0.25; cursor: not-allowed; }
.go-btn:not(:disabled):active { transform: scale(0.9); background: #D95A00; }

.calc-preview {
  text-align: center;
  font-size: 16px;
  color: rgba(61,24,0,0.5);
  margin-top: 8px;
  min-height: 20px;
  font-variant-numeric: tabular-nums;
}

/* HISTORY */
.history-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
}

#attempts-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.attempt-row {
  display: grid;
  grid-template-columns: 52px 22px 52px 22px 68px;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.att-slot {
  height: 46px;
  border-radius: 10px;
  border: 2px solid rgba(61,24,0,0.12);
  background: #FFF8F2;
  color: #C4622A;
  font-size: 22px;
  font-family: 'League Gothic', sans-serif;
  font-weight: 400;
  display: flex;
  align-items: center;
  justify-content: center;
}

.att-op {
  color: rgba(61,24,0,0.4);
  font-size: 20px;
  font-weight: 700;
  text-align: center;
}

.att-eq {
  color: rgba(61,24,0,0.4);
  font-size: 20px;
  font-weight: 700;
  text-align: center;
}

.att-result {
  height: 46px;
  border-radius: 10px;
  background: rgba(247,104,0,0.12);
  border: 2px solid #F76800;
  color: #F76800;
  font-size: 18px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

.att-result.att-win {
  background: rgba(78,204,163,0.2);
  border-color: #4ecca3;
  color: #2aaa80;
}

/* POST-GAME */
.post-game {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 20px 0 8px;
}
.post-game.hidden { display: none; }

.countdown-section { text-align: center; }
.countdown-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: #C4622A;
  opacity: 0.7;
  margin-bottom: 4px;
}
.countdown-timer {
  font-size: 38px;
  font-weight: 900;
  font-family: 'League Gothic', sans-serif;
  background: linear-gradient(to bottom, #D4893A 0%, #3D1000 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  display: flex;
  align-items: baseline;
  justify-content: center;
}
.countdown-timer span {
  display: inline-block;
  width: 2.2ch;
  text-align: center;
}
.countdown-timer .cd-sep {
  width: auto;
  padding: 0 2px;
}

.game-share-row {
  display: flex;
  justify-content: center;
  gap: 14px;
}
.game-share-row .share-icon-btn {
  color: #C4622A;
  background: rgba(196, 98, 42, 0.08);
}

/* ── OVERLAYS ── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.overlay.hidden { display: none; }

/* RESULT */
.result-card {
  background: #FFF8F2;
  border-radius: 22px;
  padding: 26px 22px 20px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  border: 1px solid rgba(61,24,0,0.1);
}

.result-icon { font-size: 46px; margin-bottom: 6px; }
.result-card h2 { font-size: 28px; font-weight: 900; margin-bottom: 4px; }
.result-card > p { color: rgba(0,0,0,0.55); font-size: 13px; margin-bottom: 14px; }

.result-attempts {
  font-size: 22px;
  letter-spacing: 5px;
  margin-bottom: 18px;
}

.stats-row {
  display: flex;
  justify-content: space-around;
  border-top: 1px solid rgba(61,24,0,0.1);
  border-bottom: 1px solid rgba(61,24,0,0.1);
  padding: 12px 0;
  margin-bottom: 18px;
}
.stat-item { text-align: center; }
.stat-value { font-size: 30px; font-weight: 900; color: #F76800; }
.stat-label { font-size: 9px; text-transform: uppercase; letter-spacing: 1px; color: rgba(61,24,0,0.4); margin-top: 2px; }

.share-section { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }

.share-main-btn {
  width: 100%;
  padding: 13px;
  border-radius: 12px;
  border: none;
  background: #F76800;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
.share-main-btn:active { background: #D95A00; }

.share-icons-row { display: flex; justify-content: center; gap: 12px; }

.share-icon-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: rgba(0,0,0,0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #3D1800;
  text-decoration: none;
  transition: background 0.12s;
}
.share-icon-btn:active { background: rgba(61,24,0,0.14); }
.share-icon-btn svg { width: 22px; height: 22px; fill: currentColor; }

.retry-overlay-btn {
  width: 100%;
  padding: 13px;
  border-radius: 12px;
  border: none;
  background: #F76800;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  margin-bottom: 10px;
}
.retry-overlay-btn:active { background: #D95A00; }

.text-btn {
  background: transparent;
  border: none;
  color: rgba(61,24,0,0.4);
  font-size: 12px;
  cursor: pointer;
  text-decoration: underline;
}

/* HELP */
.help-card {
  background: #FFF8F2;
  border-radius: 22px;
  padding: 26px 22px;
  width: 100%;
  max-width: 360px;
  position: relative;
  border: 1px solid rgba(61,24,0,0.1);
}
.close-btn {
  position: absolute;
  top: 14px; right: 14px;
  background: transparent;
  border: none;
  color: rgba(61,24,0,0.45);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
}
.help-card h2 { font-size: 20px; font-weight: 900; margin-bottom: 14px; }
.help-card ol { padding-left: 20px; margin-bottom: 14px; }
.help-card li { font-size: 14px; line-height: 1.65; color: rgba(61,24,0,0.75); margin-bottom: 5px; }
.help-rules { background: rgba(61,24,0,0.05); border-radius: 12px; padding: 12px; }
.help-rules p { font-size: 13px; color: rgba(0,0,0,0.55); margin-bottom: 5px; line-height: 1.5; }
.help-rules p:last-child { margin-bottom: 0; }

.reset-btn {
  margin-top: 14px;
  width: 100%;
  padding: 10px;
  border-radius: 10px;
  border: 1.5px solid rgba(61,24,0,0.15);
  background: transparent;
  color: rgba(61,24,0,0.45);
  font-size: 13px;
  cursor: pointer;
}

/* ── SMALL SCREEN TWEAKS ── */
@media (max-height: 650px) {
  .header-target { font-size: 42px; }
  #game-screen { padding: 8px 14px 6px; gap: 7px; }
  .number-btn { height: 56px; border-radius: 14px; }
  .num-slot, .go-btn, .op-cycle-btn { width: 46px; height: 46px; }
  .op-cycle-btn { font-size: 22px; }
}
