/* latin-ext (Polish: ą ć ę ł ń ó ś ź ż and more) */
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/jetbrains-mono-400-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/jetbrains-mono-400-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* latin-ext bold */
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('fonts/jetbrains-mono-700-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* latin bold */
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('fonts/jetbrains-mono-700-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

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

body {
  background: #090c10;
  font-family: 'JetBrains Mono', 'Fira Code', Consolas, 'Courier New', monospace;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  color: #c9d1d9;
}

/* ── Window ──────────────────────────────────────────────────── */
.terminal-window {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #0d1117;
}

@media (min-width: 980px) {
  .terminal-window {
    width: min(960px, 98vw);
    height: 92vh;
    border-radius: 10px;
    box-shadow: 0 28px 90px rgba(0,0,0,.85);
    overflow: hidden;
  }
}

/* ── Titlebar ─────────────────────────────────────────────────── */
.terminal-titlebar {
  background: #161b22;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid #21262d;
  flex-shrink: 0;
}
.dot { width: 12px; height: 12px; border-radius: 50%; }
.dot-red    { background: #ff5f57; }
.dot-yellow { background: #ffbd2e; }
.dot-green  { background: #28c840; }
.terminal-title {
  color: #8b949e;
  font-size: 12px;
  margin: 0 auto;
  letter-spacing: .4px;
}

/* ── Body ────────────────────────────────────────────────────── */
.terminal-body {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 14px;
  gap: 8px;
}

/* ── Output ──────────────────────────────────────────────────── */
#output {
  flex: 1;
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.65;
  scrollbar-width: thin;
  scrollbar-color: #30363d transparent;
}
#output::-webkit-scrollbar { width: 5px; }
#output::-webkit-scrollbar-thumb { background: #30363d; border-radius: 3px; }

/* ── Input line ──────────────────────────────────────────────── */
.input-line {
  display: flex;
  align-items: center;
  border-top: 1px solid #21262d;
  padding-top: 8px;
  flex-shrink: 0;
}
#prompt { white-space: nowrap; font-size: 13px; }
#cmd-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #c9d1d9;
  font-family: inherit;
  font-size: 13px;
  caret-color: #3fb950;
}

.mobile-actions {
  display: none;
  gap: 8px;
  padding: 0 0 8px;
  border-bottom: 1px solid #21262d;
}

.qa-btn {
  border: 1px solid #30363d;
  background: #0f141b;
  color: #c9d1d9;
  font-family: inherit;
  font-size: 12px;
  line-height: 1;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.qa-enter {
  margin-left: auto;
  border-color: #3fb950;
  color: #3fb950;
}

/* ── Colors ──────────────────────────────────────────────────── */
.g  { color: #3fb950; }   /* green  */
.c  { color: #79c0ff; }   /* cyan   */
.r  { color: #f85149; }   /* red    */
.y  { color: #d29922; }   /* yellow */
.m  { color: #d2a8ff; }   /* magenta */
.b  { color: #388bfd; }   /* blue   */
.d  { color: #8b949e; }   /* dim    */
.bld { font-weight: bold; }
.ita { font-style: italic; }

/* Rich world flavor (admin WYSIWYG HTML, sanitized in game.js) */
#output .flavor-html {
  display: block;
  font-style: normal;
  color: #8b949e;
}
#output .flavor-html p { margin: 0.4em 0; }
#output .flavor-html h2,
#output .flavor-html h3,
#output .flavor-html h4 { color: #c9d1d9; margin: 0.5em 0 0.25em; font-weight: 700; }
#output .flavor-html ul,
#output .flavor-html ol { margin: 0.35em 0; padding-left: 1.35em; }
#output .flavor-html li { margin: 0.15em 0; }
#output .flavor-html a { color: #79c0ff; text-decoration: underline; }
#output .flavor-html code {
  font-family: inherit;
  background: rgba(110,118,129,.25);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-size: 0.95em;
}
#output .flavor-html pre {
  margin: 0.4em 0;
  padding: 0.5em 0.65em;
  background: rgba(110,118,129,.12);
  border-radius: 6px;
  overflow-x: auto;
  white-space: pre-wrap;
}
#output .flavor-html blockquote {
  margin: 0.4em 0;
  padding-left: 0.85em;
  border-left: 3px solid #30363d;
  color: #b1bac4;
}
#output .flavor-html hr {
  border: none;
  border-top: 1px solid #30363d;
  margin: 0.65em 0;
}

/* ── Panel ───────────────────────────────────────────────────── */
.panel {
  border: 1px solid;
  border-radius: 5px;
  margin: 5px 0;
  overflow: hidden;
}
.p-cyan   { border-color: #79c0ff; }
.p-red    { border-color: #f85149; }
.p-yellow { border-color: #d29922; }
.p-blue   { border-color: #388bfd; }
.p-green  { border-color: #3fb950; }

.panel-hd {
  padding: 4px 12px;
  font-weight: bold;
  font-size: 12px;
  border-bottom: 1px solid;
}
.p-cyan .panel-hd   { background:rgba(121,192,255,.07); color:#79c0ff; border-color:#79c0ff; }
.p-red .panel-hd    { background:rgba(248,81,73,.07);   color:#f85149; border-color:#f85149; }
.p-yellow .panel-hd { background:rgba(210,153,34,.07);  color:#d29922; border-color:#d29922; }
.p-blue .panel-hd   { background:rgba(56,139,253,.07);  color:#388bfd; border-color:#388bfd; }
.p-green .panel-hd  { background:rgba(63,185,80,.07);   color:#3fb950; border-color:#3fb950; }

.panel-bd {
  padding: 8px 12px;
  line-height: 1.65;
  white-space: pre-wrap;
}

/* ── Theory table ────────────────────────────────────────────── */
.tbl {
  width: 100%;
  border-collapse: collapse;
  margin: 5px 0;
  font-size: 12.5px;
}
.tbl th {
  background: #161b22;
  color: #79c0ff;
  padding: 5px 10px;
  text-align: left;
  border: 1px solid #21262d;
}
.tbl td {
  padding: 4px 10px;
  border: 1px solid #1c2128;
  vertical-align: top;
}
.tbl tr:nth-child(even) td { background: rgba(255,255,255,.02); }
.tbl .tc { color: #3fb950; font-weight: bold; white-space: nowrap; }
.tbl .tw { color: #c9d1d9; }
.tbl .tn { color: #8b949e; font-size: 12px; }

/* ── Footer ──────────────────────────────────────────────────── */
.terminal-footer {
  background: #161b22;
  padding: 8px 14px calc(8px + env(safe-area-inset-bottom, 0px));
  text-align: center;
  border-top: 1px solid #21262d;
  flex-shrink: 0;
  font-size: 11px;
  color: #6e7681;
  letter-spacing: .3px;
}

/* ── Misc ────────────────────────────────────────────────────── */
.cmd-out  { color: #c9d1d9; white-space: pre-wrap; margin: 2px 0; opacity: .9; }
.echo-in  { color: #8b949e; }
.sep      { color: #21262d; margin: 6px 0; }

.lang-choice {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid #30363d;
  background: transparent;
  color: #c9d1d9;
  font: inherit;
  font-size: 13px;
  padding: 0;
  cursor: pointer;
}

.lang-choice:hover,
.lang-choice:focus-visible {
  color: #e6edf3;
  outline: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.ai-toggle {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 50;
  border: 1px solid #3fb950;
  background: #0d1117;
  color: #3fb950;
  font-family: inherit;
  font-size: 12px;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.ai-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(380px, 92vw);
  height: 100vh;
  background: #0b1016;
  border-left: 1px solid #21262d;
  display: flex;
  flex-direction: column;
  z-index: 60;
  transition: transform .2s ease;
}

.ai-panel-hidden {
  transform: translateX(100%);
}

.ai-panel-header {
  border-bottom: 1px solid #21262d;
  color: #79c0ff;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
}

.ai-close {
  border: 1px solid #30363d;
  background: transparent;
  color: #8b949e;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  cursor: pointer;
}

.ai-thread {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  font-size: 12px;
  line-height: 1.5;
}

.ai-msg {
  border: 1px solid #21262d;
  border-radius: 6px;
  padding: 7px 8px;
  margin-bottom: 8px;
  white-space: pre-wrap;
}

.ai-msg-user { color: #79c0ff; }
.ai-msg-assistant { color: #c9d1d9; background: rgba(121, 192, 255, 0.04); }
.ai-msg-system { color: #8b949e; font-style: italic; }

.ai-prefix { color: #8b949e; }
.ai-inline-code { background: #161b22; color: #79c0ff; padding: 1px 5px; border-radius: 3px; font-size: 11px; }
.ai-code { background: #161b22; color: #79c0ff; padding: 6px 8px; border-radius: 4px; margin: 4px 0; font-size: 11px; overflow-x: auto; }
.ai-msg-assistant strong { color: #e6edf3; }
.ai-msg-assistant em { color: #8b949e; }

.ai-form {
  border-top: 1px solid #21262d;
  display: flex;
  gap: 8px;
  padding: 10px;
}

#ai-input {
  flex: 1;
  min-width: 0;
  background: #0d1117;
  border: 1px solid #30363d;
  color: #c9d1d9;
  font-family: inherit;
  font-size: 12px;
  border-radius: 5px;
  padding: 7px 8px;
  outline: none;
}

#ai-send {
  border: 1px solid #3fb950;
  background: transparent;
  color: #3fb950;
  font-family: inherit;
  font-size: 12px;
  border-radius: 5px;
  padding: 7px 10px;
  cursor: pointer;
}

@media (max-width: 768px) {
  body {
    align-items: stretch;
    justify-content: stretch;
    min-height: 100dvh;
  }

  .terminal-titlebar {
    padding: 10px 12px;
  }

  .terminal-title {
    font-size: 11px;
  }

  .terminal-body {
    padding: 10px;
    gap: 6px;
  }

  #output {
    font-size: 14px;
    line-height: 1.6;
    -webkit-overflow-scrolling: touch;
  }

  .mobile-actions {
    display: flex;
    flex-wrap: wrap;
  }

  .input-line {
    padding-top: 10px;
  }

  #prompt,
  #cmd-input {
    font-size: 16px; /* prevents iOS zoom on focus */
  }

  .terminal-footer {
    font-size: 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }

  .ai-toggle {
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }

  .ai-panel {
    width: 100vw;
  }
}
