* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', 'Hiragino Sans', sans-serif;
  background: #1a1a2e;
  color: #eee;
}

#app {
  display: flex;
  height: 100%;
  width: 100%;
}

/* Left panel - Luanti WASM */
#left-panel {
  flex: 1;
  min-width: 200px;
  position: relative;
  background: #000;
}

#left-panel iframe {
  width: 100%;
  height: 100%;
  border: none;
}

#luanti-overlay {
  position: absolute;
  inset: 0;
  z-index: 15;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
}

#luanti-overlay.hidden {
  display: none;
}

#btn-play {
  padding: 14px 28px;
  font-size: 18px;
  border: 2px solid #00d4ff;
  border-radius: 10px;
  background: rgba(15, 52, 96, 0.85);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

#btn-play:hover {
  background: rgba(0, 212, 255, 0.3);
  transform: scale(1.05);
}

/* Divider */
.divider {
  width: 8px;
  background: #0f3460;
  cursor: col-resize;
  flex-shrink: 0;
  transition: background 0.15s;
  position: relative;
  z-index: 30;
}

.divider:hover,
.divider.dragging {
  background: #00d4ff;
}

/* Grab zone inside left panel to prevent iframe from stealing events near divider */
#left-panel-grab {
  position: absolute;
  top: 0;
  right: 0;
  width: 12px;
  height: 100%;
  cursor: col-resize;
  z-index: 25;
}

/* Center panel — hidden by default (Luanti fullscreen) */
#center-panel {
  display: none;
  flex-direction: column;
  background: #16213e;
  position: relative;
  overflow: hidden;
}

/* Divider — hidden by default */
#divider-left {
  display: none;
}

/* Layout: code mode (Luanti 65% / Blockly 35%) */
.layout-code #left-panel {
  flex: 65 1 0%;
}
.layout-code #divider-left {
  display: block;
}
.layout-code #center-panel {
  display: flex;
  flex: 35 1 0%;
  min-width: 200px;
}

/* Layout: content mode (Luanti 60% / Content 40%) */
.layout-content #left-panel {
  flex: 60 1 0%;
}
.layout-content #center-panel {
  display: flex;
  flex: 40 1 0%;
  min-width: 200px;
}

.center-view {
  display: none;
  position: absolute;
  inset: 0;
  flex-direction: column;
}

.center-view.active {
  display: flex;
}

.center-view iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.placeholder-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 12px;
  color: #667;
}

.placeholder-content h2 {
  font-size: 20px;
  color: #556;
}

.placeholder-content p {
  font-size: 14px;
}

/* Right menu */
#right-menu {
  width: 44px;
  flex-shrink: 0;
  background: #0d1117;
  border-left: 1px solid #1a2332;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0;
  gap: 4px;
}

.menu-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: #8899aa;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: background 0.15s, color 0.15s;
}

.menu-btn:hover {
  background: #1a2332;
  color: #ccc;
}

.menu-btn.active {
  background: #0f3460;
  color: #00d4ff;
}

.menu-spacer {
  flex: 1;
}

/* Tooltip */
.tooltip {
  display: none;
  position: absolute;
  right: 48px;
  top: 50%;
  transform: translateY(-50%);
  background: #222;
  color: #eee;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 13px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 100;
  border: 1px solid #333;
  line-height: 1.3;
}

.tt-ruby {
  display: block;
  font-size: 9px;
  opacity: 0.6;
  letter-spacing: 0.5px;
}

.menu-btn:hover .tooltip {
  display: block;
}

/* Blockly tab bar */
.blockly-tabs {
  display: flex;
  height: 32px;
  background: #0d1117;
  border-bottom: 1px solid #1a2332;
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: #667;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.tab-btn:hover {
  background: #1a2332;
  color: #ccc;
}

.tab-btn.active {
  background: #0f3460;
  color: #00d4ff;
}

/* Drag overlay to prevent iframe event capture */
.drag-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  cursor: col-resize;
}

/* Result overlay */
.result-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease;
}

.result-overlay.hidden {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes popIn {
  from { transform: scale(0.7); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes starPop {
  0% { transform: scale(0) rotate(-30deg); opacity: 0; }
  60% { transform: scale(1.3) rotate(5deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

.result-card {
  background: linear-gradient(135deg, #16213e, #1a1a2e);
  border: 2px solid #0f3460;
  border-radius: 16px;
  padding: 32px 40px;
  text-align: center;
  min-width: 280px;
  max-width: 400px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  animation: popIn 0.4s ease;
}

.result-title {
  font-size: 24px;
  font-weight: bold;
  color: #00d4ff;
  margin-bottom: 16px;
}

.result-stars {
  font-size: 40px;
  margin-bottom: 12px;
  display: flex;
  justify-content: center;
  gap: 8px;
}

.result-stars .star {
  display: inline-block;
  opacity: 0;
  animation: starPop 0.4s ease forwards;
}

.result-stars .star.filled {
  color: #FFD700;
  text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

.result-stars .star.empty {
  color: #444;
}

.result-score {
  font-size: 28px;
  font-weight: bold;
  color: #fff;
  margin-bottom: 8px;
}

.result-crown {
  font-size: 16px;
  color: #FFD700;
  margin-bottom: 8px;
  text-shadow: 0 0 12px rgba(255, 215, 0, 0.4);
}

.result-crown.hidden {
  display: none;
}

.result-time {
  font-size: 13px;
  color: #8899aa;
  margin-bottom: 20px;
}

.result-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.result-btn {
  padding: 10px 24px;
  border: 1.5px solid #0f3460;
  border-radius: 8px;
  background: transparent;
  color: #8899aa;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.result-btn:hover {
  background: #0f3460;
  color: #fff;
}

.result-btn.primary {
  background: #0f3460;
  color: #00d4ff;
  border-color: #00d4ff;
}

.result-btn.primary:hover {
  background: #00d4ff;
  color: #1a1a2e;
}

/* Responsive: tablet portrait */
@media (max-width: 768px) {
  #app {
    flex-direction: column;
  }

  #left-panel {
    flex: none;
    height: 50%;
    min-width: unset;
  }

  .divider {
    width: auto;
    height: 5px;
    cursor: row-resize;
  }

  #center-panel {
    width: auto;
    min-width: unset;
    flex: 1;
  }

  #right-menu {
    width: auto;
    height: 44px;
    flex-direction: row;
    border-left: none;
    border-top: 1px solid #1a2332;
    padding: 0 8px;
  }

  .menu-spacer {
    flex: 1;
  }

  .tooltip {
    display: none !important;
  }
}
