:root {
  --border: #1f1f1f;
  --surface: #0a0a0a;
  --surface-raised: #111;
  --text: #e0e0e0;
  --text-dim: #777;
  --text-muted: #555;
  --accent: #e0e0e0;
  --danger: #b05a5a;
  --radius: 10px;
  --radius-sm: 8px;
}

html, body {
  height: 100%;
  width: 100%;
}

body {
  font-family: 'Open Runde', -apple-system, BlinkMacSystemFont, 'Inter', system-ui, sans-serif;
  touch-action: manipulation;
  color-scheme: dark;
}

button {
  font-family: inherit;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

input, textarea {
  font-family: inherit;
}

.connect-view {
  min-height: 100%;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.connect-card {
  width: 100%;
  max-width: 460px;
  animation: card-in 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.recent-list-wrap {
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.recent-list {
  display: grid;
  gap: 0;
}

.recent-item {
  display: flex;
  align-items: center;
  gap: 0;
}

.recent-item + .recent-item {
  border-top: 1px solid var(--border);
}

.recent-connect,
.recent-remove {
  min-height: 48px;
  border: 0;
  background: transparent;
  transition: background 0.15s;
}

.recent-connect {
  flex: 1;
  min-width: 0;
  padding: 0 0.75rem;
  text-align: left;
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-connect:hover {
  background: var(--surface-raised);
}

.recent-connect:active {
  background: #181818;
}

.recent-remove {
  width: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.recent-remove:hover {
  color: var(--danger);
  background: rgba(176, 90, 90, 0.08);
}

#connectForm {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.field-row {
  display: flex;
  gap: 0.75rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 0;
  flex: 1;
}

.field-host { flex: 2.2; }
.field-port { flex: 1; max-width: 96px; }

.field-label {
  font-size: 0.76rem;
  color: var(--text-dim);
}

.field input,
.field textarea {
  width: 100%;
  padding: 0.65rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}

.field textarea {
  resize: vertical;
  min-height: 84px;
  font-family: 'SFMono-Regular', Menlo, Monaco, Consolas, monospace;
  font-size: 0.8rem;
  line-height: 1.5;
}

.field input:focus,
.field textarea:focus {
  border-color: #555;
  background: #0e0e0e;
}

.field input::placeholder,
.field textarea::placeholder {
  color: var(--text-muted);
}

.field input.invalid,
.field textarea.invalid {
  border-color: var(--danger);
}

.auth-toggle {
  display: flex;
  gap: 0.4rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 3px;
}

.auth-toggle button {
  flex: 1;
  padding: 0.5rem 0;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 0.8rem;
  transition: background 0.15s, color 0.15s;
  min-height: 36px;
}

.auth-toggle button.active {
  background: var(--surface-raised);
  color: var(--text);
}

.auth-toggle button:not(.active):hover {
  color: #bbb;
}

.auth-toggle button:active,
.file-btn:active {
  transform: scale(0.97);
}

.key-drop {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.1rem;
}

.key-drop.drag-over {
  outline: 1px dashed #555;
  outline-offset: 3px;
}

.file-btn {
  padding: 0.4rem 0.7rem;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: #ccc;
  font-size: 0.76rem;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.file-btn:hover {
  background: #1a1a1a;
  border-color: #333;
}

.key-drop-text {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.3;
}

.connect-error {
  font-size: 0.8rem;
  color: var(--danger);
  line-height: 1.45;
  animation: fade-in 0.2s ease both;
}

.btn-connect {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.7rem 0;
  min-height: 46px;
  background: var(--accent);
  border: 0;
  border-radius: var(--radius-sm);
  color: #111;
  font-size: 0.9rem;
  font-weight: 600;
  transition: opacity 0.2s, transform 0.12s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s;
}

.btn-connect:hover {
  background: #f0f0f0;
  box-shadow: 0 0 12px rgba(224, 224, 224, 0.15);
}

.btn-connect:active {
  transform: scale(0.98);
}

.btn-connect:disabled {
  opacity: 0.5;
  cursor: default;
  box-shadow: none;
}

.btn-connect svg {
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.btn-connect:hover:not(:disabled) svg {
  transform: translateY(1px);
}

.save-connection {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 28px;
  color: var(--text-dim);
  font-size: 0.74rem;
  cursor: pointer;
}

.save-connection input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}

.terminal-view {
  position: fixed;
  inset: 0;
  animation: fade-in 0.35s ease both;
}

#terminal {
  position: absolute;
  inset: 0;
  padding: 6px 2px 2px 8px;
}

#terminal .xterm { height: 100%; }
#terminal .xterm-viewport { background: transparent !important; }

.new-conn {
  position: fixed;
  top: calc(0.75rem + env(safe-area-inset-top, 0px));
  right: calc(0.75rem + env(safe-area-inset-right, 0px) + 1rem);
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(13, 13, 13, 0.82);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: #777;
  z-index: 30;
  transition: color 0.15s, border-color 0.15s, transform 0.15s;
}

.new-conn:hover {
  color: var(--text);
  border-color: #333;
  transform: scale(1.06);
}

.new-conn:active {
  transform: scale(0.95);
}

.status {
  position: fixed;
  left: 50%;
  bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 1rem;
  background: rgba(13, 13, 13, 0.88);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: 99px;
  z-index: 25;
  transition: opacity 0.3s, transform 0.3s;
  white-space: nowrap;
}

.status.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(6px);
}

.status.error {
  border-color: #5a3232;
}
.status.error .status-text { color: var(--danger); }
.status.error .status-spinner { display: none; }

.connect-state {
  position: fixed;
  left: 50%;
  bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(8px);
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 1rem;
  background: rgba(13, 13, 13, 0.88);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: 99px;
  opacity: 0;
  pointer-events: none;
  z-index: 60;
  transition: opacity 0.25s, transform 0.25s;
  white-space: nowrap;
}

.connect-state.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.connect-state-text {
  font-size: 0.8rem;
  color: #aaa;
}

.status-spinner {
  width: 13px;
  height: 13px;
  border: 2px solid #333;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.confirm-dialog {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  background: rgba(0, 0, 0, 0.6);
  animation: fade-in 0.15s ease both;
}

.confirm-dialog-inner {
  background: #1a1a1a;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  max-width: 260px;
  width: 90vw;
  animation: card-in 0.2s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.confirm-dialog-text {
  font-size: 0.85rem;
  color: var(--text);
  text-align: center;
  margin-bottom: 1rem;
  line-height: 1.4;
}

.confirm-dialog-actions {
  display: flex;
  gap: 0.5rem;
}

.confirm-btn {
  flex: 1;
  padding: 0.55rem 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
  background: var(--surface-raised);
  color: var(--text);
  transition: background 0.15s, border-color 0.15s;
  min-height: 40px;
}

.confirm-btn:hover {
  background: #1c1c1c;
  border-color: #333;
}

.confirm-btn-danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.confirm-btn-danger:hover {
  background: rgba(176, 90, 90, 0.12);
}

@media (display-mode: standalone) {
  .new-conn { width: 40px; height: 40px; }
  .status, .connect-state { padding: 0.7rem 1.1rem; }
}

@media (max-width: 420px) {
  .connect-view { padding: 1rem; }
  .field-row { gap: 0.55rem; }
  .field-port { max-width: 82px; }
}

.status-spinner {
  animation: none;
  border-top-color: #555;
}
