* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-1: #081126;
  --bg-2: #1a1133;
  --bg-3: #05070f;
  --accent: #66c6ff;
  --accent-2: #9f8bff;
  --grid: rgba(130, 180, 255, 0.2);
  --text: #e7f1ff;
  --muted: rgba(231, 241, 255, 0.7);
  --chip: rgba(16, 26, 46, 0.75);
}

html, body {
  width: 100%;
  height: 100%;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(circle at 20% 20%, rgba(80, 120, 255, 0.18), transparent 55%),
    radial-gradient(circle at 80% 30%, rgba(140, 90, 255, 0.12), transparent 60%),
    linear-gradient(135deg, var(--bg-1), var(--bg-2) 55%, var(--bg-3));
  color: var(--text);
  overflow: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: -20%;
  background-image:
    radial-gradient(2px 2px at 20% 30%, rgba(150, 200, 255, 0.35), transparent 60%),
    radial-gradient(1px 1px at 70% 20%, rgba(130, 160, 255, 0.25), transparent 60%),
    radial-gradient(1.5px 1.5px at 40% 80%, rgba(180, 120, 255, 0.2), transparent 60%);
  opacity: 0.5;
  animation: drift 30s linear infinite;
  pointer-events: none;
  z-index: 0;
}

@keyframes drift {
  0% { transform: translate3d(0, 0, 0); }
  50% { transform: translate3d(-2%, 1.5%, 0); }
  100% { transform: translate3d(0, 0, 0); }
}

.app {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 10px;
}

.header {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.title-row h1 {
  font-size: 2rem;
  letter-spacing: 1px;
}

.subtitle {
  display: block;
  font-size: 0.9rem;
  color: var(--muted);
}

.status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.status-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  border: 1px solid rgba(120, 160, 255, 0.2);
  background: rgba(16, 26, 46, 0.7);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.icon-btn:active {
  transform: scale(0.95);
}

.subscribe-btn {
  height: 32px;
  padding: 0 10px;
  border-radius: 12px;
  border: 1px solid rgba(120, 160, 255, 0.2);
  background: rgba(16, 26, 46, 0.7);
  color: var(--text);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  white-space: nowrap;
}

.subscribe-btn:active {
  transform: scale(0.97);
}

.status-chip {
  padding: 8px 14px;
  border-radius: 18px;
  background: var(--chip);
  border: 1px solid rgba(120, 160, 255, 0.2);
  font-weight: 600;
}

.score {
  display: flex;
  gap: 10px;
  font-weight: 600;
}

.score-item {
  padding: 6px 10px;
  border-radius: 12px;
  background: rgba(10, 18, 35, 0.6);
  border: 1px solid rgba(120, 160, 255, 0.15);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.panel-bar {
  background: rgba(10, 18, 35, 0.55);
  border: 1px solid rgba(120, 160, 255, 0.18);
  border-radius: 16px;
  padding: 6px;
  position: relative;
  z-index: 2;
}

.control-group {
  background: rgba(10, 18, 35, 0.55);
  border: 1px solid rgba(120, 160, 255, 0.18);
  border-radius: 14px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 180px;
}

.control-group.compact {
  background: transparent;
  border: none;
  padding: 4px 6px;
  flex: 1 1 auto;
}

.control-title {
  font-size: 0.8rem;
  color: var(--muted);
}

.control-options {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.option-btn {
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid rgba(120, 160, 255, 0.25);
  background: rgba(12, 18, 38, 0.6);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.option-btn.active {
  background: linear-gradient(135deg, rgba(80, 150, 255, 0.9), rgba(150, 110, 255, 0.9));
  color: #061021;
  border: none;
  font-weight: 700;
  box-shadow: 0 6px 16px rgba(90, 140, 255, 0.35);
}

.primary-btn {
  padding: 10px 14px;
  border-radius: 14px;
  border: none;
  background: linear-gradient(135deg, #5bb8ff, #7a6dff);
  color: #050814;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.primary-btn.compact {
  min-width: 140px;
  margin-left: auto;
  padding: 8px 12px;
  font-size: 0.95rem;
}

.primary-btn:active {
  transform: scale(0.98);
}

.board-wrap {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 0;
  position: relative;
  z-index: 1;
}

.board {
  display: grid;
  gap: 4px;
  padding: 10px;
  border-radius: 18px;
  background: rgba(6, 10, 24, 0.7);
  border: 1px solid rgba(120, 160, 255, 0.2);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

.cell {
  width: var(--cell);
  height: var(--cell);
  border: 1px solid var(--grid);
  border-radius: 10px;
  background: rgba(10, 16, 35, 0.5);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.cell.corner {
  border-color: rgba(140, 200, 255, 0.55);
  box-shadow: inset 0 0 8px rgba(120, 200, 255, 0.3);
}

.cell.edge {
  border-color: rgba(140, 200, 255, 0.35);
}

.cell.valid-move {
  box-shadow: 0 0 0 2px rgba(140, 200, 255, 0.8);
  animation: pulse 1.6s ease-in-out infinite;
}

.cell:hover {
  transform: scale(1.03);
  box-shadow: 0 0 12px rgba(130, 190, 255, 0.4);
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(140, 200, 255, 0.5); }
  50% { box-shadow: 0 0 0 3px rgba(140, 200, 255, 0.9); }
}

.disc {
  width: 75%;
  height: 75%;
  border-radius: 50%;
  background: transparent;
  box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.35);
  transition: background 0.35s ease, box-shadow 0.35s ease;
}

.disc.black {
  background: radial-gradient(circle at 30% 30%, rgba(160, 200, 255, 0.45), #0a0f1b);
  box-shadow: 0 0 14px rgba(90, 150, 255, 0.6);
  animation: glow 2.6s ease-in-out infinite;
}

.disc.white {
  background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.9), rgba(180, 210, 255, 0.6));
  box-shadow: 0 0 14px rgba(170, 210, 255, 0.7);
  animation: glow 2.6s ease-in-out infinite reverse;
}

@keyframes glow {
  0%, 100% { transform: scale(1); opacity: 0.95; }
  50% { transform: scale(1.03); opacity: 1; }
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 20, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.overlay.fullscreen {
  align-items: stretch;
  justify-content: stretch;
}

.overlay-card {
  background: rgba(8, 12, 30, 0.95);
  border: 1px solid rgba(120, 160, 255, 0.3);
  border-radius: 20px;
  padding: 24px;
  text-align: center;
  max-width: 320px;
  width: 90%;
}

.overlay.fullscreen .overlay-card {
  width: 100%;
  height: 100%;
  max-width: none;
  border-radius: 0;
  padding: 28px 22px calc(env(safe-area-inset-bottom, 0px) + 24px);
  overflow-y: auto;
  text-align: left;
}

.overlay.fullscreen .overlay-text ul {
  padding-left: 18px;
  margin-top: 8px;
}

.overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.overlay-title {
  font-size: 1.4rem;
  margin-bottom: 10px;
}

.overlay-text {
  color: var(--muted);
  margin-bottom: 16px;
  line-height: 1.4;
}

.overlay-card-apps {
  max-width: 420px;
  width: min(92vw, 420px);
  max-height: min(78vh, 560px);
  text-align: left;
}

.overlay-scroll {
  max-height: min(50vh, 380px);
  overflow-y: auto;
  padding-right: 6px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.overlay-scroll::-webkit-scrollbar {
  width: 8px;
}

.overlay-scroll::-webkit-scrollbar-track {
  background: rgba(10, 18, 35, 0.35);
  border-radius: 999px;
}

.overlay-scroll::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, rgba(102, 198, 255, 0.9), rgba(159, 139, 255, 0.85));
  border-radius: 999px;
}

.overlay-card-apps .primary-btn {
  width: 100%;
  text-align: left;
}

.hidden {
  display: none !important;
}

body[data-difficulty="easy"] .board {
  border-color: rgba(120, 200, 255, 0.25);
}

body[data-difficulty="medium"] .board {
  border-color: rgba(160, 200, 255, 0.35);
}

body[data-difficulty="hard"] .board {
  border-color: rgba(200, 120, 255, 0.45);
  box-shadow: 0 20px 45px rgba(120, 100, 255, 0.35);
}

@media (max-width: 768px) {
  .title-row h1 {
    font-size: 1.6rem;
  }
  .controls {
    flex-direction: column;
    align-items: stretch;
  }
  .panel-bar {
    gap: 6px;
  }
  .control-group.compact {
    padding: 0;
  }
  .primary-btn.compact {
    margin-left: 0;
  }
}

@media (max-width: 560px) {
  .app {
    padding: 6px;
    gap: 6px;
  }
  .header {
    gap: 4px;
  }
  .subtitle {
    font-size: 0.72rem;
  }
  .status-row {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "turn score"
      "actions actions";
    align-items: center;
    gap: 6px;
  }
  .status-chip {
    grid-area: turn;
  }
  .score {
    grid-area: score;
    justify-content: flex-end;
  }
  .status-actions {
    grid-area: actions;
    justify-content: flex-start;
  }
  .status-chip {
    padding: 5px 8px;
    font-size: 0.8rem;
  }
  .status-actions {
    row-gap: 6px;
  }
  .subscribe-btn {
    flex-basis: 100%;
    justify-content: center;
    height: 34px;
    font-size: 0.8rem;
  }
  .score-item {
    padding: 3px 7px;
    font-size: 0.8rem;
  }
  .controls.panel-bar {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-auto-rows: auto;
    gap: 4px;
  }
  .size-group {
    grid-column: 1 / 2;
    grid-row: 1;
  }
  .primary-btn.compact {
    grid-column: 2 / 3;
    grid-row: 1;
    justify-self: end;
  }
  .difficulty-group {
    grid-column: 1 / -1;
    grid-row: 2;
  }
  .control-group.compact {
    flex-direction: row;
    align-items: center;
    gap: 4px;
    padding: 3px 5px;
    background: rgba(10, 18, 35, 0.4);
    border: 1px solid rgba(120, 160, 255, 0.12);
  }
  .control-title {
    font-size: 0.68rem;
    white-space: nowrap;
  }
  .control-options {
    gap: 4px;
    flex-wrap: nowrap;
  }
  .option-btn {
    padding: 4px 7px;
    font-size: 0.75rem;
  }
  .primary-btn.compact {
    flex: 0 0 auto;
    min-width: auto;
    padding: 6px 9px;
    font-size: 0.8rem;
  }
  .board-wrap {
    padding-bottom: 64px;
  }
}
