/* ===========================
   drkl.net — terminal theme
   Color tokens live in theme-tokens.css (shared with stats.html).
   =========================== */

/* --- Base --- */
* { box-sizing: border-box; }

/* Visible only to screen readers */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed; left: max(8px, env(safe-area-inset-left)); top: -80px; z-index: 1000;
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 14px; font-size: 13px; text-decoration: none;
  transition: top .15s;
}
.skip-link:focus { top: max(8px, env(safe-area-inset-top)); }
a:focus-visible, button:focus-visible, input:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

html, body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 15px;
  transition: background .3s, color .3s;
  -webkit-text-size-adjust: 100%;
}
html { overflow-x: hidden; max-width: 100vw; }
body {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 40px 16px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  padding-bottom: max(40px, env(safe-area-inset-bottom));
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  max-width: 100vw;
}
.wrap {
  width: 100%;
  max-width: 700px;
  display: flex;
  flex-direction: column;
  min-height: fit-content;
}
a { color: var(--blue); transition: color .15s; }
a:hover { filter: brightness(1.2); }

/* --- Header --- */
.site {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2px;
}
header.site { margin-bottom: 14px; }
footer.site { margin-top: 14px; justify-content: center; gap: 18px; }
.site .brand { color: var(--text); font-weight: 700; font-size: 15px; }
.site .brand .dim { color: var(--muted); font-weight: 400; }
.site nav { display: flex; gap: 16px; align-items: center; }
.site nav a { color: var(--muted); font-size: 13px; text-decoration: none; }
.site nav a:hover { color: var(--blue); }
footer.site a { color: var(--muted); font-size: 13px; text-decoration: none; }
footer.site a:hover { color: var(--blue); }
.sep { color: var(--border); }

/* --- Theme button --- */
.theme-btn {
  background: none; border: none; cursor: pointer; font-size: 18px;
  padding: 2px 6px; border-radius: 4px; line-height: 1; color: var(--muted);
  transition: color .15s, background .15s; width: auto; flex-shrink: 0;
}
.theme-btn:hover { background: var(--panel2); color: var(--blue); }
.theme-btn.switching { animation: themeSpin .4s ease; }
@keyframes themeSpin {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(1.3); }
  100% { transform: rotate(360deg) scale(1); }
}

/* --- Terminal --- */

.term {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--term-shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.titlebar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--panel2);
  border-bottom: 1px solid var(--border);
}
.dot { width: 11px; height: 11px; border-radius: 50%; }
.dot.r { background: var(--red); }
.dot.y { background: var(--yellow); }
.dot.g { background: var(--green); }
.titlebar span { margin-left: 8px; color: var(--muted); font-size: 13px; }

#screen {
  flex: 1 1 auto;
  height: calc(100vh - 220px);
  height: calc(100dvh - 220px);
  max-height: 600px;
  min-height: 200px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px 20px;
  line-height: 1.45;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  user-select: text;
  -webkit-user-select: text;
  min-width: 0;
}
#screen::-webkit-scrollbar { width: 8px; }
#screen::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::selection { background: var(--blue); color: var(--bg); }

/* --- Terminal text --- */
.row { white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; user-select: text; -webkit-user-select: text; max-width: 100%; }
.prompt { color: var(--green); }
.cmd { color: var(--text); }
.muted { color: var(--muted); }
.err { color: var(--red); }
.ok { color: var(--yellow); }
.dir { color: var(--blue); }
.blue { color: var(--blue); }
pre { margin: 0 0 4px; font-family: inherit; font-size: 12px; line-height: 1.25; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
pre.neofetch, pre.fastfetch { font-size: 13px; line-height: 1.4; }

/* Fastfetch ASCII art coloring (pre.neofetch kept as alias) */
[data-theme="dark"] pre.neofetch,
[data-theme="dark"] pre.fastfetch {
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg) 100%);
}
pre.neofetch .ascii-line-0, pre.fastfetch .ascii-line-0 { color: var(--blue); }
pre.neofetch .ascii-line-1, pre.fastfetch .ascii-line-1 { color: var(--blue); }
pre.neofetch .ascii-line-2, pre.fastfetch .ascii-line-2 { color: var(--cyan); }
pre.neofetch .ascii-line-3, pre.fastfetch .ascii-line-3 { color: var(--cyan); }
pre.neofetch .ascii-line-4, pre.fastfetch .ascii-line-4 { color: var(--green); }
pre.neofetch .ascii-line-5, pre.fastfetch .ascii-line-5 { color: var(--green); }
pre.neofetch .ascii-line-6, pre.fastfetch .ascii-line-6 { color: var(--yellow); }
pre.neofetch .ascii-line-7, pre.fastfetch .ascii-line-7 { color: var(--yellow); }
pre.neofetch .ascii-line-8, pre.fastfetch .ascii-line-8 { color: var(--orange); }
pre.neofetch .ascii-line-9, pre.fastfetch .ascii-line-9 { color: var(--orange); }
pre.neofetch .ascii-line-10, pre.fastfetch .ascii-line-10 { color: var(--red); }
pre.neofetch .ascii-line-11, pre.fastfetch .ascii-line-11 { color: var(--red); }
.chat-reply { color: var(--text); white-space: pre-wrap; word-break: break-word; line-height: 1.5; user-select: text; -webkit-user-select: text; }
.chat-you { color: var(--green); font-weight: 700; }
.chat-ai { color: var(--cyan); font-weight: 700; }
.chat-code {
  display: block; background: var(--code-bg); border: 1px solid var(--border);
  border-radius: 4px; padding: 8px 12px; margin: 4px 0 8px;
  font-size: 13px; line-height: 1.4; overflow-x: auto;
  white-space: pre; position: relative;
}
.chat-code code { font: inherit; color: inherit; background: none; padding: 0; }

/* Copy button on finished code blocks */
.copy-btn {
  position: absolute; top: 5px; right: 5px;
  font: inherit; font-size: 10px; letter-spacing: .06em; text-transform: uppercase;
  background: var(--panel2); color: var(--muted);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 2px 7px; cursor: pointer;
  opacity: .7; transition: opacity .15s, color .15s, border-color .15s;
}
.chat-code:hover .copy-btn,
.copy-btn:hover,
.copy-btn:focus-visible { opacity: 1; color: var(--blue); }
.copy-btn.done { color: var(--green); border-color: var(--green); }
.chat-inline {
  background: var(--code-bg); padding: 1px 5px; border-radius: 3px;
  font-size: 13px; color: var(--yellow);
}
.chat-bold { color: var(--yellow); font-weight: 700; }
.chat-italic { color: var(--muted); font-style: italic; }
.chat-code-lang {
  display: block; font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 1px; margin-bottom: 6px;
}
.chat-h1 { color: var(--yellow); font-weight: 700; }
.chat-h2 { color: var(--blue); font-weight: 700; }
.chat-h3 { color: var(--cyan); font-weight: 700; }
.chat-quote {
  display: block; border-left: 3px solid var(--border);
  padding-left: 10px; color: var(--muted); margin: 2px 0;
}
.chat-bullet, .chat-num { color: var(--cyan); font-weight: 700; margin-right: 4px; }
.chat-task { color: var(--text); }
.chat-task.done { color: var(--muted); text-decoration: line-through; }

/* --- Chat tables --- */
.chat-table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 13px;
  line-height: 1.4;
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.chat-table th,
.chat-table td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}
.chat-table th {
  background: var(--panel2);
  color: var(--text);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1;
}
.chat-table tr:nth-child(even) td {
  background: var(--panel2);
}
.chat-table td {
  color: var(--text);
}
@media (max-width: 480px) {
  .chat-table {
    font-size: 12px;
    margin: 6px -12px;
    padding: 0 12px 6px;
    border-radius: 0;
  }
  .chat-table th,
  .chat-table td {
    padding: 5px 8px;
    min-width: max-content;
  }
}

/* --- Input (sticky footer outside the scroll area) --- */
#inputbar {
  border-top: 1px solid var(--border);
  background: var(--panel);
  padding: 10px 20px 12px;
  flex-shrink: 0;
}
#inputline { display: flex; align-items: center; gap: 6px; }
#inputline .prompt {
  flex-shrink: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.inputwrap { position: relative; flex: 1; min-width: 0; overflow: hidden; }
#cmdInput {
  width: 100%; padding: 0; background: transparent; border: none; outline: none;
  color: var(--text); font-family: inherit; font-size: 15px; caret-color: var(--blue);
  position: relative; z-index: 1;
}
#suggest {
  position: absolute; left: 0; top: 0; bottom: 0; z-index: 0;
  display: flex; align-items: center;
  color: var(--muted); opacity: .6; pointer-events: none;
  white-space: pre; overflow: hidden; visibility: hidden;
}

/* --- Suggestion list --- */
#suggestList {
  display: flex; flex-wrap: wrap; gap: 4px 12px; padding: 2px 0 6px; font-size: 13px;
}
#suggestList span {
  cursor: pointer; color: var(--blue); border-radius: 3px; padding: 0 4px;
  transition: background .12s, color .12s;
}
#suggestList span:hover { background: var(--panel2); color: var(--cyan); }
#suggestList span.active { background: var(--border); }
#suggestList:empty { display: none; }

/* --- Help list --- */
.helplist { margin: 4px 0 0; padding-left: 18px; }
.helplist li { margin: 2px 0; }

/* --- Chat welcome box --- */
.chat-welcome {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 16px;
  margin: 8px 0;
  background: var(--panel2);
}
.chat-welcome .chat-welcome-title {
  color: var(--green);
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 10px;
}
.chat-welcome-cmds {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 16px;
  font-size: 14px;
}
.chat-welcome-cmds .cmd-name { color: var(--text); }
.chat-welcome-cmds .cmd-desc { color: var(--muted); }

/* --- Chat help table --- */
.chat-help {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 16px;
  font-size: 14px;
  margin: 4px 0;
}
.chat-help .cmd-name { color: var(--text); }
.chat-help .cmd-desc { color: var(--muted); }

/* --- Tic-tac-toe visual board --- */
.ttt-board {
  display: grid;
  grid-template-columns: repeat(3, 64px);
  grid-auto-rows: 64px;
  gap: 8px;
  margin: 10px 0;
  width: max-content;
  max-width: 100%;
}
.ttt-cell {
  font: inherit;
  font-size: 26px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  padding: 0;
  transition: transform .1s, border-color .15s, color .15s;
}
.ttt-cell:not(:disabled):hover {
  border-color: var(--blue);
  color: var(--text);
  transform: scale(1.05);
}
.ttt-cell.x { color: var(--green); cursor: default; }
.ttt-cell.o { color: var(--blue); cursor: default; }
.ttt-cell:disabled { cursor: default; }
.ttt-cell.win { border-color: var(--green); box-shadow: 0 0 10px var(--green); }

/* --- Mobile --- */
@media (max-width: 480px) {
  body {
    padding: 0;
    padding-bottom: env(safe-area-inset-bottom);
    font-size: 14px;
    align-items: stretch;
    min-height: 100vh;
    min-height: 100dvh;
  }
  .wrap { max-width: 100%; flex: 1; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; min-width: 0; }
  header.site { padding: 8px 12px 0; padding-left: max(12px, env(safe-area-inset-left)); margin-bottom: 8px; }
  footer.site { padding: 0 12px 8px; padding-bottom: max(8px, env(safe-area-inset-bottom)); margin-top: 8px; gap: 12px; }
  header.site nav { gap: 8px; }
  .site .brand { font-size: 14px; }
  .site nav a { font-size: 12px; padding: 4px 0; }
  footer.site a { font-size: 12px; }
  .term { flex: 1; min-height: 0; }
  #screen {
    flex: 1 1 auto;
    height: auto;
    padding: 12px;
    min-height: 0;
    max-height: none;
  }
  .titlebar { padding: 8px 12px; flex-shrink: 0; }
  .titlebar span { display: inline; font-size: 11px; }
  .dot { width: 9px; height: 9px; }
  #inputbar {
    position: sticky;
    bottom: 0;
    padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  #cmdInput { font-size: 16px; padding: 8px 0; }
  #inputline { padding: 0; gap: 8px; }
  #inputline .prompt { max-width: 38vw; font-size: 13px; }
  .term { border-radius: 0; border-left: none; border-right: none; border-bottom: none; }
  pre { font-size: 11px; padding: 6px 8px; }
  .chat-help { font-size: 12px; gap: 2px 10px; }
  .chat-welcome { padding: 10px 12px; }
  .chat-welcome-title { font-size: 14px !important; }
  .chat-welcome-cmds { font-size: 12px; gap: 3px 10px; }
  .chat-reply { font-size: 13px; line-height: 1.5; }
  .row { font-size: 13px; }
  .ttt-board { grid-template-columns: repeat(3, 52px); grid-auto-rows: 52px; gap: 6px; }
  .ttt-cell { font-size: 22px; border-radius: 6px; }
}

@media (max-width: 360px) {
  body { font-size: 13px; }
  .site .brand { font-size: 13px; }
  #screen { padding: 10px; }
  #cmdInput { font-size: 16px; }
  #inputline .prompt { max-width: 32vw; font-size: 12px; }
  .titlebar { padding: 6px 10px; }
  .titlebar span { font-size: 10px; }
  .dot { width: 8px; height: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .theme-btn.switching { animation: none; }
}

/* Syntax highlighting for code blocks in chat */
.hl-kw { color: var(--purple); font-weight: 600; }
.hl-str { color: var(--green); }
.hl-comment { color: var(--muted); font-style: italic; }
.hl-num { color: var(--orange); }
.hl-func { color: var(--blue); }
.hl-type { color: var(--yellow); font-weight: 600; }
.hl-decorator { color: var(--cyan); }

/* Terminal text editor */
.editor-line { font-family: inherit; white-space: pre; }
.editor-cursor {
  display: inline-block;
  width: 8px;
  height: 1.2em;
  background: var(--blue);
  animation: blink 1s infinite;
  vertical-align: text-bottom;
  margin: 0 1px;
}
@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}
input[placeholder*="Editing mode"] {
  border-bottom: 2px solid var(--blue);
}

/* Prevent zoom on input focus (iOS) */
@media screen and (max-width: 768px) {
  #cmdInput {
    font-size: 16px !important;
  }
}
