/* Global Reset & Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; /* Eliminate double-tap to zoom globally and block click delay */
}

html {
  overflow: hidden;
  height: 100%;
  touch-action: manipulation;
}


:root {
  --bg-color: #080c14;
  --panel-bg: rgba(13, 20, 35, 0.65);
  --panel-border: rgba(99, 102, 241, 0.15);
  --primary-color: #6366f1;
  --primary-glow: rgba(99, 102, 241, 0.4);
  --accent-color: #10b981;
  --accent-glow: rgba(16, 185, 129, 0.3);
  --danger-color: #ef4444;
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --terminal-bg: #0c0c0c;
  
  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-color);
  color: var(--text-primary);
  height: 100%;
  overflow: hidden;
  position: relative;
  touch-action: manipulation;
  background-image: 
    radial-gradient(circle at 10% 20%, rgba(99, 102, 241, 0.08) 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(16, 185, 129, 0.05) 0%, transparent 40%);
}

/* App Container Layout */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  position: relative;
}

/* Views Management */
.view-panel {
  display: none;
  flex-direction: column;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.view-panel.active {
  display: flex;
  opacity: 1;
}

/* Glassmorphism Card (Connection Panel) */
#connection-view {
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.glass-card {
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  width: 100%;
  max-width: 520px;
  padding: 24px;
  margin: auto 0;
}

.card-header {
  text-align: center;
  margin-bottom: 24px;
}

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 8px;
}

.logo-icon {
  color: var(--primary-color);
  width: 32px;
  height: 32px;
  filter: drop-shadow(0 0 8px var(--primary-glow));
}

.logo h1 {
  font-size: 28px;
  font-weight: 700;
  background: linear-gradient(135deg, #a5b4fc 0%, #6366f1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.5px;
}

.subtitle {
  font-size: 14px;
  color: var(--text-secondary);
}

/* Form Styles */
.form-group {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-row {
  display: flex;
  gap: 12px;
  width: 100%;
}

.flex-1 { flex: 1; }
.flex-3 { flex: 3; }

label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

label i {
  width: 14px;
  height: 14px;
}

input[type="text"],
input[type="number"],
input[type="password"],
textarea {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  color: var(--text-primary);
  padding: 12px 14px;
  font-size: 14px;
  font-family: var(--font-sans);
  transition: all 0.2s ease;
  width: 100%;
  outline: none;
}

input:focus,
textarea:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
  background: rgba(255, 255, 255, 0.07);
}

textarea {
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
  height: 100px;
  resize: vertical;
}

/* Auth Buttons Toggle */
.auth-toggle-group {
  display: flex;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  padding: 3px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.auth-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.auth-btn.active {
  background: var(--primary-color);
  color: white;
  box-shadow: 0 2px 8px var(--primary-glow);
}

/* Auth Sections switching */
.auth-section {
  display: none;
  animation: fadeIn 0.25s ease forwards;
}

.auth-section.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Password Toggle Wrapper */
.password-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.password-wrapper input {
  padding-right: 44px;
}

.password-toggle {
  position: absolute;
  right: 12px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
}

.password-toggle:hover {
  color: var(--text-primary);
}

/* File Upload styling */
.file-upload-wrapper {
  position: relative;
  width: 100%;
}

.file-upload-wrapper input[type="file"] {
  position: absolute;
  left: 0;
  top: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.file-upload-trigger {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(99, 102, 241, 0.1);
  border: 1px dashed rgba(99, 102, 241, 0.4);
  border-radius: 10px;
  padding: 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--primary-color);
  text-align: center;
  transition: all 0.2s ease;
}

.file-upload-wrapper:hover .file-upload-trigger {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--primary-color);
}

/* Custom Checkbox */
.form-row-checkbox {
  margin: 18px 0;
}

.checkbox-container {
  display: flex;
  align-items: center;
  position: relative;
  padding-left: 28px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  user-select: none;
}

.checkbox-container input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
  height: 0;
  width: 0;
}

.checkmark {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  left: 0;
  height: 18px;
  width: 18px;
  background-color: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  transition: all 0.2s ease;
}

.checkbox-container:hover input ~ .checkmark {
  background-color: rgba(255, 255, 255, 0.1);
}

.checkbox-container input:checked ~ .checkmark {
  background-color: var(--primary-color);
  border-color: var(--primary-color);
}

.checkmark:after {
  content: "";
  position: absolute;
  display: none;
}

.checkbox-container input:checked ~ .checkmark:after {
  display: block;
}

.checkbox-container .checkmark:after {
  left: 6px;
  top: 2px;
  width: 4px;
  height: 8px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* Connect Submit Button */
.submit-btn {
  background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  border: none;
  border-radius: 12px;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  padding: 14px;
  width: 100%;
  cursor: pointer;
  box-shadow: 0 4px 16px var(--primary-glow);
  transition: all 0.2s ease;
  margin-top: 10px;
}

.submit-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px var(--primary-glow);
}

.submit-btn:active {
  transform: translateY(1px);
}

/* Connection History */
.history-section {
  margin-top: 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 18px;
}

.history-section h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 120px;
  overflow-y: auto;
  padding-right: 4px;
}

.empty-history {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: 10px;
}

.history-item {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.history-item:hover {
  background: rgba(99, 102, 241, 0.08);
  border-color: rgba(99, 102, 241, 0.2);
}

.history-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.history-host {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.history-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.history-delete {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.history-delete:hover {
  color: var(--danger-color);
  background: rgba(239, 68, 68, 0.1);
}

/* Terminal View Panel */
#terminal-view {
  background-color: var(--terminal-bg);
  overflow: hidden;
  height: 100%;
}

.terminal-header {
  height: 52px;
  background: #0d111a;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px;
  z-index: 10;
}

.connection-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  max-width: 60%;
  overflow: hidden;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-dot.connected {
  background-color: var(--accent-color);
  box-shadow: 0 0 8px var(--accent-glow);
}

#active-connection-title {
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  color: var(--text-secondary);
}

.terminal-actions {
  display: flex;
  gap: 8px;
}

.action-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.action-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.action-btn.active {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
  box-shadow: 0 2px 8px var(--primary-glow);
}

.action-btn.active:hover {
  background: #4f46e5;
  color: white;
}

.danger-btn {
  border-color: rgba(239, 68, 68, 0.2);
}

.danger-btn:hover {
  background: var(--danger-color);
  border-color: var(--danger-color);
  color: white;
}

.action-btn i {
  width: 14px;
  height: 14px;
}

/* Terminal Wrapper occupies all remaining space */
.terminal-wrapper {
  flex: 1;
  min-height: 0;
  position: relative;
  padding: 8px;
  overflow: hidden;
}

#terminal-container {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* Customize xterm viewport styling */
.xterm-viewport {
  background-color: var(--terminal-bg) !important;
  -webkit-overflow-scrolling: touch !important; /* Enable smooth iOS momentum scrolling */
  touch-action: none !important; /* Managed by JS Kinetic scroll simulator */
  will-change: transform, scroll-position !important;
  transform: translate3d(0, 0, 0) !important; /* Force GPU composite layer creation */
}

.xterm-screen {
  font-family: var(--font-mono) !important;
  touch-action: none !important; /* Managed by JS Kinetic scroll simulator */
  -webkit-touch-callout: none !important; /* Disable iOS context menu on long-press */
  will-change: transform !important;
  transform: translate3d(0, 0, 0) !important; /* Force GPU composite layer creation */
}

/* Mobile Helper Keyboard Bar */
#helper-keyboard {
  height: 48px;
  background-color: #0b0f19;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  width: 100%;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
  z-index: 20;
  transition: height 0.2s ease;
}

/* Expanded Multi-row layout styles */
#helper-keyboard.expanded {
  height: 200px; /* Fix height to comfortably fit 5 fixed rows */
  overflow: visible;
  align-items: flex-start; /* Prevent top layout clipping when content height exceeds container */
}

.helper-scroll-container {
  display: flex;
  overflow-x: auto;
  gap: 8px;
  padding: 0 12px;
  width: 100%;
  height: 100%;
  align-items: center;
  scrollbar-width: none; /* Hide scrollbar for Firefox */
}

/* Default unexpanded state: Let the browser treat .helper-row children as direct children of the flex container */
.helper-row {
  display: contents;
}

#helper-keyboard.expanded .helper-scroll-container {
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: hidden; /* Lock vertical scroll in expanded mode for safety */
  padding: 10px 12px;
  height: 100%;
  gap: 6px;
  align-items: flex-start;
  justify-content: flex-start;
}

#helper-keyboard.expanded .helper-row {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 5px;
  width: 100%;
  overflow-x: hidden; /* Defeat horizontal scroll entirely */
  justify-content: flex-start;
  align-items: center;
}

#helper-keyboard.expanded .helper-key {
  flex: 1;
  min-width: 0; /* Enable auto shrinking to fit screen width perfectly */
  padding: 0 2px;
  font-size: 11px;
  justify-content: center;
  text-align: center;
}

#key-layout-toggle.active {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
  box-shadow: 0 0 8px var(--primary-glow);
}

.helper-scroll-container::-webkit-scrollbar {
  display: none; /* Hide scrollbar for Chrome/Safari */
}

.helper-key {
  height: 32px;
  min-width: 44px;
  padding: 0 10px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.helper-key:active {
  background: rgba(255, 255, 255, 0.15);
  transform: scale(0.95);
}

.helper-key.toggle-key.active {
  background: var(--primary-color);
  border-color: var(--primary-color);
  color: white;
  box-shadow: 0 0 8px var(--primary-glow);
}

.helper-key.nav-key {
  min-width: 36px;
}

.helper-key.nav-key i {
  width: 16px;
  height: 16px;
}

#key-clear {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.2);
  color: var(--danger-color);
}

#key-clear:active {
  background: var(--danger-color);
  color: white;
}

/* Global Loading Overlay */
.overlay-panel {
  display: none;
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(5, 7, 12, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.overlay-panel.active {
  display: flex;
}

.overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 24px;
  max-width: 320px;
  text-align: center;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(99, 102, 241, 0.1);
  border-radius: 50%;
  border-top-color: var(--primary-color);
  animation: spin 1s linear infinite;
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.1);
}

#loading-message {
  font-size: 14px;
  color: var(--text-secondary);
}

.cancel-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 13px;
  padding: 8px 16px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.cancel-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Scrollbars styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #0c0c0c;
}

::-webkit-scrollbar-thumb {
  background: #333333;
  border-radius: 4px;
  border: 1px solid #0c0c0c;
}

::-webkit-scrollbar-thumb:hover {
  background: #555555;
}

/* Desktop overrides */
@media (min-width: 768px) {
  body {
    background-size: 40% 40%;
  }
  
  .glass-card {
    padding: 32px;
  }
  
  /* On desktop, hide helper keyboard completely to fit the terminal full-screen */
  #helper-keyboard {
    display: none !important;
  }
  
  /* Slim title bar for terminal header on desktop, matching Windows Terminal */
  .terminal-header {
    height: 38px;
    background: #1e1e1e;
    padding: 0 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }
  
  .connection-info {
    font-size: 12px;
  }

  .action-btn {
    padding: 4px 8px;
    font-size: 11px;
    border-radius: 6px;
  }
  
  /* Zero margins and padding for clean full window experience */
  .terminal-wrapper {
    padding: 0;
  }
}

/* Copy Modal Styles */
.copy-modal-card {
  width: 95%;
  max-width: 800px;
  height: 90%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  padding: 20px;
  overflow: hidden; /* Block child overflows and force inner scrolling */
}

#copy-dump-area {
  flex: 1;
  min-height: 0; /* Critical for enabling flex child scroll behaviour */
  height: 100%;
  max-height: 100%;
  width: 100%;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  color: var(--accent-color);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  padding: 12px;
  margin: 16px 0;
  outline: none;
  overflow-y: auto;
  overflow-x: hidden;
  white-space: pre-wrap;
  word-break: break-all;
  user-select: text !important;
  -webkit-user-select: text !important;
  -webkit-touch-callout: default !important;
  touch-action: auto !important;
  -webkit-overflow-scrolling: touch;
}

.terminal-link {
  color: #60a5fa !important;
  text-decoration: underline;
  cursor: pointer;
  font-weight: 500;
  transition: opacity 0.15s ease;
}

.terminal-link:hover {
  opacity: 0.85;
}

.modal-buttons {
  display: flex;
  gap: 12px;
  width: 100%;
}

.modal-buttons button {
  flex: 1;
  margin-top: 0;
}

/* Remove text selection block to allow touch events to pass for scrolling, rely on long-press callout prevention */
#terminal-container {
  -webkit-touch-callout: none !important;
  touch-action: none !important; /* Managed by JS Kinetic scroll simulator */
  will-change: transform !important;
  transform: translate3d(0, 0, 0) !important; /* Force GPU composite layer creation */
  background-color: var(--terminal-bg) !important; /* Set opaque background to prevent blending compositor slowdowns */
}

/* Mobile-specific adjustments to fit the connection card on a single screen without scrolling */
@media (max-width: 480px) {
  #connection-view {
    padding: 8px;
    justify-content: flex-start; /* Prevent centering clipping on very small screens */
    overflow-y: auto;
  }

  .connection-card {
    padding: 14px 16px;
    border-radius: 16px;
    margin: 8px 0;
  }

  .card-header {
    margin-bottom: 12px;
  }

  .logo {
    margin-bottom: 4px;
    gap: 6px;
  }

  .logo-icon {
    width: 24px;
    height: 24px;
  }

  .logo h1 {
    font-size: 22px;
  }

  .subtitle {
    font-size: 11px;
  }

  .form-group {
    margin-bottom: 8px;
    gap: 4px;
  }

  .form-row {
    gap: 8px;
  }

  label {
    font-size: 12px;
    gap: 4px;
  }

  input[type="text"],
  input[type="number"],
  input[type="password"],
  textarea {
    padding: 8px 10px;
    font-size: 13px;
    border-radius: 8px;
  }

  textarea {
    height: 60px; /* Reduce private key box height to fit screen */
  }

  .auth-toggle-group {
    border-radius: 6px;
  }

  .auth-btn {
    padding: 6px 10px;
    font-size: 12px;
    border-radius: 5px;
  }

  .file-upload-trigger {
    padding: 8px;
    font-size: 12px;
    border-radius: 8px;
  }

  .form-row-checkbox {
    margin: 10px 0;
  }

  .checkbox-container {
    font-size: 11px;
    padding-left: 24px;
  }

  .checkmark {
    width: 16px;
    height: 16px;
  }

  .checkmark:after {
    left: 5px;
    top: 1px;
  }

  .submit-btn {
    padding: 10px;
    font-size: 14px;
    border-radius: 10px;
    margin-top: 4px;
  }

  .history-section {
    margin-top: 12px;
    padding-top: 10px;
  }

  .history-section h3 {
    margin-bottom: 6px;
  }

  .history-list {
    max-height: 80px;
    gap: 6px;
  }

  .history-item {
    padding: 6px 10px;
    border-radius: 6px;
  }

  .history-host {
    font-size: 12px;
  }

  .history-meta {
    font-size: 10px;
  }
}

/* Force native text selection compatibility in xterm.js DOM renderer */
.xterm,
.xterm-screen,
.xterm-rows,
.xterm-row,
.xterm-row span {
  user-select: text !important;
  -webkit-user-select: text !important;
  -moz-user-select: text !important;
  -ms-user-select: text !important;
}

.xterm-screen,
.xterm-rows,
.xterm-row,
.xterm-row span {
  cursor: text !important;
}

/* Customize selection highlight colors globally */
::selection {
  background: rgba(99, 102, 241, 0.4) !important;
  color: #ffffff !important;
}
::-moz-selection {
  background: rgba(99, 102, 241, 0.4) !important;
  color: #ffffff !important;
}

/* Customize xterm.js internal selection overlay visual style if browser default is bypassed */
.xterm .xterm-selection div {
  background-color: rgba(99, 102, 241, 0.4) !important;
}

/* Enable native selection handles dragging on mobile touch devices when selection is active */
#terminal-container.touch-selectable,
#terminal-container.touch-selectable .xterm-screen {
  touch-action: auto !important;
  -webkit-touch-callout: default !important;
}

/* Helper Keyboard Edit Mode Styles */
@keyframes key-wiggle {
  0% { transform: rotate(-1deg); }
  50% { transform: rotate(1deg); }
  100% { transform: rotate(-1deg); }
}

#helper-keyboard {
  position: relative;
}

#helper-keyboard.edit-mode .helper-key {
  animation: key-wiggle 0.2s infinite ease-in-out;
  border-color: rgba(99, 102, 241, 0.5) !important;
  box-shadow: 0 0 5px rgba(99, 102, 241, 0.2);
  background: rgba(99, 102, 241, 0.08) !important;
}

#helper-keyboard.edit-mode .helper-key.dragging {
  animation: none !important;
  opacity: 0.3 !important;
  border: 1px dashed var(--primary-color) !important;
  background: rgba(99, 102, 241, 0.15) !important;
}

.helper-key.floating-drag {
  position: fixed;
  z-index: 10000;
  pointer-events: none;
  background: rgba(99, 102, 241, 0.4) !important;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border-color: var(--primary-color) !important;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.5);
  transform: scale(1.15);
  transition: none !important;
}

/* Edit Mode Overlay Button style */
.edit-done-btn {
  display: none;
  position: absolute;
  top: -38px;
  right: 12px;
  height: 30px;
  padding: 0 14px;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  border: none;
  border-radius: 6px;
  color: white;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(16, 185, 129, 0.3);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

#helper-keyboard.edit-mode .edit-done-btn {
  display: flex;
}

.edit-done-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(16, 185, 129, 0.4);
}

.edit-done-btn:active {
  transform: translateY(1px);
}

/* iOS Safari IME Korean input fix: Force helper textarea to be on-screen and opaque but visually hidden */
.xterm-helper-textarea {
  position: absolute !important;
  left: 0 !important;
  top: 0 !important;
  width: 10px !important;
  height: 10px !important;
  opacity: 1 !important;
  color: transparent !important;
  background: transparent !important;
  caret-color: transparent !important;
  border: none !important;
  resize: none !important;
  outline: none !important;
  z-index: -1 !important;
  overflow: hidden !important;
  pointer-events: none !important;
}
