

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #1a1a1a;
  --bg-elevated: #222;
  --bg-hover: #2a2a2a;
  --bg-active: #333;
  --fg: #e4e4e4;
  --fg-dim: #888;
  --fg-faint: #555;
  --accent: #7dd3c0;
  --border: #2a2a2a;
  --modified: #e8b842;
  --danger: #e57373;
  --ui-font-delta: 0px;  
  --glow-color: transparent;
}

html[data-theme="green"]  { --accent:#39ff77; --glow-color:#39ff77; }
html[data-theme="amber"]  { --accent:#ffb000; --glow-color:#ffb000; }
html[data-theme="red"]    { --accent:#ffc0b8; --glow-color:#ff2020; }
html[data-theme="pink"]   { --accent:#ffc8f0; --glow-color:#ff26b3; }
html[data-theme="cyber"]  { --accent:#B2FFCA; --glow-color:#39ff77; }

html[data-theme] .title,
html[data-theme] .modal-body h3,
html[data-theme] .modal-body .app-name {
  text-shadow: 0 0 8px var(--glow-color), 0 0 16px var(--glow-color);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  background: var(--bg);
  color: var(--fg);
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  font-size: 13px;
}

header {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: calc(10px + var(--ui-font-delta));
  background: var(--bg-elevated);
  min-width: 0;
}
header button {
  padding: calc(5px + var(--ui-font-delta) / 2) calc(12px + var(--ui-font-delta));
  font-size: calc(12px + var(--ui-font-delta));
}

.title { font-weight: 600; letter-spacing: 1px; font-size: 12px; color: var(--accent); flex-shrink: 0; }

.doc-name {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: calc(12px + var(--ui-font-delta));
  color: var(--fg-dim);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.doc-dirty {
  color: var(--modified);
  font-size: calc(12px + var(--ui-font-delta));
  margin-left: -6px;
  flex-shrink: 0;
  line-height: 1;
}

button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 5px 12px;
  font-size: 12px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  white-space: nowrap;
  flex-shrink: 0;
}
button:hover:not(:disabled) { background: var(--bg-hover); border-color: var(--accent); }
button:disabled { opacity: 0.35; cursor: not-allowed; }
button.primary { background: var(--accent); color: #111; border-color: var(--accent); font-weight: 600; }
button.primary:hover:not(:disabled) { background: #9ae0d0; }

#btn-new-window, #btn-settings {
  
  padding: calc(5px + var(--ui-font-delta) / 2) calc(9px + var(--ui-font-delta));
  font-size: calc(13px + var(--ui-font-delta));
}

main {
  display: flex;
  overflow: hidden;
  min-height: 0;
}

#editor-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.editor-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
}

#editor {
  flex: 1;
  background: var(--bg);
  color: var(--fg);
  border: none;
  padding: 14px 18px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  line-height: 1.65;
  resize: none;
  outline: none;
  tab-size: 2;
  white-space: pre;
  width: 100%;
  height: 100%;
}
#editor:disabled { color: var(--fg-faint); }
#editor::placeholder { color: var(--fg-faint); }

body.wrap-on #editor {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

footer {
  padding: 5px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  font-size: calc(11px + var(--ui-font-delta));
  color: var(--fg-dim);
  display: flex;
  gap: 16px;
  align-items: center;
  overflow: hidden;
}
#status-info { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.footer-hint { white-space: nowrap; flex-shrink: 0; }

.kbd {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  background: var(--bg-active);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10.5px;
  border: 1px solid var(--border);
}

.footer-pill {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: calc(10.5px + var(--ui-font-delta));
  padding: 1px 7px;
  border-radius: 3px;
  border: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  color: var(--fg-dim);
  background: transparent;
  flex-shrink: 0;
}
.footer-pill:hover { color: var(--fg); border-color: var(--accent); }
#pill-readonly { color: var(--modified); border-color: var(--modified); }

.settings-popover {
  position: fixed;
  top: 56px;
  right: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  min-width: 240px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  z-index: 1500;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.settings-popover[hidden] { display: none; }

.popover-backdrop {
  position: fixed;
  inset: 0;
  background: transparent;
  z-index: 1400;
}
.popover-backdrop[hidden] { display: none; }

.settings-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 2px;
  font-size: calc(11.5px + var(--ui-font-delta));
}

.settings-label {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: calc(10px + var(--ui-font-delta));
  color: var(--fg-faint);
  text-transform: uppercase;
  letter-spacing: 1px;
  width: calc(64px + var(--ui-font-delta));
  flex-shrink: 0;
}

.font-btn {
  width: calc(22px + var(--ui-font-delta));
  height: calc(22px + var(--ui-font-delta));
  padding: 0;
  font-size: calc(12px + var(--ui-font-delta));
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#font-size-display {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: calc(11px + var(--ui-font-delta));
  color: var(--fg-dim);
  min-width: calc(36px + var(--ui-font-delta));
  text-align: center;
}

.settings-reset {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: calc(10px + var(--ui-font-delta));
  color: var(--fg-faint);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 3px;
  user-select: none;
  margin-left: auto;
}
.settings-reset:hover { color: var(--accent); background: var(--bg-hover); }

.wrap-btn, .ui-size-btn {
  padding: 3px 8px;
  font-size: calc(10.5px + var(--ui-font-delta));
}
.wrap-btn.active, .ui-size-btn.active {
  background: var(--accent);
  color: #111;
  border-color: var(--accent);
}

.theme-dot {
  width: calc(18px + var(--ui-font-delta));
  height: calc(18px + var(--ui-font-delta));
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-hover);
  cursor: pointer;
}
.theme-dot:hover { transform: scale(1.1); }
.theme-dot[data-theme="calm"]  { background: #7dd3c0; }
.theme-dot[data-theme="green"] { background: #39ff77; }
.theme-dot[data-theme="amber"] { background: #ffb000; }
.theme-dot[data-theme="red"]   { background: #ffc0b8; box-shadow: 0 0 6px #ff2020; }
.theme-dot[data-theme="pink"]  { background: #ffc8f0; box-shadow: 0 0 6px #ff26b3; }
.theme-dot[data-theme="cyber"] { background: #B2FFCA; box-shadow: 0 0 6px #39ff77; }
.theme-dot.active {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.settings-about-row {
  border-top: 1px solid var(--border);
  margin-top: 4px;
  padding-top: 8px;
}
.settings-about {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: calc(10.5px + var(--ui-font-delta));
  color: var(--fg-faint);
  cursor: pointer;
  user-select: none;
  padding: 4px 6px;
  border-radius: 3px;
}
.settings-about:hover { color: var(--accent); background: var(--bg-hover); }

.context-menu {
  position: fixed;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px;
  min-width: 160px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 1600;
  display: none;
}
.context-item {
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  border-radius: 4px;
  color: var(--fg);
  user-select: none;
}
.context-item:hover { background: var(--bg-hover); }
.context-item.heading { color: var(--fg-faint); font-size: 10.5px; cursor: default; }
.context-item.heading:hover { background: transparent; }
.context-separator { height: 1px; background: var(--border); margin: 4px 2px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-width: 640px;
  width: 100%;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
}
.modal-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--accent);
  letter-spacing: 0.5px;
}
.modal-close {
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 16px;
  line-height: 1;
  color: var(--fg-dim);
  border-color: transparent;
}
.modal-close:hover { color: var(--fg); background: var(--bg-hover); }
.modal-body {
  padding: 20px 24px 24px;
  overflow-y: auto;
  color: var(--fg);
  font-size: 12.5px;
  line-height: 1.75;
}
.modal-body h3 {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 1.5px;
  color: var(--accent);
  text-transform: uppercase;
  margin: 18px 0 6px;
}
.modal-body h3:first-child { margin-top: 0; }
.modal-body p { color: var(--fg-dim); margin-bottom: 2px; }
.modal-body .version-line {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  color: var(--fg-faint);
  margin-bottom: 16px;
}
.modal-body .app-name {
  font-size: 16px;
  color: var(--fg);
  font-weight: 600;
  margin-bottom: 2px;
}
.modal-body .license-text {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 10.5px;
  line-height: 1.6;
  color: var(--fg-dim);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 12px;
  white-space: pre-wrap;
  word-break: break-word;
}
.modal-body .author-line {
  font-size: 11px;
  color: var(--fg-dim);
  margin-bottom: 8px;
}
.modal-body a {
  color: var(--accent);
  text-decoration: none;
}
.modal-body a:hover { text-decoration: underline; }
.modal-body code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 0.92em;
  color: var(--fg);
}

@media (max-width: 768px) {
  header { padding: 8px 10px; gap: calc(8px + var(--ui-font-delta)); }
  .title { display: none; }
  header button {
    padding: calc(8px + var(--ui-font-delta) / 2) calc(11px + var(--ui-font-delta));
    font-size: calc(13px + var(--ui-font-delta));
    min-height: 40px;
  }
  .doc-name { font-size: calc(11px + var(--ui-font-delta)); }

  footer { padding: 5px 10px; font-size: calc(10px + var(--ui-font-delta)); gap: 8px; }
  .footer-hint { display: none; }

  footer { padding-bottom: calc(5px + env(safe-area-inset-bottom, 0px)); }

  .settings-popover {
    top: auto;
    bottom: 12px;
    right: 12px;
    left: 12px;
    min-width: 0;
  }
}

.initially-hidden.initially-hidden { display: none; }
