:root {
  color-scheme: dark;
  --terminal-bottom-gutter: 0px;
  --bg: #111315;
  --panel: #181b1f;
  --panel-strong: #0d0f11;
  --text: #f4f0e8;
  --muted: #aeb5b8;
  --line: #2e3438;
  --accent: #51c7a9;
  --accent-strong: #8ad7ff;
  --danger: #ff9b8f;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(81, 199, 169, 0.14), transparent 34%),
    linear-gradient(315deg, rgba(138, 215, 255, 0.1), transparent 28%),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: grid;
  place-items: center;
  padding: 12px;
  overflow: hidden;
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 24px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(24, 27, 31, 0.94);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.36);
}

.terminal-panel {
  width: min(1420px, calc(100vw - 24px));
  height: calc(100vh - 24px);
  height: calc(100dvh - 24px);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) var(--terminal-bottom-gutter);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.36);
}

.terminal-header {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.1;
}

h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
}

.login-form {
  display: grid;
  gap: 16px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  background: #0f1214;
  color: var(--text);
  outline: none;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(81, 199, 169, 0.18);
}

button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 14px;
  background: var(--accent);
  color: #07100d;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.06);
}

button:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.toolbar button {
  background: transparent;
  color: var(--text);
  border-color: var(--line);
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 14px;
}

.copy-status {
  min-height: 20px;
  margin: 0;
  padding: 0 18px;
  color: var(--accent-strong);
  background: var(--panel-strong);
  font-size: 13px;
  line-height: 20px;
}

.clipboard-buffer {
  position: fixed;
  left: -9999px;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(3, 6, 8, 0.72);
}

.password-dialog {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
}

.files-dialog {
  width: min(980px, 100%);
  max-height: min(760px, 100%);
  display: grid;
  grid-template-rows: auto auto auto auto minmax(100px, 1fr) minmax(180px, 2fr);
  gap: 12px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.files-header,
.editor-header,
.files-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.files-header button,
.files-actions button,
.editor-header button,
.upload-label {
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.upload-label input { display: none; }
.files-path { margin: 0; color: var(--accent); font-family: monospace; }
.file-list { min-height: 0; overflow: auto; display: grid; align-content: start; gap: 4px; padding: 4px; border: 1px solid var(--line); border-radius: 6px; }
.file-entry { min-height: 36px; padding: 6px 8px; border: 0; border-radius: 4px; background: transparent; color: var(--text); text-align: left; font-weight: 400; }
.file-entry:hover { background: rgba(81, 199, 169, 0.12); }
.editor-panel { min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 8px; }
.editor-header > div { display: flex; gap: 8px; }
#editorContent { min-height: 0; resize: none; padding: 10px; font-family: "SFMono-Regular", Consolas, monospace; font-size: 14px; line-height: 1.35; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-actions button:first-child {
  background: transparent;
  color: var(--text);
  border-color: var(--line);
}

#terminal {
  min-height: 0;
  overflow: hidden;
  padding: 10px 10px 0;
}

.xterm {
  height: 100% !important;
  max-height: 100%;
}

.xterm .xterm-viewport {
  bottom: 0;
}

.selection-overlay {
  grid-row: 3;
  min-height: 0;
  margin: 0;
  overflow: auto;
  padding: 10px;
  background: #0d0f11;
  color: var(--text);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 14px;
  line-height: 1.18;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  -webkit-user-select: text;
  user-select: text;
  touch-action: pan-y;
}

.terminal-footer {
  display: none;
  background: var(--panel-strong);
}

@media (max-width: 680px) {
  :root {
    --terminal-bottom-gutter: calc(106px + env(safe-area-inset-bottom));
  }

  .app-shell {
    padding:
      max(8px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
  }

  .terminal-panel {
    width: calc(100vw - 16px);
    height: calc(100vh - 16px);
    height: calc(100dvh - 16px);
  }

  .terminal-header {
    min-height: 0;
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
  }

  .terminal-header h1 {
    font-size: 20px;
  }

  .toolbar {
    width: 100%;
  }

  .toolbar button {
    min-height: 44px;
    flex: 1 1 108px;
    padding: 0 10px;
  }

  #terminal {
    padding: 8px 6px 0;
  }

  .selection-overlay {
    padding: 8px 6px;
  }

  .files-backdrop { padding: 8px; }
  .files-dialog { height: 100%; max-height: none; padding: 12px; }
  .files-actions { flex-wrap: wrap; justify-content: flex-start; }

  .terminal-footer {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
    border-top: 1px solid rgba(46, 52, 56, 0.7);
  }

  .terminal-footer button {
    min-width: 0;
    min-height: 42px;
    padding: 0 4px;
    border-color: var(--line);
    background: #181b1f;
    color: var(--text);
    font-size: 13px;
    touch-action: manipulation;
  }
}
