:root {
  color-scheme: dark;
  --bg: #000000;
  --fg: #e5e5e5;
  --muted: #888888;
  --border: #3a3a3a;
  --app-height: 100dvh;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  border-radius: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: var(--app-height);
  background: var(--bg);
  color: var(--fg);
  font-family: "D2Coding", ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, Menlo, Monaco, "DotumChe", monospace;
  font-size: 13px;
  overflow: hidden;
  touch-action: manipulation;
}

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border);
  outline: none;
}

button {
  cursor: pointer;
}

button:active {
  background: var(--fg);
  color: var(--bg);
}

.app-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: var(--app-height);
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.hidden {
  display: none !important;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 4px 6px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  min-height: 36px;
  flex-shrink: 0;
}

.session-strip {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  touch-action: pan-x;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  flex: 1;
}

.session-strip::-webkit-scrollbar {
  display: none;
}

.session-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  white-space: nowrap;
  cursor: pointer;
}

.session-pill.active {
  border-color: var(--fg);
  background: var(--fg);
  color: var(--bg);
  font-weight: 700;
}

.session-close {
  border: none;
  background: transparent;
  color: inherit;
  padding: 0 2px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.status-dot {
  width: 8px;
  height: 8px;
  border: 1px solid var(--border);
  background: transparent;
}

.status-dot.connected {
  background: var(--fg);
  border-color: var(--fg);
}

.status-dot.reconnecting {
  background: var(--muted);
  border-color: var(--muted);
}

.status-dot.disconnected {
  background: transparent;
  border-color: var(--fg);
}

.icon-btn {
  height: 28px;
  padding: 0 8px;
  white-space: nowrap;
}

.icon-btn.primary {
  border-color: var(--fg);
}

.floating-toggle {
  position: fixed;
  right: 6px;
  z-index: 30;
  height: 26px;
  padding: 0 8px;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
  font-size: 12px;
}

.floating-toggle.top {
  top: calc(4px + env(safe-area-inset-top));
}

.floating-toggle.dock-expand {
  bottom: calc(6px + env(safe-area-inset-bottom));
  right: 6px;
}

.floating-toggle.dock-expand.left {
  right: auto;
  left: 6px;
}

/* Workspace row + vertical side dock */
.workspace-row {
  position: relative;
  display: flex;
  flex-direction: row;
  flex: 1;
  min-height: 0;
  width: 100%;
}

.file-drawer {
  order: 2;
  width: 280px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-left: 1px solid var(--border);
  min-height: 0;
}

.file-drawer.drag-over {
  border-left: 2px solid var(--fg);
}

/* Terminal area */
.terminal-wrap {
  order: 1;
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  padding: 2px 4px;
  background: var(--bg);
}

#terminal {
  width: 100%;
  height: 100%;
}

.xterm .xterm-viewport {
  overflow-y: auto !important;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none !important;
}

.xterm .xterm-viewport::-webkit-scrollbar {
  width: 0 !important;
  height: 0 !important;
  display: none !important;
}

.xterm .composition-view {
  background: transparent !important;
  color: var(--fg) !important;
  border-bottom: 1px solid var(--fg) !important;
  z-index: 10 !important;
}

/* Side quick-key dock */
.side-dock {
  order: 3;
  width: 48px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-left: 1px solid var(--border);
}

.workspace-row.dock-left .side-dock {
  order: -1;
  border-left: none;
  border-right: 1px solid var(--border);
}

.side-dock.dragging {
  opacity: 0.72;
  will-change: transform;
}

.dock-controls {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.dock-ctrl-btn {
  flex: 1;
  height: 28px;
  border: none;
  border-right: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  font-size: 12px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.dock-ctrl-btn:last-child {
  border-right: none;
}

.quick-keys {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.quick-keys::-webkit-scrollbar {
  display: none;
}

.qkey {
  width: 100%;
  min-height: 34px;
  padding: 2px;
  font-size: 11px;
  white-space: nowrap;
  flex-shrink: 0;
  user-select: none;
  -webkit-user-select: none;
}

.qkey.armed {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
  font-weight: 700;
}

.ime-bar {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 4px 6px 6px;
  border-top: 1px solid var(--border);
}

.ime-bar textarea {
  flex: 1;
  min-height: 36px;
  max-height: 110px;
  padding: 7px 8px;
  font-size: 14px;
  line-height: 1.35;
  resize: none;
}

.ime-bar textarea:focus {
  border-color: var(--fg);
}

.ime-send-btn {
  height: 36px;
  padding: 0 12px;
  border-color: var(--fg);
  font-weight: 700;
  flex-shrink: 0;
}

/* Modals & toasts */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--bg);
}

.card {
  width: 100%;
  max-width: 340px;
  padding: 16px;
  border: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card h2 {
  font-size: 15px;
  font-weight: 700;
}

.card p {
  font-size: 12px;
  color: var(--muted);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 12px;
  color: var(--muted);
}

.field input,
.field select {
  height: 36px;
  padding: 0 8px;
  font-size: 14px;
}

.field input:focus,
.field select:focus {
  border-color: var(--fg);
}

.field input:disabled,
.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.btn-primary {
  height: 36px;
  padding: 0 12px;
  background: var(--fg);
  color: var(--bg);
  border: 1px solid var(--fg);
  font-weight: 700;
}

.error-text {
  font-size: 12px;
  color: var(--fg);
  text-decoration: underline;
}

.clipboard-toast {
  position: fixed;
  top: 42px;
  right: 6px;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border: 1px solid var(--fg);
  background: var(--bg);
  font-size: 12px;
}

/* Project file drawer & viewer */
.icon-btn.armed {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
  font-weight: 700;
}

.icon-btn.mini {
  height: 24px;
  padding: 0 6px;
  font-size: 11px;
}

.link-btn {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  border: 1px solid var(--border);
  color: var(--fg);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 4px 6px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.drawer-title {
  font-size: 12px;
  font-weight: 700;
}

.drawer-header-actions {
  display: flex;
  gap: 4px;
}

.files-breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  padding: 4px 6px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted);
  flex-shrink: 0;
}

.crumb-btn {
  border: none;
  padding: 1px 2px;
  color: var(--fg);
  font-size: 11px;
}

.crumb-btn:hover {
  text-decoration: underline;
}

.crumb-sep {
  color: var(--muted);
}

.drawer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px 6px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.files-status {
  padding: 4px 6px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted);
}

.files-list {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
}

.file-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border-bottom: 1px solid #1d1d1d;
  cursor: pointer;
  font-size: 12px;
  content-visibility: auto;
  contain-intrinsic-size: auto 32px;
}

.file-row:hover {
  background: #121212;
}

.file-tag {
  color: var(--muted);
  flex-shrink: 0;
}

.file-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-size {
  color: var(--muted);
  font-size: 11px;
  flex-shrink: 0;
}

.file-insert-btn {
  height: 22px;
  padding: 0 6px;
  font-size: 11px;
  flex-shrink: 0;
}

.file-empty {
  padding: 12px 8px;
  color: var(--muted);
  font-size: 12px;
}

.field textarea {
  padding: 6px 8px;
  font-size: 13px;
  resize: vertical;
}

.viewer-card {
  width: 100%;
  max-width: 780px;
  height: min(88dvh, 720px);
  border: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding: 10px;
  gap: 8px;
}

.viewer-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
  flex-shrink: 0;
}

.viewer-title {
  font-size: 12px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.viewer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  flex-shrink: 0;
}

.viewer-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  padding: 8px;
}

.viewer-pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  line-height: 1.45;
}

.viewer-editor {
  width: 100%;
  height: 100%;
  border: none;
  resize: none;
  font-size: 13px;
  line-height: 1.45;
}

.viewer-image {
  max-width: 100%;
  max-height: 100%;
  display: block;
}

.viewer-frame {
  width: 100%;
  height: 100%;
  border: none;
  background: #ffffff;
  display: block;
}

.viewer-media {
  max-width: 100%;
  max-height: 100%;
  display: block;
}

.viewer-audio {
  width: 100%;
  margin-top: 8px;
}

.viewer-notice {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

@media (max-width: 767px) {
  .file-drawer {
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    z-index: 25;
    width: min(88vw, 310px);
  }
}
