* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  touch-action: manipulation;
}

body {
  min-height: 100dvh;
  margin: 0;
  background: #0f1012;
  color: #fff;
  font-family: Arial, sans-serif;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 32px 20px 20px;
  overflow-x: hidden;
}

.app {
  width: 100%;
  max-width: 560px;
  background: #1c1d22;
  border-radius: 24px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  padding: 18px;
}

.topbar {
  display: grid;
  grid-template-columns: 100px 1fr 100px;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.topbar-centered {
  grid-template-columns: 100px 1fr 100px;
}

.topbar-spacer {
  width: 100%;
  min-height: 40px;
}

.topbar h1 {
  margin: 0;
  text-align: center;
  font-size: 28px;
  line-height: 1.1;
}

.nav-btn {
  appearance: none;
  border: none;
  text-decoration: none;
  background: #3a3b40;
  color: #fff;
  border-radius: 10px;
  min-height: 40px;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.stats-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin-bottom: 12px;
  font-size: 18px;
  font-weight: 700;
}

.stats-bar div:first-child {
  justify-self: start;
}

.stats-bar div:last-child {
  justify-self: end;
}

.share-btn {
  background: #538d4e;
}

.mode-panel {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.mode-option {
  background: #4a4b50;
}

.mode-option.active {
  background: #3f6db3;
}

.online-panel {
  background: #17181b;
  border: 1px solid #2d2f36;
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 14px;
}

.online-main-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.online-btn {
  background: #538d4e;
}

.join-open-btn {
  background: #44474f;
}

.created-room-box {
  margin-top: 12px;
  background: #2a2b30;
  border-radius: 12px;
  padding: 14px;
  text-align: center;
}

.created-room-title {
  font-size: 14px;
  font-weight: 700;
  opacity: 0.85;
  margin-bottom: 6px;
}

.created-room-code {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 4px;
  margin-bottom: 6px;
}

.created-room-subtext {
  font-size: 13px;
  opacity: 0.75;
  font-weight: 700;
}

.join-box {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.join-box input {
  width: 100%;
  border: none;
  outline: none;
  background: #2b2c31;
  color: #fff;
  border-radius: 10px;
  min-height: 40px;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
}

.game-wrap {
  display: flex;
  justify-content: center;
}

.game-wrap.hidden {
  display: none !important;
}

.board {
  width: 100%;
  max-width: 400px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  background: #0b0b0d;
  border: 4px solid #d7d7d7;
  border-radius: 8px;
  padding: 10px;
}

.cell {
  appearance: none;
  border: none;
  padding: 0;
  width: 100%;
  min-width: 0;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  background: #2b2c31;
  color: #fff;
  font-size: clamp(42px, 10vw, 72px);
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s ease, background 0.12s ease;
}

.cell:hover {
  background: #35363c;
  transform: translateY(-1px);
}

.cell:disabled {
  opacity: 1;
  cursor: default;
}

.cell.x {
  color: #ffffff;
}

.cell.o {
  color: #8df04f;
}

.cell.win {
  background: #538d4e;
  color: #fff;
}

.message {
  min-height: 24px;
  text-align: center;
  margin-top: 14px;
  font-size: 16px;
  font-weight: 700;
}

.copy-toast {
  position: fixed;
  top: 18px;
  right: 18px;
  background: #2f2f31;
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  border: 1px solid #4a4a4d;
  z-index: 999;
}

.hidden {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 2000;
}

.modal-card {
  width: 100%;
  max-width: 420px;
  background: #1c1d22;
  border-radius: 20px;
  padding: 22px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  border: 1px solid #2d2f36;
  text-align: center;
}

.modal-title {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 10px;
}

.modal-text {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 18px;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.single-modal-action {
  display: flex;
  justify-content: center;
}

.single-modal-action .nav-btn {
  min-width: 180px;
}

.modal-yes {
  background: #538d4e;
}

.modal-no {
  background: #b34747;
}

.modal-waiting {
  margin-top: 16px;
  font-size: 16px;
  font-weight: 700;
}

@media (max-width: 600px) {
  html,
  body {
    overflow-x: hidden;
  }

  body {
    min-height: 100dvh;
    padding: 22px 12px 12px;
    align-items: flex-start;
    overflow-y: auto;
  }

  .app {
    padding: 14px;
    border-radius: 20px;
  }

.topbar {
  grid-template-columns: 78px 1fr 78px;
  gap: 8px;
  margin-bottom: 8px;
}

.topbar-centered {
  grid-template-columns: 78px 1fr 78px;
}

.topbar-spacer {
  min-height: 36px;
}

  .topbar h1 {
    font-size: 20px;
  }

  .nav-btn {
    min-height: 36px;
    font-size: 12px;
    padding: 8px 10px;
  }

  .stats-bar {
    font-size: 15px;
    gap: 8px;
    margin-bottom: 10px;
  }

  .mode-panel {
    gap: 8px;
  }

  .online-main-actions {
    grid-template-columns: 1fr;
  }

  .join-box {
    grid-template-columns: 1fr;
  }

  .created-room-code {
    font-size: 24px;
    letter-spacing: 3px;
  }

  .board {
    gap: 8px;
    padding: 8px;
  }

  .cell {
    font-size: clamp(36px, 12vw, 56px);
    border-radius: 10px;
  }

  .message {
    font-size: 14px;
  }

  .copy-toast {
    top: 12px;
    right: 12px;
    font-size: 13px;
    padding: 8px 10px;
  }

  .modal-card {
    padding: 18px;
    border-radius: 16px;
  }

  .modal-title {
    font-size: 22px;
  }

  .modal-text {
    font-size: 16px;
  }

  .modal-waiting {
    font-size: 14px;
  }
}