* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  background: radial-gradient(ellipse at 30% 40%, #0b0f1c, #020308);
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  color: #ffffff;
}

.app-wrapper {
  width: 100%;
  max-width: 1100px;
  height: auto;
  max-height: 96vh;
  background: rgba(8, 12, 24, 0.55);
  backdrop-filter: blur(14px);
  border-radius: 24px;
  border: 1px solid rgba(66, 140, 255, 0.25);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  padding: 12px 16px;
  overflow-y: auto;
}

.game-container {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 16px;
  align-items: start;
}

.game-main {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.score-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 40px;
  padding: 6px 12px;
  backdrop-filter: blur(8px);
  flex-wrap: nowrap;
}

.score-card {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(18, 25, 45, 0.7);
  border-radius: 32px;
  padding: 4px 12px;
  border: 1px solid rgba(77, 166, 255, 0.25);
  flex: 1;
  justify-content: center;
}

.score-card img {
  width: 20px;
  height: 20px;
}

.score-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.score-label {
  font-size: 9px;
  letter-spacing: 0.8px;
  font-weight: 500;
  opacity: 0.8;
}

.score-value {
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
  color: #3c8eff;
}

.action-group {
  display: flex;
  gap: 6px;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 28px;
  padding: 5px 10px;
  font-weight: 500;
  font-size: 11px;
  cursor: pointer;
  transition: 0.2s;
  color: #ffffff;
  backdrop-filter: blur(4px);
}

.icon-btn:hover {
  background: #2b7aff20;
  border-color: #2b7aff;
  transform: translateY(-1px);
}

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  aspect-ratio: 1 / 1;
  max-width: 380px;
  width: 100%;
  margin: 0 auto;
  gap: 8px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 24px;
  padding: 10px;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5), 0 4px 12px black;
}

.cell {
  background: linear-gradient(145deg, #101624, #070a14);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.12s ease;
  border: 1px solid rgba(77, 166, 255, 0.15);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
  color: #ffffff;
}

.cell.x {
  color: #ff4d6d;
  text-shadow: 0 0 6px #ff4d6d80;
}

.cell.o {
  color: #3c8eff;
  text-shadow: 0 0 6px #3c8eff80;
}

.cell:hover {
  transform: scale(1.02);
  background: #1f2a44;
  border-color: #3c8eff;
}

.cell.win {
  background: radial-gradient(circle, #2b7aff30, #0f1424);
  box-shadow: 0 0 14px #2b7aff, inset 0 0 3px #ffffff30;
  border-color: #3c8eff;
}

.status-bar {
  display: flex;
  justify-content: space-between;
  padding: 6px 12px;
  font-size: 11px;
  font-weight: 500;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 28px;
  width: 100%;
  max-width: 380px;
  margin: 0 auto;
}

.control-sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel {
  background: rgba(12, 16, 28, 0.7);
  backdrop-filter: blur(12px);
  border-radius: 20px;
  padding: 10px 12px;
  border: 1px solid rgba(66, 140, 255, 0.2);
}

.panel h3 {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 8px;
  letter-spacing: -0.2px;
}

.train-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.train-btn {
  background: linear-gradient(135deg, #1a253f, #0c1122);
  border: none;
  border-radius: 24px;
  padding: 5px 10px;
  font-weight: 600;
  font-size: 10px;
  cursor: pointer;
  transition: 0.2s;
  color: white;
  box-shadow: 0 1px 3px black;
}

.train-btn:hover {
  background: #2b7aff;
  transform: translateY(-1px);
}

.stop-btn {
  background: #aa2e4e;
}

.stop-btn:hover {
  background: #ff3366;
}

.progress-wrapper {
  height: 4px;
  background: #1e243b;
  border-radius: 3px;
  overflow: hidden;
  margin: 6px 0;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #3c8eff, #9bc6ff);
  transition: width 0.1s linear;
}

.stats-row {
  display: flex;
  justify-content: space-between;
  margin: 6px 0 4px;
  font-weight: 700;
  font-size: 10px;
}

.data-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.sec-btn {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 24px;
  padding: 3px 7px;
  font-size: 9px;
  font-weight: 500;
  cursor: pointer;
  transition: 0.2s;
  color: #ffffff;
}

.sec-btn:hover {
  background: #2b7aff20;
  border-color: #2b7aff;
}

.param {
  margin: 8px 0;
}

.param label {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  margin-bottom: 3px;
}

input[type="range"] {
  width: 100%;
  background: #232a44;
  height: 4px;
  border-radius: 3px;
  -webkit-appearance: none;
}

input[type="range"]:focus {
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #3c8eff;
  cursor: pointer;
  box-shadow: 0 0 2px white;
}

.checkbox {
  margin-top: 6px;
  font-size: 10px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.info-text {
  font-size: 10px;
  opacity: 0.85;
  margin: 6px 0;
  line-height: 1.4;
}

.social-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 6px 0 4px;
}

.social-row img {
  width: 16px;
  height: 16px;
  opacity: 0.7;
  transition: 0.2s;
}

.social-row img:hover {
  opacity: 1;
  transform: translateY(-2px);
}

.legal-links {
  text-align: center;
  font-size: 8px;
  margin-top: 5px;
}

.legal-links a {
  color: #3c8eff;
  text-decoration: none;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(20px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal.active {
  display: flex;
}

.modal-card {
  background: #0f1422;
  border-radius: 24px;
  width: min(400px, 85vw);
  padding: 16px;
  text-align: center;
  border: 1px solid #2b7aff;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-card h2,
.modal-card h3 {
  color: #ffffff;
  margin-bottom: 8px;
  font-size: 16px;
}

.modal-card p,
.modal-card li {
  color: #dddddd;
  font-size: 11px;
  line-height: 1.5;
}

.modal-card ul {
  padding-left: 16px;
  margin: 6px 0;
}

.modal-card a {
  color: #3c8eff;
  text-decoration: none;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 12px;
}

canvas {
  position: fixed;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 99;
}

@media (min-width: 901px) {
  .app-wrapper {
    padding: 16px 20px;
  }

  .board {
    max-width: 420px;
  }

  .cell {
    font-size: 42px;
  }
}

@media (max-width: 900px) and (orientation: landscape) {
  .app-wrapper {
    padding: 10px 12px;
    max-height: 98vh;
  }

  .game-container {
    grid-template-columns: 1fr 240px;
    gap: 12px;
  }

  .board {
    max-width: 320px;
    padding: 8px;
  }

  .cell {
    font-size: 32px;
  }

  .score-value {
    font-size: 18px;
  }

  .panel {
    padding: 8px 10px;
  }
}

@media (max-width: 600px) and (orientation: portrait) {
  body {
    padding: 6px;
    overflow: auto;
  }

  .app-wrapper {
    max-height: none;
    height: auto;
    padding: 10px 12px;
    overflow: visible;
  }

  .game-container {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .control-sidebar {
    order: 2;
  }

  .game-main {
    order: 1;
  }

  .score-header {
    padding: 5px 10px;
    flex-wrap: wrap;
  }

  .score-card {
    padding: 3px 10px;
  }

  .score-card img {
    width: 18px;
    height: 18px;
  }

  .score-value {
    font-size: 16px;
  }

  .score-label {
    font-size: 8px;
  }

  .action-group {
    width: 100%;
    justify-content: center;
  }

  .board {
    max-width: 300px;
    padding: 8px;
    gap: 7px;
  }

  .cell {
    font-size: 32px;
    border-radius: 14px;
  }

  .status-bar {
    max-width: 300px;
    padding: 5px 10px;
    font-size: 10px;
  }

  .panel {
    padding: 10px 12px;
  }

  .panel h3 {
    font-size: 11px;
  }

  .train-buttons {
    gap: 5px;
  }

  .train-btn {
    padding: 4px 8px;
    font-size: 9px;
  }

  .progress-wrapper {
    height: 3px;
    margin: 5px 0;
  }

  .stats-row {
    font-size: 9px;
    margin: 5px 0;
  }

  .data-actions {
    gap: 5px;
  }

  .sec-btn {
    padding: 3px 6px;
    font-size: 8px;
  }

  .param {
    margin: 6px 0;
  }

  .param label {
    font-size: 9px;
  }

  input[type="range"] {
    height: 3px;
  }

  input[type="range"]::-webkit-slider-thumb {
    width: 10px;
    height: 10px;
  }

  .checkbox {
    font-size: 9px;
  }

  .info-text {
    font-size: 9px;
    margin: 5px 0;
  }
}

@media (max-width: 400px) and (orientation: portrait) {
  .board {
    max-width: 260px;
    padding: 6px;
    gap: 6px;
  }

  .cell {
    font-size: 28px;
  }

  .status-bar {
    max-width: 260px;
    font-size: 9px;
  }

  .score-value {
    font-size: 14px;
  }

  .score-card img {
    width: 16px;
    height: 16px;
  }

  .icon-btn {
    padding: 4px 8px;
    font-size: 10px;
  }
}

@media (max-width: 350px) {
  .board {
    max-width: 240px;
    padding: 5px;
    gap: 5px;
  }

  .cell {
    font-size: 26px;
  }

  .status-bar {
    max-width: 240px;
    font-size: 8px;
  }
}