:root {
  color-scheme: dark;
  --status-height: 2.25rem;
  --status-line: var(--editor-highlight);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: #0f0f0f; /* neutral so browser chrome stays dark, not blue */
  color: var(--editor-fg);
  font-family: "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#status {
  position: relative;
  height: var(--status-height);
  background: var(--editor-bg);
  color: var(--editor-highlight);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.75rem;
  font-size: 0.95rem;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#status::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: var(--status-line);
  pointer-events: none;
  transform: translateY(-50%);
}

#status-filename {
  display: inline-block;
  padding: 0 1rem;
  background: var(--editor-bg);
  position: relative;
  z-index: 1;
  text-align: center;
  cursor: pointer;
}

#status-dirty {
  position: absolute;
  left: 1.25rem;
  color: var(--editor-dark);
  font-size: 0.9rem;
  background: var(--editor-bg);
  z-index: 1;
  cursor: pointer;
}

#status-dirty-box {
  color: #00ff00;
}

#editor {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0; /* allow scrolling within flex parent */
  padding: 1rem;
  border: none;
  margin: 0;
  background: var(--editor-bg);
  color: var(--editor-fg);
  font: inherit;
  line-height: 1.3;
  resize: none;
  outline: none;
  caret-color: var(--editor-fg);
  tab-size: 4;
  -moz-tab-size: 4;
  white-space: pre-wrap;
}

/* Mobile: make sure the viewport is usable */
@media (max-width: 600px) {
  #editor {
    padding: 0.75rem;
  }
}

/* PWA with window-controls-overlay: keep the top status bar clear of the
   OS window controls (traffic lights on macOS, min/close on Windows). */
@media (display-mode: window-controls-overlay) {
  #status {
    padding-left: calc(env(titlebar-area-x, 0) + 0.75rem);
    padding-right: calc(100vw - env(titlebar-area-width, 100vw) - env(titlebar-area-x, 0) + 0.75rem);
  }
}

/* Hide the file input; it's only triggered from the keyboard shortcut */
#fileInput {
  display: none;
}

#status-bottom {
  position: relative;
  height: var(--status-height);
  background: var(--editor-bg);
  color: var(--editor-dark);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0 0.75rem;
  font-size: 0.95rem;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#status-bottom::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: var(--status-line);
  pointer-events: none;
  transform: translateY(-50%);
}

#status-pos {
  display: inline-block;
  padding: 0 0.75rem;
  background: var(--editor-bg);
  position: relative;
  z-index: 1;
}

/* Help menu: a table of actions on the shared dialog panel. */
#help:focus {
  outline: none;
}

#help table {
  border-collapse: collapse;
  width: 100%;
}

#help td {
  padding: 0.15rem 0.5rem 0.15rem 0;
  vertical-align: top;
}

#help tr[data-action] {
  cursor: pointer;
}

/* Needs something not set up yet (e.g. a repository); still selectable. */
#help tr.unavailable td {
  color: var(--editor-dark);
}

#help tr[aria-selected="true"] td {
  background: var(--editor-highlight);
  color: var(--editor-bg);
}

#help td.key {
  color: var(--editor-dark);
  white-space: nowrap;
  width: 12rem;
  text-align: right;
}

#status-msg {
  display: inline-block;
  margin-left: auto;
  padding: 0 0.75rem;
  background: var(--editor-bg);
  color: var(--editor-fg);
  position: relative;
  z-index: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

dialog.panel {
  background: var(--editor-bg);
  color: var(--editor-fg);
  border: 1px solid var(--editor-highlight);
  padding: 1rem 1.25rem;
  width: min(32rem, calc(100vw - 2rem));
  max-height: 85vh;
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.4;
}

dialog.panel::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

dialog.panel h2 {
  margin: 0 0 0.75rem 0;
  font-size: 1rem;
  color: var(--editor-highlight);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

dialog.panel .field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin-bottom: 0.6rem;
}

dialog.panel .label-row {
  display: flex;
  justify-content: space-between;
}

dialog.panel a {
  color: var(--editor-highlight);
}

dialog.panel input,
dialog.panel button {
  font: inherit;
  color: var(--editor-fg);
  background: transparent;
  border: 1px solid var(--editor-dark);
  padding: 0.3rem 0.5rem;
}

dialog.panel input:focus,
dialog.panel button:focus-visible {
  outline: none;
  border-color: var(--editor-highlight);
}

dialog.panel button {
  cursor: pointer;
}

dialog.panel button:hover {
  color: var(--editor-highlight);
}


dialog.panel .hint {
  color: var(--editor-dark);
  font-size: 0.85rem;
  margin: 0.5rem 0;
}

dialog.panel .hint:empty {
  display: none;
}

dialog.panel .buttons {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

dialog.panel label.check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

dialog.panel input[type="checkbox"] {
  accent-color: var(--editor-highlight);
  width: 1rem;
  height: 1rem;
  margin: 0;
}

#s-remove,
dialog.panel .keys-hint {
  margin-right: auto;
}

dialog.panel .buttons {
  align-items: center;
}

dialog.panel .buttons .hint {
  margin: 0 auto 0 0;
}

#status-msg[hidden] {
  display: none;
}

/* Fixed height so the dialog doesn't resize as the list filters or loads. */
.pick-dialog[open] {
  height: min(30rem, 85vh);
  display: flex;
  flex-direction: column;
}

.pick-search {
  width: 100%;
  flex: none;
}

/* Always reserve one line for loading/error text so the list doesn't shift. */
.pick-msg,
.pick-msg:empty {
  display: block;
  min-height: 1.2em;
  margin: 0.4rem 0;
  flex: none;
}

.pick-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.pick-dialog .buttons {
  flex: none;
}

.pick-list li {
  padding: 0.1rem 0.4rem;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pick-list li[aria-selected="true"] {
  background: var(--editor-highlight);
  color: var(--editor-bg);
}
