* {
  box-sizing: border-box;
}

html, body {
  min-height: 100%;
  overscroll-behavior: none;
}

body {
  margin: 0;
  min-height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 16px;
  background: #10131a;
  color: #eaeaea;
  font-family: "Segoe UI", "Hiragino Kaku Gothic ProN", sans-serif;
}

h1 {
  margin: 4px 0 0;
  font-size: 1.4rem;
  letter-spacing: 0.05em;
}

.home-layout {
  width: min(1120px, 100%);
  display: grid;
  grid-template-columns: minmax(250px, 0.82fr) minmax(0, 1.18fr);
  gap: 16px;
  align-items: start;
}

.home-layout.game-active {
  display: block;
  width: min(520px, 100%);
}

.panel,
.practice-panel {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid #30384d;
  border-radius: 10px;
  background: #1c2130;
  text-align: center;
}

.lobby-panel {
  position: relative;
  overflow: hidden;
}

.lobby-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lobby-card {
  min-width: 0;
  min-height: 92px;
  padding: 12px;
  border: 1px solid #30384d;
  border-radius: 8px;
  background: #171c2a;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  position: relative;
  z-index: 1;
  transition: transform 360ms cubic-bezier(0.22, 0.61, 0.36, 1),
    opacity 260ms ease;
}

.lobby-panel.private-open .lobby-card {
  transform: translateX(-115%);
  opacity: 0;
  pointer-events: none;
}

.lobby-panel.private-open .lobby-card:nth-child(1) { transition-delay: 0ms; }
.lobby-panel.private-open .lobby-card:nth-child(2) { transition-delay: 35ms; }
.lobby-panel.private-open .lobby-card:nth-child(3) { transition-delay: 70ms; }
.lobby-panel.private-open .lobby-card:nth-child(4) { transition-delay: 105ms; }
.lobby-panel.private-open .lobby-card:nth-child(5) { transition-delay: 140ms; }

.empty-card {
  min-height: 72px;
}

.practice-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.home-layout.game-active .practice-panel {
  width: min(520px, 100%);
  margin: 0 auto;
  padding: 0;
  border: 0;
  background: transparent;
}

.home-layout.game-active .practice-heading {
  display: none;
}

.practice-heading h2 {
  margin: 0;
  font-size: 1.1rem;
}

.practice-heading p {
  margin: 3px 0 0;
  font-size: 0.82rem;
  opacity: 0.75;
}

.lobby-card h2 {
  margin: 0;
  font-size: 1rem;
}

.lobby-card p {
  margin: 0;
  font-size: 0.82rem;
  opacity: 0.75;
}

.online-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.private-match-panel {
  position: absolute;
  z-index: 4;
  inset: 12px 16px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  padding: 20px;
  border: 1px solid #3e8cff;
  border-radius: 8px;
  background: #171c2a;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateX(-112%);
  transition: transform 360ms cubic-bezier(0.22, 0.61, 0.36, 1),
    opacity 240ms ease, visibility 0s linear 360ms;
}

.private-match-panel.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateX(0);
  transition-delay: 0s;
}

.private-match-panel.is-closing {
  opacity: 0;
  visibility: visible;
  pointer-events: none;
  transform: translateX(-112%);
  transition-delay: 0s;
}

/* Quick-match waiting uses the opposite entry direction from the private room panel. */
.quick-match-panel {
  transform: translateX(112%);
}

.quick-match-panel.is-closing {
  transform: translateX(112%);
}

.quick-match-panel .secondary-button {
  align-self: center;
  background: #4a536b;
}

.quick-match-panel .secondary-button:hover {
  background: #5d6985;
}

.private-match-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.private-match-panel h3 {
  margin: 0;
  font-size: 0.9rem;
  font-weight: normal;
  opacity: 0.8;
}

.private-match-header .secondary-button {
  background: #4a536b;
}

.private-match-header .secondary-button:hover {
  background: #5d6985;
}

.join-line { display: inline-flex; gap: 0; }
.join-line input { border-radius: 6px 0 0 6px; }
.join-line button { border-radius: 0 6px 6px 0; }
.local-card button { min-width: 150px; }
.cpu-level-buttons { display: inline-flex; }
.cpu-level-button {
  min-width: 34px;
  padding: 6px 10px;
  border-radius: 0;
  background: #4a536b;
}
.cpu-level-button:first-child { border-radius: 6px 0 0 6px; }
.cpu-level-button:last-child { border-radius: 0 6px 6px 0; }
.cpu-level-button.active { background: #3e8cff; }

button, input {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  font: inherit;
}

button {
  padding: 6px 12px;
  background: #3e8cff;
  color: white;
  cursor: pointer;
  font-weight: bold;
}

button:hover { background: #5b9eff; }
button:disabled { opacity: 0.5; cursor: default; }
input {
  width: 100px;
  padding: 6px 8px;
  background: #0c1420;
  color: #fff;
  border: 1px solid #3a4256;
  text-transform: uppercase;
}

.status { margin-top: 8px; font-size: 0.8rem; opacity: 0.75; }
.status.error { color: #ff8b96; opacity: 1; }
.room-hint { margin-top: 4px; color: #89c5ff; font-size: 0.9rem; font-weight: bold; }
.hidden { display: none !important; }

.scoreboard {
  display: flex;
  gap: 40px;
}

.score-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 140px;
  padding: 8px 16px;
  border-radius: 10px;
  background: #1c2130;
}

.score-box.you { border-bottom: 4px solid #55aaff; }
.score-box.opponent { border-bottom: 4px solid #ff5566; }

.score-box .label {
  font-size: 0.8rem;
  opacity: 0.75;
}

.score-box .score {
  font-size: 2rem;
  font-weight: bold;
}

canvas {
  display: block;
  flex: 0 0 auto;
  width: min(500px, 100%);
  height: auto;
  max-width: 100%;
  background: #0c1420;
  border: 3px solid #3a4256;
  border-radius: 12px;
  box-shadow: 0 0 30px rgba(0, 150, 255, 0.15);
  touch-action: none;
}

.info {
  font-size: 0.9rem;
  opacity: 0.8;
  text-align: center;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(0, 0, 0, 0.55);
  font-size: 1.6rem;
  font-weight: bold;
  text-align: center;
  padding: 20px;
}

.overlay.hidden {
  display: none;
}

.overlay-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  min-height: 38px;
}

.overlay-action {
  font-size: 1rem;
}

.overlay-action.secondary { background: #4a536b; }
.overlay-action.secondary:hover { background: #5d6985; }

small { font-size: 0.95rem; font-weight: normal; opacity: 0.85; }

.match-intro {
  position: fixed;
  z-index: 15;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 28px 16px;
  pointer-events: none;
  background: radial-gradient(circle at center, rgba(62, 140, 255, 0.12), rgba(0, 0, 0, 0.22));
  animation: match-intro-fade-in 420ms ease both;
}

.match-intro-content {
  position: relative;
  width: min(520px, 100%);
  height: min(620px, calc(100dvh - 56px));
  display: flex;
  justify-content: center;
}

.match-intro-names {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 12px;
  color: #ffffff;
  font-size: clamp(1rem, 3vw, 1.35rem);
  font-weight: bold;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.65);
}

.match-intro-vs {
  position: absolute;
  top: 50%;
  left: 50%;
  color: #ffffff;
  font-size: clamp(2.4rem, 8vw, 4.2rem);
  letter-spacing: 0.08em;
  text-shadow: 0 4px 16px rgba(0, 0, 0, 0.75);
  transform: translate(-50%, -50%);
}

.match-intro.hidden {
  display: none;
}

.home-layout.match-transition .practice-panel {
  animation: match-field-arrive 3000ms cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

@keyframes match-field-arrive {
  from {
    opacity: 0.35;
    transform: translateX(46vw) scale(0.96);
  }
  62% {
    opacity: 1;
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

@keyframes match-intro-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .lobby-card,
  .private-match-panel {
    transition-duration: 1ms;
  }

  .home-layout.match-transition .practice-panel {
    animation-duration: 1ms;
  }
}

@media (max-height: 850px) {
  body { padding: 8px; gap: 6px; }
  h1 { font-size: 1.1rem; margin-top: 0; }
  .panel { padding: 8px 12px; }
  .practice-panel { padding: 8px 12px; }
  .lobby-card { min-height: 82px; padding: 8px; gap: 5px; }
  .empty-card { min-height: 64px; }
  .lobby-card h2 { font-size: 0.9rem; }
  .info { font-size: 0.75rem; }
}

@media (max-height: 650px) {
  body { padding: 5px; gap: 4px; }
  h1 { font-size: 0.95rem; }
  .scoreboard { gap: 12px; }
  .score-box { min-width: 108px; padding: 4px 10px; }
  .score-box .score { font-size: 1.45rem; }
  .info { font-size: 0.68rem; }
}

@media (max-width: 760px) {
  .home-layout { grid-template-columns: 1fr; }
  .lobby-card { min-height: 0; }
}
