*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #0a1628 0%, #111 55%, #000 100%);
  color: #f0f0f0;
  margin: 0;
  padding: 16px;
  min-height: 100vh;
}

.wrapper {
  max-width: 900px;
  margin: 0 auto;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.back-link {
  color: #7ee8ff;
  text-decoration: none;
  font-size: 0.85rem;
  opacity: 0.9;
}

.back-link:hover {
  text-decoration: underline;
}

.lang-switch button {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #ccc;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
}

.lang-switch button.active {
  background: #00f5ff;
  color: #111;
  border-color: #00f5ff;
}

.container {
  display: flex;
  gap: 20px;
  background: rgba(40, 40, 40, 0.85);
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  flex-wrap: wrap;
  justify-content: center;
}

.game-info {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 200px;
  max-width: 240px;
}

h1 {
  margin: 0;
  color: #00f5ff;
  text-align: center;
  letter-spacing: 3px;
  font-size: 1.5rem;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.panel {
  background: #3a3a3a;
  padding: 10px;
  border-radius: 6px;
}

.panel-label {
  margin: 0 0 8px;
  font-size: 0.85rem;
  color: #aaa;
}

.panel p {
  margin: 4px 0;
  font-size: 0.9rem;
}

.mode-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.mode-btn {
  background: #2a2a2a;
  border: 1px solid #555;
  color: #ddd;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
}

.mode-btn.active {
  background: #00f5ff;
  color: #111;
  border-color: #00f5ff;
  font-weight: 600;
}

.mode-desc {
  margin: 8px 0 0;
  font-size: 0.75rem;
  color: #999;
  line-height: 1.4;
}

.streak-label {
  margin: 8px 0 0;
  font-size: 0.8rem;
  color: #ffe138;
  font-weight: 600;
  min-height: 1.2em;
}

.hidden {
  display: none !important;
}

.b2b-on {
  color: #ffe138;
  font-weight: bold;
}

.b2b-off {
  color: #666;
}

.combo-row span#combo {
  color: #0dff72;
  font-weight: bold;
}

.hold-piece canvas,
.next-piece canvas {
  display: block;
  margin: 4px auto 0;
  background: #111;
  border: 1px solid #444;
  border-radius: 4px;
}

.settings summary,
.achievements summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
}

.setting-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 0.85rem;
}

.setting-row select {
  margin-left: auto;
  background: #222;
  color: #fff;
  border: 1px solid #555;
  border-radius: 4px;
  padding: 4px;
}

.achievement-list {
  list-style: none;
  padding: 0;
  margin: 8px 0 0;
  font-size: 0.8rem;
}

.achievement-list li {
  padding: 4px 0;
  border-bottom: 1px solid #444;
}

.achievement-list li.unlocked {
  color: #0dff72;
}

.achievement-list li.locked {
  color: #666;
}

.controls {
  font-size: 0.75rem;
}

.controls p {
  margin: 3px 0;
  color: #bbb;
}

.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: auto;
}

#start-button {
  background: #00f5ff;
  border: none;
  padding: 12px;
  color: #111;
  font-weight: bold;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95rem;
}

#start-button:hover {
  background: #00cccc;
}

.secondary-btn {
  background: transparent;
  border: 1px solid #00f5ff;
  color: #00f5ff;
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}

.secondary-btn:hover {
  background: rgba(0, 245, 255, 0.1);
}

.play-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

#tetris {
  background: #111;
  border: 2px solid #444;
  border-radius: 4px;
  display: block;
  max-width: 100%;
  height: auto;
}

#tetris:focus {
  outline: 2px solid rgba(0, 245, 255, 0.5);
  outline-offset: 2px;
}

.float-layer {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 240px;
  height: 400px;
  pointer-events: none;
  overflow: hidden;
}

.float-text {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-weight: bold;
  font-size: 1.1rem;
  text-shadow: 0 0 8px rgba(0, 0, 0, 0.9);
  animation: floatUp 1.2s ease-out forwards;
  white-space: nowrap;
}

.float-text.tetris {
  font-size: 1.6rem;
  color: #ffe138;
}

.float-text.tspin {
  color: #f538ff;
}

.float-text.combo {
  color: #0dff72;
}

.float-text.b2b {
  color: #ff8e0d;
}

@keyframes floatUp {
  0% {
    opacity: 1;
    top: 45%;
  }
  100% {
    opacity: 0;
    top: 20%;
  }
}

.mobile-controls {
  display: none;
  margin-top: 12px;
  gap: 12px;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 320px;
}

.dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.dpad-row {
  display: flex;
  gap: 4px;
}

.ctrl-btn {
  width: 52px;
  height: 52px;
  background: rgba(0, 245, 255, 0.15);
  border: 1px solid rgba(0, 245, 255, 0.4);
  color: #00f5ff;
  border-radius: 8px;
  font-size: 1.2rem;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}

.ctrl-btn:active {
  background: rgba(0, 245, 255, 0.35);
}

.hard-btn {
  font-size: 1rem;
}

.hold-btn {
  font-size: 0.9rem;
  font-weight: bold;
}

.hint {
  margin-top: 12px;
  font-size: 0.8rem;
  color: #888;
  text-align: center;
  max-width: 280px;
  line-height: 1.4;
}

.achievement-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 200, 100, 0.95);
  color: #111;
  padding: 12px 20px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  z-index: 100;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  transition: opacity 0.3s;
}

.achievement-toast.hidden {
  opacity: 0;
  pointer-events: none;
}

.sidebar-drawer {
  width: 100%;
  max-width: 320px;
}

.drawer-summary {
  display: none;
}

@media (max-width: 720px) {
  .container {
    flex-direction: column;
    align-items: center;
    gap: 8px;
  }

  .sidebar-drawer {
    max-width: 100%;
    order: 2;
  }

  .play-area {
    order: 1;
    flex: 1;
    width: 100%;
  }

  .drawer-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    list-style: none;
    cursor: pointer;
    min-height: 44px;
    padding: 10px 14px;
    margin-bottom: 8px;
    border-radius: 10px;
    background: rgba(0, 245, 255, 0.08);
    border: 1px solid rgba(0, 245, 255, 0.25);
    color: #00f5ff;
    font-size: 0.9rem;
  }

  .drawer-summary::-webkit-details-marker {
    display: none;
  }

  .drawer-score {
    font-weight: 700;
    color: #fff;
  }

  .game-info {
    max-width: 100%;
    width: 100%;
    max-height: 42vh;
    overflow-y: auto;
  }

  #tetris {
    max-height: 52vh;
    width: auto;
    height: auto;
  }

  .mobile-controls {
    display: flex;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .mode-buttons {
    grid-template-columns: 1fr 1fr;
  }

  .controls.panel {
    display: none;
  }
}

@media (min-width: 721px) {
  .hint {
    max-width: 240px;
  }
}
