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

[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
  overflow: auto;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #151515;
  color: #abb2bf;
}

/* Login Overlay */
#login-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #151515;
  z-index: 1000;
}

#login-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 32px;
  width: 300px;
}

#login-title {
  font-size: 24px;
  font-weight: 700;
  color: #e0e0e0;
  text-align: center;
  margin-bottom: 8px;
}

#login-password {
  padding: 12px 14px;
  border: 1px solid #2a2a2a;
  border-radius: 6px;
  background: #0e0e0e;
  color: #e0e0e0;
  font-size: 15px;
  outline: none;
}

#login-password:focus {
  border-color: #555;
}

#login-btn {
  padding: 12px;
  border: none;
  border-radius: 6px;
  background: #e0e0e0;
  color: #151515;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

#login-btn:hover {
  background: #fff;
}

#login-error {
  color: #e06c75;
  font-size: 13px;
  text-align: center;
}

/* -- App ------------------------------------------- */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* -- Floating Controls ------------------------------ */
#floating-controls {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 10;
}

#floating-controls > *, #floating-right > * {
  pointer-events: auto;
}

#floating-right {
  position: absolute;
  right: 12px;
  top: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Ensure floating controls layout adjusts when edit button is moved */
#floating-controls {
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.text-size-btn {
  min-width: 44px;
  min-height: 44px;
  padding: 6px 14px;
  border: 1px solid rgba(69, 71, 90, 0.8);
  border-radius: 6px;
  background: rgba(240, 240, 240, 0.95);
  color: #333;
  font-size: 15px;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.text-size-btn:hover {
  background: rgba(255, 255, 255, 0.95);
}

#btn-split {
  border-radius: 0 0 6px 6px;
  border-top: none;
}

#floating-right {
  position: absolute;
  right: 12px;
  top: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.floating-btn, #btn-send {
  min-width: 44px;
  min-height: 44px;
  padding: 6px 14px;
  border: 1px solid rgba(69, 71, 90, 0.8);
  border-radius: 6px;
  background: rgba(21, 21, 21, 0.85);
  color: #abb2bf;
  font-size: 15px;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.floating-btn:hover, #btn-send:hover {
  background: rgba(69, 71, 90, 0.9);
}

.floating-btn.active {
  background: rgba(97, 175, 239, 0.9);
  color: #151515;
  border-color: #61afef;
}

#lang-select {
  min-height: 44px;
  padding: 6px 10px;
  border: 1px solid rgba(69, 71, 90, 0.8);
  border-radius: 6px;
  background: rgba(21, 21, 21, 0.85);
  color: #abb2bf;
  font-size: 14px;
  cursor: pointer;
  touch-action: manipulation;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

#connection-status {
  font-size: 12px;
  color: #e06c75;
  transition: color 0.3s;
}

#connection-status.connected {
  color: #98c379;
}

/* -- Info Box ------------------------------------------ */
#info-box-wrapper {
  position: fixed !important;
  left: auto !important;
  bottom: 0 !important;
  right: 20px !important;
  min-width: 25vw;
  width: 33vw;
  height: 40vh;
  min-height: 80px;
  max-width: 90vw;
  max-height: 80vh;
  z-index: 100;
  display: grid;
  background: rgba(21, 21, 21, 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(69, 71, 90, 0.8);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.3);
}



#info-box-wrapper::after {
  content: attr(data-value) " ";
  white-space: pre-wrap;
  visibility: hidden;
  grid-area: 1 / 1 / 2 / 2;
  font-family: inherit;
  font-size: 24px;
  font-weight: bold;
  padding: 12px;
  line-height: 1.4;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

#info-box {
  grid-area: 1 / 1 / 2 / 2;
  width: 100%;
  height: 100%;
  background: transparent;
  color: #ffffff;
  font-weight: bold;
  border: none;
  padding: 12px;
  font-family: inherit;
  font-size: 24px;
  resize: none;
  outline: none;
  line-height: 1.4;
  overflow: auto;
}



#info-box:not([readonly]) {
  background: rgba(30, 30, 30, 0.95);
  caret-color: #528bff;
}

/* Make it resizable — handles are large enough for touch */
.info-resize-nw {
  position: absolute;
  top: 0;
  left: 0;
  width: 28px;
  height: 28px;
  cursor: nwse-resize;
  z-index: 10;
  touch-action: none;
}

.info-resize-n {
  position: absolute;
  top: 0;
  left: 28px;
  right: 0;
  height: 20px;
  cursor: ns-resize;
  z-index: 10;
  touch-action: none;
}

.info-resize-w {
  position: absolute;
  top: 28px;
  left: 0;
  bottom: 0;
  width: 20px;
  cursor: ew-resize;
  z-index: 10;
  touch-action: none;
}

/* -- Shared code font ------------------------------ */
:root {
  --code-font: "SF Mono", "Fira Code", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --code-size: 16px;
  --code-lh: 1.35;
  --code-pad: 16px;
}

/* -- Code Container -------------------------------- */
#code-container {
  flex: 1;
  overflow: auto;
  position: relative;
}

.code-panel {
  height: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

/* CodeMirror styling */
.CodeMirror {
  height: 100% !important;
  font-family: var(--code-font) !important;
}

.CodeMirror-scroll {
  background: #151515;
}

/* Code display areas fallback */
#code-display, #code-left, #code-right {
  height: 100%;
  overflow: auto;
}

/* Fallback editor styling */
#fallback-editor {
  width: 100%;
  height: 100%;
  background: #151515;
  color: #f8f8f2;
  border: none;
  padding: 16px;
  font-family: var(--code-font);
  font-size: var(--code-size);
  line-height: 1.4;
  resize: none;
  outline: none;
  tab-size: 4;
  white-space: pre;
  overflow: auto;
}

#fallback-editor:focus {
  background: #1a1a1a;
}

#code-single {
  height: 100%;
}

/* Split view */
.split-panels {
  display: flex;
  height: 100%;
  gap: 2px;
}

.split-left, .split-right {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.split-left {
  border-right: 2px solid #2a2a2a;
}

/* -- Editor (CodeMirror) --------------------------- */
#editor-wrap {
  z-index: 5;
  position: absolute;
  inset: 0;
  display: flex;
}

#editor-area {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 200px;
}

#cm-editor-host {
  height: 100%;
  width: 100%;
}

#cm-editor-host .cm-editor {
  height: 100%;
}

#cm-editor-host .cm-scroller {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

/* -- Chat Panel (edit mode only) ------------------- */
#chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-left: 1px solid #b0b8c4;
  background: #e0e4ea;
  min-width: 0;
}

#chat-panel-header {
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  color: #4a5568;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid #b0b8c4;
  flex-shrink: 0;
}

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  -webkit-overflow-scrolling: touch;
}

.chat-msg {
  padding: 6px 10px;
  border-radius: 6px;
  background: #ffffff;
  color: #1a1a1a;
  font-size: 13px;
  line-height: 1.4;
  word-wrap: break-word;
}

/* -- Chat Bar -------------------------------------- */
#chat-bar {
  display: flex;
  align-items: stretch;
  gap: 0;
  padding: 0;
  background: #d8dce3;
  border-top: 1px solid #b0b8c4;
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  min-height: 44px;
  padding: 8px 14px;
  border: none;
  border-radius: 0;
  background: #d8dce3;
  color: #1a1a1a;
  font-size: 14px;
  outline: none;
  touch-action: manipulation;
}

#chat-input:focus {
  background: #e8ecf0;
}

#chat-input::placeholder {
  color: #6b7280;
}

#btn-send {
  border: none;
  border-left: 1px solid #b0b8c4;
  border-radius: 0;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  background: #d8dce3;
  color: #1a1a1a;
}

/* Toast */
#chat-toast {
  position: fixed;
  bottom: 52px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px;
  background: #2a2a2a;
  color: #abb2bf;
  border: 1px solid #333;
  border-radius: 8px;
  font-size: 13px;
  max-width: 80%;
  text-align: center;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  z-index: 100;
}

#chat-toast.show {
  opacity: 1;
}

/* -- Responsive ------------------------------------ */
@media (max-width: 600px) {
  .split-panels {
    flex-direction: column;
  }

  .split-left {
    border-right: none;
    border-bottom: 2px solid #2a2a2a;
  }

  :root {
    --code-size: 13px;
  }

  .floating-btn, #btn-send {
    padding: 6px 10px;
    font-size: 14px;
  }
}

/* -- Remote Selection (Read-only mode - Student view) -- */
/* Highlighted selection from teacher - bright cyan for visibility */
.remote-selection-highlight {
  background: rgba(0, 255, 255, 0.4) !important;
  box-shadow: 0 0 8px rgba(0, 255, 255, 0.3) !important;
}

/* Highlighted selection from teacher */
.CodeMirror-remote-selection {
  background: rgba(0, 255, 255, 0.4) !important;
}

@keyframes cursor-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

@keyframes blink-cursor {
  0%, 100% { opacity: 1; box-shadow: 0 0 8px #ffeb3b, 0 0 16px #ffeb3b; }
  50% { opacity: 0.6; box-shadow: 0 0 4px #ffeb3b, 0 0 8px #ffeb3b; }
}

/* Make normal CodeMirror cursor visible */
.CodeMirror-cursor {
  border-left: 2px solid #528bff !important;
}
