:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #08101f;
  --surface: rgba(15, 24, 43, 0.78);
  --surface-strong: rgba(19, 31, 55, 0.96);
  --border: rgba(255, 255, 255, 0.09);
  --text: #f7f9ff;
  --muted: #99a8c2;
  --accent: #7c8cff;
  --accent-strong: #9a7cff;
  --success: #72e6ae;
  --danger: #ff7788;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(65, 78, 145, 0.18), transparent 34rem),
    linear-gradient(180deg, #0b1325 0%, #07101d 100%);
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 3px solid rgba(124, 140, 255, 0.5);
  outline-offset: 3px;
}

.background-glow {
  position: fixed;
  width: 28rem;
  height: 28rem;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.16;
  pointer-events: none;
}

.background-glow--one {
  top: -10rem;
  right: -8rem;
  background: #6c7cff;
}

.background-glow--two {
  bottom: -14rem;
  left: -10rem;
  background: #7e4dff;
}

.app-shell {
  position: relative;
  width: min(1080px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 56px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 38px;
}

.brand__mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 15px;
  background: linear-gradient(135deg, #7185ff, #a05df6);
  box-shadow: 0 12px 30px rgba(106, 104, 255, 0.28);
  font-size: 1.35rem;
  font-weight: 900;
}

.brand h1,
.hero h2,
.game-toolbar h2,
.stats-section h3,
.result-panel h2 {
  margin: 0;
}

.brand h1 {
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.view {
  display: none;
}

.view--active {
  display: block;
}

#homeView {
  grid-template-columns: minmax(0, 1.08fr) minmax(320px, 0.92fr);
  gap: 44px;
  align-items: center;
}

#homeView.view--active {
  display: grid;
}

.hero {
  padding: 36px 0;
}

.hero h2 {
  max-width: 700px;
  font-size: clamp(2.7rem, 6vw, 5.6rem);
  line-height: 0.95;
  letter-spacing: -0.065em;
}

.hero h2 span {
  color: #a6b0ff;
}

.hero__copy {
  max-width: 630px;
  margin: 28px 0 30px;
  color: #b5c0d3;
  font-size: 1.05rem;
  line-height: 1.7;
}

.hero__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.install-hint {
  max-width: 560px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
}

.primary-button,
.secondary-button,
.icon-button,
.text-button {
  border: 0;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, opacity 160ms ease;
}

.primary-button {
  display: inline-flex;
  min-height: 54px;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 0 22px;
  border-radius: 16px;
  color: white;
  background: linear-gradient(135deg, #7185ff, #985ff4);
  box-shadow: 0 16px 36px rgba(102, 102, 246, 0.28);
  font-weight: 800;
}

.primary-button:hover,
.secondary-button:hover,
.icon-button:hover {
  transform: translateY(-2px);
}

.stats-section {
  padding: 26px;
  border: 1px solid var(--border);
  border-radius: 28px;
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.section-heading,
.game-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.stats-section h3 {
  font-size: 1.35rem;
}

.text-button {
  padding: 8px 0;
  color: var(--muted);
  background: transparent;
  font-size: 0.82rem;
}

.text-button:hover {
  color: white;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 22px;
}

.stat-card {
  min-height: 122px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.035);
}

.stat-card__label {
  display: block;
  margin-bottom: 20px;
  color: var(--muted);
  font-size: 0.83rem;
}

.stat-card strong {
  font-size: 2rem;
  letter-spacing: -0.04em;
}

.stat-card small {
  margin-left: 3px;
  color: var(--muted);
  font-size: 0.9rem;
}

#gameView {
  max-width: 920px;
  margin: 0 auto;
}

.game-toolbar {
  margin-bottom: 20px;
}

.game-toolbar h2 {
  font-size: 1.5rem;
}

.icon-button {
  display: grid;
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 14px;
  color: white;
  background: rgba(255, 255, 255, 0.05);
  font-size: 1.3rem;
}

.score-pill {
  min-width: 70px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.05);
  text-align: center;
  font-weight: 700;
}

.score-pill span {
  color: white;
}

.number-panel {
  margin-bottom: 18px;
  padding: 22px 26px;
  border: 1px solid rgba(139, 147, 255, 0.28);
  border-radius: 24px;
  background:
    linear-gradient(135deg, rgba(113, 133, 255, 0.16), rgba(152, 95, 244, 0.09)),
    var(--surface-strong);
  text-align: center;
  box-shadow: var(--shadow);
}

.number-panel__label,
.number-panel__hint {
  margin: 0;
  color: var(--muted);
}

.number-panel__label {
  font-size: 0.82rem;
  font-weight: 700;
}

.current-number {
  margin: 4px 0 2px;
  font-size: clamp(3.2rem, 9vw, 5.3rem);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.06em;
}

.number-panel__hint {
  min-height: 22px;
  font-size: 0.9rem;
}

.number-panel__hint--error {
  color: #ff9da9;
}

.board {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.slot {
  display: flex;
  min-height: 72px;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  color: white;
  background: rgba(255, 255, 255, 0.038);
  cursor: pointer;
  text-align: left;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}

.slot:hover:not(:disabled) {
  transform: translateY(-2px);
  border-color: rgba(124, 140, 255, 0.5);
  background: rgba(124, 140, 255, 0.09);
}

.slot:disabled {
  cursor: default;
}

.slot--filled {
  border-color: rgba(114, 230, 174, 0.18);
  background: rgba(114, 230, 174, 0.065);
}

.slot--invalid {
  animation: shake 260ms ease;
  border-color: rgba(255, 119, 136, 0.72);
}

.slot__position {
  display: grid;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  place-items: center;
  border-radius: 9px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.055);
  font-size: 0.72rem;
  font-weight: 800;
}

.slot__value {
  margin-left: auto;
  font-size: 1.15rem;
  font-weight: 850;
  letter-spacing: -0.02em;
}

.slot--empty .slot__value {
  color: rgba(255, 255, 255, 0.24);
}

.result-panel {
  margin-top: 18px;
  padding: 30px;
  border: 1px solid var(--border);
  border-radius: 26px;
  background: var(--surface-strong);
  box-shadow: var(--shadow);
  text-align: center;
}

.result-panel__icon {
  display: grid;
  width: 58px;
  height: 58px;
  margin: 0 auto 18px;
  place-items: center;
  border-radius: 18px;
  background: rgba(124, 140, 255, 0.15);
  font-size: 1.65rem;
}

.result-panel p:not(.eyebrow) {
  color: var(--muted);
  line-height: 1.6;
}

.result-panel__actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 22px;
}

.secondary-button {
  min-height: 54px;
  padding: 0 20px;
  border: 1px solid var(--border);
  border-radius: 16px;
  color: white;
  background: rgba(255, 255, 255, 0.05);
  font-weight: 750;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 26px;
  padding: 10px 0 14px;
  background: linear-gradient(180deg, rgba(8, 16, 31, 0.96) 72%, rgba(8, 16, 31, 0));
  backdrop-filter: blur(14px);
}

.topbar .brand {
  margin-bottom: 0;
}

.identity {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-code {
  min-width: 128px;
  padding: 8px 12px;
  border: 1px solid rgba(124, 140, 255, 0.28);
  border-radius: 14px;
  color: white;
  background: rgba(124, 140, 255, 0.09);
  cursor: pointer;
  text-align: right;
}

.user-code span {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.user-code strong {
  font-size: 0.95rem;
  letter-spacing: 0.09em;
}

.user-code--copied {
  border-color: rgba(114, 230, 174, 0.5);
}

.identity__restore {
  padding: 8px 2px;
  border: 0;
  color: #b8c0ff;
  background: transparent;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 750;
}

.identity__restore:hover {
  color: white;
}

.history-section {
  grid-column: 1 / -1;
  padding: 26px;
  border: 1px solid var(--border);
  border-radius: 28px;
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.history-section h3 {
  margin: 0;
  font-size: 1.35rem;
}

.history-count {
  color: var(--muted);
  font-size: 0.82rem;
}

.history-list {
  display: grid;
  gap: 9px;
  max-height: 410px;
  margin-top: 20px;
  overflow-y: auto;
  padding-right: 4px;
}

.history-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 14px;
  min-height: 54px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.03);
}

.history-entry__date {
  color: var(--muted);
  font-size: 0.82rem;
}

.history-entry__score {
  font-size: 1rem;
  font-weight: 850;
}

.history-entry__score small {
  color: var(--muted);
  font-size: 0.72rem;
}

.history-entry__result {
  min-width: 66px;
  padding: 5px 8px;
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.05);
  font-size: 0.7rem;
  font-weight: 800;
  text-align: center;
}

.history-entry__result--win {
  color: var(--success);
  background: rgba(114, 230, 174, 0.09);
}

.history-empty {
  margin: 8px 0;
  color: var(--muted);
  text-align: center;
}

.code-dialog {
  width: min(460px, calc(100% - 24px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 26px;
  color: var(--text);
  background: #101a2d;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.55);
}

.code-dialog::backdrop {
  background: rgba(2, 7, 15, 0.72);
  backdrop-filter: blur(5px);
}

.code-dialog__content {
  display: grid;
  gap: 18px;
  padding: 28px;
}

.code-dialog h2 {
  margin: 0;
}

.code-dialog__copy,
.code-warning,
.code-error {
  margin: 8px 0 0;
  line-height: 1.55;
}

.code-dialog__copy,
.code-warning {
  color: var(--muted);
  font-size: 0.88rem;
}

.code-warning {
  margin: 0;
  font-size: 0.76rem;
}

.code-error {
  margin: -8px 0 0;
  color: #ff9da9;
  font-size: 0.82rem;
}

.code-field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 750;
}

.code-field input {
  width: 100%;
  min-height: 52px;
  padding: 0 15px;
  border: 1px solid var(--border);
  border-radius: 14px;
  outline: none;
  color: white;
  background: rgba(255, 255, 255, 0.05);
  font: inherit;
  font-size: 1.05rem;
  font-weight: 850;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.code-field input:focus {
  border-color: rgba(124, 140, 255, 0.65);
  box-shadow: 0 0 0 3px rgba(124, 140, 255, 0.12);
}

.code-dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  33% { transform: translateX(-5px); }
  66% { transform: translateX(5px); }
}

@media (max-width: 820px) {
  #homeView.view--active {
    display: block;
  }

  .hero {
    padding: 18px 0 34px;
  }

  .stats-section {
    margin-top: 8px;
  }

  .board {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .app-shell {
    width: min(100% - 20px, 1080px);
    padding-top: 20px;
  }

  .brand {
    margin-bottom: 24px;
  }

  .hero h2 {
    font-size: clamp(2.55rem, 13vw, 4rem);
  }

  .hero__copy {
    margin: 22px 0 24px;
    font-size: 0.98rem;
  }

  .primary-button {
    width: 100%;
  }

  .stats-section {
    padding: 18px;
    border-radius: 22px;
  }

  .stat-card {
    min-height: 108px;
    padding: 15px;
  }

  .game-toolbar {
    align-items: flex-start;
  }

  .game-toolbar > div:nth-child(2) {
    flex: 1;
  }

  .game-toolbar h2 {
    font-size: 1.25rem;
  }

  .number-panel {
    padding: 18px;
  }

  .board {
    gap: 7px;
  }

  .slot {
    min-height: 61px;
    padding: 9px 10px;
    border-radius: 15px;
  }

  .slot__position {
    width: 24px;
    height: 24px;
    flex-basis: 24px;
    border-radius: 7px;
  }

  .result-panel__actions {
    flex-direction: column;
  }

  .secondary-button {
    width: 100%;
  }
}

@media (max-width: 820px) {
  .history-section {
    margin-top: 18px;
  }
}

@media (max-width: 520px) {
  .topbar {
    gap: 10px;
    margin-bottom: 18px;
    padding-top: 4px;
  }

  .brand {
    gap: 9px;
  }

  .brand__mark {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    font-size: 1.1rem;
  }

  .brand h1 {
    font-size: 0.95rem;
  }


  .brand .eyebrow {
    font-size: 0.58rem;
  }

  .identity {
    gap: 6px;
  }

  .user-code {
    min-width: 104px;
    padding: 7px 9px;
    border-radius: 12px;
  }

  .user-code span {
    font-size: 0.56rem;
  }

  .user-code strong {
    font-size: 0.78rem;
  }

  .identity__restore {
    max-width: 58px;
    font-size: 0.67rem;
    line-height: 1.15;
  }


  .history-section {
    padding: 18px;
    border-radius: 22px;
  }

  .history-entry {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px 12px;
    padding: 10px 12px;
  }

  .history-entry__result {
    grid-column: 1 / -1;
    justify-self: start;
  }

  .code-dialog__content {
    padding: 22px;
  }

  .code-dialog__actions {
    flex-direction: column-reverse;
  }
}

/* Mobile game viewport + refreshed brand treatment */
.brand__mark {
  display: block;
  width: 50px;
  height: 50px;
  flex: 0 0 50px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: 17px;
  background: transparent;
  box-shadow: 0 10px 24px rgba(51, 31, 137, 0.26);
}

.brand__mark img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.topbar {
  top: 10px;
  padding: 12px 16px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 24px;
  background: linear-gradient(135deg, rgba(105, 125, 255, 0.94), rgba(151, 82, 222, 0.94));
  box-shadow: 0 16px 42px rgba(66, 43, 170, 0.28);
  backdrop-filter: blur(18px);

}

.topbar .eyebrow,
.topbar .user-code span {
  color: rgba(255, 255, 255, 0.72);
}

.user-code {
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(28, 18, 88, 0.18);
}

.identity__restore {
  color: rgba(255, 255, 255, 0.88);
}

.identity__restore:hover {
  color: #fff;
}

.board-scroll {
  min-height: 0;
}

@media (max-width: 520px) {
  body.game-view-active {
    height: 100dvh;
    min-height: 100dvh;

    overflow: hidden;
  }

  body.game-view-active .app-shell {
    display: flex;
    height: 100dvh;
    min-height: 0;
    flex-direction: column;
    overflow: hidden;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  body.game-view-active .topbar {
    position: relative;
    top: auto;
    flex: 0 0 auto;
    margin-bottom: 10px;
  }

  body.game-view-active #gameView.view--active {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    flex-direction: column;
  }

  body.game-view-active .game-toolbar {
    flex: 0 0 auto;
    margin-bottom: 10px;

  }

  body.game-view-active .number-panel {
    flex: 0 0 auto;
    margin-bottom: 10px;
    padding: 12px 16px;
  }

  body.game-view-active .current-number {
    font-size: clamp(2.8rem, 14vw, 4rem);
  }

  body.game-view-active .board-scroll {
    order: 4;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    -webkit-overflow-scrolling: touch;
    padding: 2px 2px 12px;
  }

  body.game-view-active .result-panel {
    order: 3;
    flex: 0 0 auto;
    max-height: 36dvh;

    margin: 0 0 10px;
    overflow-y: auto;
    padding: 16px;
  }

  body.game-view-active .result-panel__icon {
    width: 42px;
    height: 42px;
    margin-bottom: 10px;
  }

  body.game-view-active .result-panel__actions {
    margin-top: 12px;
  }

  .topbar {
    top: 8px;
    padding: 9px 10px;
    border-radius: 19px;
  }

  .brand__mark {
    width: 42px;
    height: 42px;
    flex-basis: 42px;
    border-radius: 14px;
  }


  .user-code {
    background: rgba(28, 18, 88, 0.22);
  }
}

@media (max-width: 520px) {
  body.result-popup-open::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 80;
    background: rgba(4, 8, 19, 0.72);
    backdrop-filter: blur(5px);
  }

  body.game-view-active .result-panel:not([hidden]) {
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 90;
    order: initial;
    width: min(340px, calc(100vw - 28px));
    max-height: none;
    margin: 0;
    overflow: visible;
    padding: 22px 18px;
    border-radius: 24px;
    transform: translate(-50%, -50%);
    box-shadow: 0 28px 80px rgba(0, 0, 0, 0.52);
  }

  body.game-view-active .result-panel:not([hidden]) .result-panel__icon {
    width: 48px;

    height: 48px;
    margin-bottom: 12px;
  }

  body.game-view-active .result-panel:not([hidden]) h2 {
    font-size: 1.5rem;
  }

  body.game-view-active .result-panel:not([hidden]) p:not(.eyebrow) {
    margin: 10px 0 0;
    font-size: 0.9rem;
    line-height: 1.45;
  }

  body.game-view-active .result-panel:not([hidden]) .result-panel__actions {
    margin-top: 16px;
  }

  body.game-view-active .result-panel:not([hidden]) .primary-button,
  body.game-view-active .result-panel:not([hidden]) .secondary-button {
    min-height: 48px;
  }
}
