/* === Responsive Font Scaling === */
html {
  font-size: 16px;
}

@media (min-width: 768px) {
  html {
    font-size: 20px;
  }
}

@media (min-width: 1024px) {
  html {
    font-size: 22px;
  }
}

#confettiContainer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
  z-index: 9999;
}

.confetti {
  position: absolute;
  border-radius: 50%;
  animation: fall 10s ease-out forwards;
}


.confetti-tile {
  position: absolute;
  width: 24px;
  height: 24px;
  font-size: 1rem;
  font-weight: bold;
  color: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  animation: fall 10s ease-out forwards;
  box-shadow: 0 0 2px rgba(0,0,0,0.3);
}


@keyframes fall {
  to {
    transform: translateY(100vh) translateX(var(--drift)) rotate(360deg);
    opacity: 1;
  }
}



#gameTitle img {
  width: 9rem;
  height: auto;
}

@media (min-width: 768px) {
  #gameTitle img {
    width: 10rem;
  }
}

@media (min-width: 1024px) {
  #gameTitle img {
    width: 11rem;
  }
}


/* === Base Styles === */
body {
  font-family: 'Segoe UI', sans-serif;
  background-color: #3388cc;
  transition: background-color 0.3s ease;
  margin: 0;
  padding: 5px, 20px;
}

/* === Orientation Warning === */
#orientationOverlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.4);
  z-index: 999;
  display: none;
}

#orientationWarning {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: #ffcc00;
  color: #333;
  padding: 16px 24px;
  font-weight: bold;
  border: 2px solid #e65100;
  z-index: 1000;
  display: none;
  text-align: center;
  border-radius: 8px;
}

/* === Game Title === */
#gameTitle {
  font-size: 1.2rem;
  font-weight: bold;
  color: black;
  margin-bottom: 2px;
  text-align: center;
}

/* === Target Section === */
#targetSection {
  margin: 20px auto;
  text-align: center;
}

#targetLabel {
  font-size: 1.2rem;
  font-weight: bold;
  color: #000;
  margin-bottom: 10px;
}

#targetNumbers span {
  margin: 0 5px;
  font-weight: bold;
  color: black;
}

/* === Target Grid === */
#targetGrid {
  display: grid;
  grid-template-columns: repeat(4, 4.0rem);
  gap: 0.3rem;
  justify-content: center;
  margin: 0 auto;
}

.target-tile {
  width: 4.0rem;
  height: 4.0rem;
  background-image: url('octa_solid.svg');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  padding: 0.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2em;
  font-weight: bold;
  color: black;
  border: none;
  box-shadow: none;
}

.target-tile.matched {
  background-image: url('octa_grey.svg');
  color: #666;
  animation: rotate360 0.6s ease-out;
}

/* === Game Wrapper === */
.gameWrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: max-content;
  max-width: 90vw;
  padding: 1rem;
  margin: 0 auto;
}

/* === Number Grid === */
.grid,
#numberGrid {
  display: grid;
  grid-template-columns: repeat(4, 4rem);
  gap: 0.25rem;
  margin-bottom: 0.5rem;
  box-shadow: 0 4px 4px rgba(0, 0, 0, 0.1);
  border: 2px solid #ccc;
  padding: 4px;
  background-color: #000;
  border-radius: 8px;
  width: max-content;
}

/* === Tiles === */
.tile {
  font-size: 1.4rem;
  font-weight: bold;
  background-color: orange;
  color: #000;
  border: 3px solid #f57c00;
  border-radius: 10px;
  cursor: pointer;
  transition: background-color 0.3s ease;
  width: 4rem;
  height: 4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  text-align: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  position: relative;
  overflow: hidden;
}

.tile::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 50%;
  background: linear-gradient(to bottom, rgba(255,255,255,0.6), rgba(255,255,255,0));
  pointer-events: none;
}

/* === Stars === */
#starContainer {
  display: grid;
  grid-template-columns: repeat(7, 1.4rem);
  gap: 0.84rem;
  justify-content: center;
  margin-bottom: 1rem;
}

.star {
  width: 1.48rem;
  height: 1.48rem;
  background-image: url('star-filled.svg');
  background-size: cover;
}

.star.lost {
  background-image: url('star-empty.svg');
  animation: fadeStar 0.6s ease;
}

@keyframes fadeStar {
  0% { transform: scale(1.2) rotate(0deg); opacity: 1; }
  100% { transform: scale(1) rotate(-72deg); opacity: 0.3; }
}

/* === Buttons === */
#buttonRow {
  margin-top: 20px;
  display: flex;
  justify-content: center;
  gap: 10px;
  width: min(340px, calc(100vw - 32px));
  margin: 12px auto 0;
}

button {
  background-color: orange;
  color: black;
  border: 2px solid #e65100;
  border-radius: 6px;
  padding: 6px 10px;
  font-weight: bold;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.6);
  cursor: pointer;
}

button:hover {
  background-color: #e65100;
}

#submitBtn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: scale(0.98);
}

#clearBtn,
#giveUpBtn,
#submitBtn {
  flex: 1 1 0;
  height: 40px;
  font-size: 0.85em;
  white-space: nowrap;
}

#giveUpBtn {
  background: #f3c6c6;
  border-color: #a51d1d;
}

#giveUpBtn:hover {
  background: #e5aaaa;
}

/* === Modal === */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-box {
  background-color: rgba(255, 255, 255, 0.6);
  border-radius: 12px;
  padding: 20px 30px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
  font-weight: bold;
  color: #333;
  text-align: center;
  animation: scaleIn 0.3s ease-out;
}

@keyframes scaleIn {
  from { transform: scale(0.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes rotate360 {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
/* Scores and safe tab handover */
.game-menu { background: #333; text-align: center; display: flex; }
.game-menu button { flex: 1 1 50%; width: auto; min-height: 40px; color: #fff; background: #333; border: 0; border-radius: 0; box-shadow: none; font: bold 14px 'Segoe UI', sans-serif; }
.game-menu button:hover { background: #444; }
.tab-guard { position: fixed; inset: 0; z-index: 20000; background: #fff; color: #222; display: grid; place-items: center; padding: 24px; text-align: center; font: 18px 'Segoe UI', sans-serif; }
.tab-guard div { max-width: 440px; }
.tab-guard[hidden], [hidden] { display: none !important; }
#scoresDialog { box-sizing: border-box; width: min(420px, calc(100vw - 32px)); max-height: calc(100dvh - 40px); overflow-y: auto; padding: 0; border: 2px solid #333; border-radius: 12px; background: #fff; color: #222; font-size: 16px; }
#scoresDialog::backdrop { background: rgba(0, 0, 0, .45); }
.scores-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid #ccc; }
.scores-header h2 { margin: 0; font-size: 20px; }
.scores-header button { background: #eee; border: 1px solid #666; box-shadow: none; min-width: 40px; min-height: 40px; font-size: 24px; }
.stats-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 0; }
.stats-grid div { padding: 16px 8px; text-align: center; border-bottom: 1px solid #ccc; }
.stats-grid div:nth-child(odd):not(.stats-wide) { border-right: 1px solid #ccc; }
.stats-grid dt { font-size: 14px; }
.stats-grid dd { margin: 4px 0 0; font-size: 24px; font-weight: bold; }
.stats-wide { grid-column: 1 / -1; }
#scoresDialog h3 { margin: 16px; font-size: 16px; }
#scoreHistory { padding: 0 16px 16px; }
.score-history-row { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid #ddd; font-size: 14px; flex-wrap: wrap; }
.game-status, .storage-notice { max-width: 400px; margin: 12px auto; padding: 0 16px; text-align: center; font-size: 14px; font-weight: bold; }
.storage-notice { background: #fff3cd; color: #222; padding: 12px; border: 2px solid #222; }
.retry-row { text-align: center; }
button:disabled { cursor: not-allowed; opacity: .5; }

/* Share results and confirmed data clearing */
.scores-data-actions { text-align: center; margin: 14px auto; }
.scores-data-actions { padding: 0 16px 4px; }
.scores-data-actions button { width: 100%; min-height: 42px; box-shadow: none; }
#clearDataDialog, #shareTextDialog { box-sizing: border-box; width: min(420px, calc(100vw - 32px)); max-height: calc(100dvh - 40px); overflow-y: auto; padding: 20px; border: 2px solid #333; border-radius: 12px; background: #fff; color: #222; font-size: 16px; }
#clearDataDialog::backdrop, #shareTextDialog::backdrop { background: rgba(0, 0, 0, .45); }
#clearDataDialog h2 { margin: 0 0 16px; font-size: 20px; }
#clearDataDialog p { line-height: 1.5; }
.dialog-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 12px; margin-top: 20px; }
.dialog-actions button { min-height: 42px; box-shadow: none; }
#cancelClearDataBtn { background: #eee; border-color: #666; }
#confirmClearDataBtn { background: #a51d1d; border-color: #701212; color: #fff; }
#clearDataError { color: #8a1414; font-weight: bold; }
#shareTextDialog { padding: 0 0 16px; }
#shareTextDialog p { margin: 16px; }
#shareTextArea { display: block; box-sizing: border-box; width: calc(100% - 32px); margin: 0 16px; padding: 12px; border: 1px solid #555; font: 16px/1.5 'Segoe UI', sans-serif; resize: vertical; }

/* A quiet logo easter egg and no empty sharing-status space. */
.sumbers-logo, .sumbers-logo:hover { display: inline-block; margin: 0; padding: 0; background: transparent; border: 0; border-radius: 0; box-shadow: none; line-height: 0; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.sumbers-logo:focus-visible { outline: 2px solid #fff; outline-offset: 6px; }
#shareStatus:empty { display: none; }

/* Completion score modal */
#completionDialog {
  box-sizing: border-box;
  width: min(360px, calc(100vw - 32px));
  padding: 0;
  border: 2px solid #333;
  border-radius: 12px;
  background: #fff;
  color: #222;
  text-align: center;
  font: 16px 'Segoe UI', sans-serif;
}

#completionDialog::backdrop {
  background: rgba(0, 0, 0, .45);
}

.completion-dialog-content {
  padding: 24px 20px 20px;
}

#completionHeading {
  margin: 0 0 18px;
  font-size: 22px;
}

.completion-label {
  margin: 0;
  font-weight: 600;
}

.completion-score {
  margin: 4px 0 8px;
  font-size: 38px;
  line-height: 1.1;
  font-weight: 800;
}

.completion-message {
  min-height: 1.5em;
  margin: 0 0 20px;
  font-weight: 700;
}

#closeCompletionBtn {
  width: 100%;
  min-height: 42px;
  box-shadow: none;
}


/* Help and Give Up dialogs */
#helpDialog,
#giveUpDialog,
#solutionDialog {
  box-sizing: border-box;
  width: min(380px, calc(100vw - 32px));
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  padding: 0;
  border: 2px solid #333;
  border-radius: 12px;
  background: #fff;
  color: #222;
  font: 16px 'Segoe UI', sans-serif;
}

#helpDialog::backdrop,
#giveUpDialog::backdrop,
#solutionDialog::backdrop {
  background: rgba(0, 0, 0, .45);
}

#helpHeading,
#giveUpHeading,
#solutionHeading {
  margin: 0 0 18px;
  font-size: 22px;
  text-align: center;
}

.help-dialog-content {
  text-align: left;
}

.help-dialog-content h3 {
  margin: 20px 0 8px;
  font-size: 18px;
}

.help-dialog-content p,
#giveUpDescription {
  margin: 0 0 14px;
  line-height: 1.5;
}

#closeHelpBtn,
#closeSolutionBtn {
  width: 100%;
  min-height: 42px;
  margin-top: 6px;
  box-shadow: none;
}

.give-up-actions {
  justify-content: center;
}

#cancelGiveUpBtn {
  background: #eee;
  border-color: #666;
}

#confirmGiveUpBtn {
  background: #a51d1d;
  border-color: #701212;
  color: #fff;
}

.solution-pairs {
  display: grid;
  gap: 8px;
  margin: 0 0 18px;
}

.solution-pair {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid #ddd;
}

.solution-pair .pair-values {
  font-weight: 700;
  text-align: right;
}

.solution-pair .pair-equals {
  color: #666;
}

.solution-pair .pair-target {
  font-weight: 800;
  text-align: left;
}

.solution-score-label {
  margin: 4px 0 18px;
  text-align: center;
}
