body {
  background: #1a1a2e;
  color: #e0e0e0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
}

#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px 6px;
}

#logo {
  width: 32px;
  height: 32px;
}

#app-title {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: #888;
  text-transform: uppercase;
}

#scramble-bar {
  padding: 12px 16px;
  text-align: center;
  font-family: monospace;
  font-size: 1.4rem;
  min-height: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

#scramble-text {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px;
}

.scramble-move {
  display: inline-block;
  width: 2.2ch;
  text-align: center;
}

.btn-ghost {
  background: none;
  border: 1px solid #444;
  color: #888;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
}

.btn-ghost:hover { color: #fff; border-color: #666; }

#session-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  padding: 4px 16px;
  font-size: 0.85rem;
  color: #888;
}

#session-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

#session-select {
  background: #222;
  color: #e0e0e0;
  border: 1px solid #444;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.85rem;
  cursor: pointer;
}

.btn-ghost-sm {
  padding: 4px 10px;
  font-size: 0.75rem;
  border-color: #555;
}

#session-today {
  color: #666;
  font-size: 0.8rem;
}

#timer-area {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#timer-display {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: monospace;
  font-size: clamp(4rem, 15vw, 8rem);
  user-select: none;
  touch-action: none;
  cursor: pointer;
}

#vs-best {
  text-align: center;
  font-family: monospace;
  font-size: 1.1rem;
  min-height: 1.4em;
  margin-top: -4px;
}

#hint {
  color: #555;
  font-size: 0.8rem;
  text-align: center;
  margin-top: 8px;
}

#speed-chart-container {
  padding: 8px 12px;
  height: 140px;
  position: relative;
}

#stats-panel {
  display: flex;
  flex-direction: column;
  max-height: 55vh;
  overflow: hidden;
}

#stats-row {
  display: flex;
  justify-content: space-around;
  padding: 12px 0;
  border-bottom: 1px solid #333;
}

.stat { text-align: center; }
.stat-label { display: block; font-size: 0.75rem; color: #888; text-transform: uppercase; }
.stat-value { display: block; font-size: 1.2rem; font-family: monospace; margin-top: 4px; }

#history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  font-size: 0.85rem;
  color: #888;
}

#history-actions {
  display: flex;
  gap: 6px;
}

#clear-all-btn:hover { color: #ff5252; border-color: #ff5252; }

#history-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px;
}

.history-row {
  display: flex;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #222;
  font-size: 0.9rem;
}

.history-num { width: 40px; color: #666; }
.history-time { width: 80px; font-family: monospace; font-weight: bold; }
.history-scramble { flex: 1; font-family: monospace; font-size: 0.75rem; color: #666; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-left: 12px; }

.history-delta {
  width: 70px;
  font-family: monospace;
  font-size: 0.8rem;
  text-align: right;
}
.delta-positive { color: #ff5252; }
.delta-negative { color: #00e676; }
.delta-neutral { color: #888; }
.delta-best { color: #ffd700; }

.history-date-header {
  padding: 8px 0 4px;
  font-size: 0.75rem;
  color: #555;
  border-bottom: 1px solid #2a2a2a;
  margin-top: 4px;
}

.history-header-row {
  display: flex;
  align-items: center;
  padding: 4px 0;
  font-size: 0.7rem;
  color: #555;
  text-transform: uppercase;
  border-bottom: 1px solid #333;
}

.history-header-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-delete {
  background: none;
  border: none;
  color: #555;
  cursor: pointer;
  font-size: 1rem;
  padding: 4px 8px;
}

.history-delete:hover { color: #ff5252; }

/* Cube Side Panel */
.cube-panel {
  position: fixed;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 50;
  display: flex;
  align-items: center;
  transition: right 0.3s ease;
}

.cube-panel.collapsed {
  right: -200px;
}

.cube-toggle {
  background: #1e1e3a;
  border: 1px solid #444;
  border-right: none;
  color: #888;
  padding: 12px 6px;
  border-radius: 6px 0 0 6px;
  cursor: pointer;
  font-size: 0.7rem;
  line-height: 1;
  flex-shrink: 0;
}

.cube-toggle:hover { color: #fff; border-color: #666; }

.cube-panel-inner {
  background: #1e1e3a;
  border: 1px solid #444;
  border-radius: 8px;
  padding: 28px;
  overflow: hidden;
}

/* 3D Cube */
.cube-scene {
  width: 130px;
  height: 130px;
  perspective: 600px;
  cursor: grab;
}

.cube-scene:active { cursor: grabbing; }

.cube {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transform: rotateX(-25deg) rotateY(-35deg);
  transition: none;
}

.cube-face {
  position: absolute;
  width: 130px;
  height: 130px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 3px;
  padding: 3px;
  box-sizing: border-box;
  backface-visibility: hidden;
}

.cube-face--U { transform: rotateX(90deg) translateZ(65px); }
.cube-face--D { transform: rotateX(-90deg) translateZ(65px); }
.cube-face--F { transform: translateZ(65px); }
.cube-face--B { transform: rotateY(180deg) translateZ(65px); }
.cube-face--R { transform: rotateY(90deg) translateZ(65px); }
.cube-face--L { transform: rotateY(-90deg) translateZ(65px); }

.sticker {
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.4);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: #1e1e3a;
  border: 1px solid #444;
  border-radius: 12px;
  padding: 24px;
  min-width: 320px;
  max-width: 400px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  font-size: 1.1rem;
  font-weight: 600;
}

.modal-close {
  font-size: 1.4rem;
  border: none;
  padding: 4px 8px;
}

.mp-input {
  background: #222;
  color: #e0e0e0;
  border: 1px solid #444;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 1rem;
  width: 100%;
  box-sizing: border-box;
}

.mp-input::placeholder { color: #666; }

.mp-actions {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.mp-or {
  color: #666;
  font-size: 0.85rem;
}

.mp-join-row {
  display: flex;
  gap: 8px;
  width: 100%;
}

.mp-join-row .mp-input {
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-family: monospace;
  font-size: 1.1rem;
  text-align: center;
}

.btn-primary {
  background: #4a4aff;
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  width: 100%;
}

.btn-primary:hover { background: #5a5aff; }

.mp-error {
  color: #ff5252;
  font-size: 0.85rem;
  margin-top: 8px;
  min-height: 1.2em;
}

.mp-code-display {
  font-family: monospace;
  font-size: 2.5rem;
  letter-spacing: 0.3em;
  text-align: center;
  color: #fff;
  padding: 16px;
}

.mp-share-hint {
  color: #666;
  font-size: 0.8rem;
  text-align: center;
}

/* Split Timer Layout */
#split-timer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  width: 100%;
}

.split-player {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.split-divider {
  width: 1px;
  height: 120px;
  background: #333;
}

.split-name {
  font-size: 0.9rem;
  color: #888;
  margin-bottom: 8px;
  font-weight: 500;
}

.split-display {
  font-family: monospace;
  font-size: clamp(2rem, 8vw, 4rem);
  user-select: none;
}

.split-status {
  font-size: 0.8rem;
  color: #666;
  margin-top: 4px;
  min-height: 1.2em;
}

/* Countdown Overlay */
#countdown-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

#countdown-text {
  font-family: monospace;
  font-size: clamp(5rem, 20vw, 12rem);
  font-weight: 700;
  color: #ffd700;
  text-shadow: 0 0 40px rgba(255, 215, 0, 0.4);
}

/* Split Stats */
.split-stats {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  min-height: 1.4em;
}

.split-stat {
  text-align: center;
}

.split-stat-label {
  display: block;
  font-size: 0.65rem;
  color: #666;
  text-transform: uppercase;
}

.split-stat-value {
  display: block;
  font-size: 0.85rem;
  font-family: monospace;
  color: #bbb;
  margin-top: 2px;
}

/* Multiplayer History */
#mp-history-panel {
  max-width: 500px;
  width: 100%;
  margin: 0 auto;
  max-height: 40vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#mp-history-header {
  display: flex;
  padding: 8px 12px;
  font-size: 0.7rem;
  color: #555;
  text-transform: uppercase;
  border-bottom: 1px solid #333;
}

#mp-history-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px;
}

.mp-history-row {
  display: flex;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid #222;
  font-size: 0.9rem;
}

.mp-history-num {
  width: 32px;
  color: #555;
  font-size: 0.8rem;
}

.mp-history-time {
  flex: 1;
  font-family: monospace;
  font-weight: 500;
  text-align: center;
}

.mp-history-time.winner {
  color: #00e676;
}

.mp-history-time.loser {
  color: #888;
}

.mp-history-vs {
  width: 24px;
  text-align: center;
  color: #444;
  font-size: 0.75rem;
}

.mp-history-header-name {
  flex: 1;
  text-align: center;
}

@media (max-width: 500px) {
  #split-timer {
    flex-direction: column;
  }
  .split-divider {
    width: 80%;
    height: 1px;
    margin: 12px 0;
  }
}

/* === Auth UI === */

#header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

#header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.85rem;
  width: auto;
}

/* Auth user menu */
#auth-user-menu {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #2a2a4a;
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  position: relative;
  font-size: 0.9rem;
}

#auth-user-name {
  color: #e0e0e0;
}

.auth-caret {
  color: #666;
  font-size: 0.7rem;
}

.auth-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: #1e1e3a;
  border: 1px solid #444;
  border-radius: 6px;
  min-width: 120px;
  z-index: 110;
  overflow: hidden;
}

.auth-dropdown.visible {
  display: block;
}

.auth-dropdown-item {
  display: block;
  width: 100%;
  padding: 10px 16px;
  background: none;
  border: none;
  color: #e0e0e0;
  font-size: 0.85rem;
  cursor: pointer;
  text-align: left;
}

.auth-dropdown-item:hover {
  background: #2a2a4a;
}

/* Auth modal */
.auth-modal {
  min-width: 340px;
  max-width: 380px;
}

.auth-tabs {
  display: flex;
  gap: 0;
}

.auth-tab {
  background: none;
  border: none;
  color: #666;
  padding: 8px 20px;
  font-size: 0.95rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.auth-tab.active {
  color: #ffd700;
  border-bottom-color: #ffd700;
}

.auth-tab:hover {
  color: #aaa;
}

.auth-field {
  margin-bottom: 14px;
}

.auth-label {
  display: block;
  color: #aaa;
  font-size: 0.8rem;
  margin-bottom: 6px;
}

.auth-forgot {
  text-align: center;
  margin-top: 10px;
}

.btn-link {
  background: none;
  border: none;
  color: #666;
  font-size: 0.8rem;
  cursor: pointer;
}

.btn-link:hover {
  color: #aaa;
}

/* Mode Selector */
.mode-selector-options {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
}

.mode-option {
  flex: 1;
  background: #2a2a4a;
  border: 2px solid #444;
  border-radius: 10px;
  padding: 20px 16px;
  text-align: center;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: border-color 0.2s;
}

.mode-option:hover {
  border-color: #7c4dff;
}

.mode-option--local:hover {
  border-color: #ffd700;
}

.mode-icon {
  font-size: 1.6rem;
}

.mode-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: #e0e0e0;
}

.mode-option:hover .mode-title {
  color: #7c4dff;
}

.mode-option--local:hover .mode-title {
  color: #ffd700;
}

.mode-desc {
  font-size: 0.75rem;
  color: #666;
}

.mode-note {
  text-align: center;
  color: #555;
  font-size: 0.8rem;
}
