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

/* ── Local fonts ── */
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 300;
  font-display: swap;
  src: url('../fonts/JetBrainsMono-300.ttf') format('truetype');
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/JetBrainsMono-400.ttf') format('truetype');
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../fonts/JetBrainsMono-500.ttf') format('truetype');
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/JetBrainsMono-700.ttf') format('truetype');
}

:root {
  /* Atom One Dark palette */
  --bg:           #282C34;
  --bg-lighter:   #2C313A;
  --bg-bar:       #21252B;
  --fg:           #ABB2BF;
  --comment:      #7F848E;
  --red:          #E06C75;
  --green:        #98C379;
  --yellow:       #D19A66;
  --blue:         #61AFEF;
  --magenta:      #C678DD;
  --cyan:         #56B6C2;
  --white:        #ABB2BF;
  --bright-white: #FFFFFF;
  --selection:    #3A3F4B;
  --border:       #3E4452;
  --footer-clearance: 72px;
  --font: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', 'SF Mono', monospace;
}

html {
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--comment) transparent;
}

body {
  font-family: var(--font);
  background-color: #1B1D23;
  background-image: url('https://www.loliapi.com/acg/');
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  background-attachment: fixed;
  color: var(--fg);
  font-size: 14px;
  line-height: 1.7;
  min-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 16px;
  padding: 24px 16px calc(var(--footer-clearance) + env(safe-area-inset-bottom));
  position: relative;
}

body::after {
  content: '';
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--footer-clearance) + 104px);
  background: linear-gradient(to bottom, transparent, rgba(27, 29, 35, 0.95));
  pointer-events: none;
  z-index: 0;
}

::selection {
  background: var(--selection);
  color: var(--bright-white);
}

/* Scrollbar: only for terminal-body */
.terminal-body::-webkit-scrollbar { width: 6px; }
.terminal-body::-webkit-scrollbar-track { background: transparent; }
.terminal-body::-webkit-scrollbar-thumb { background: var(--comment); border-radius: 3px; }
.terminal-body::-webkit-scrollbar-thumb:hover { background: var(--fg); }

/* ── Terminal window ── */
.terminal {
  width: 100%;
  max-width: 960px;
  height: 680px;
  max-height: calc(100vh - var(--footer-clearance) - 44px);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.4),
    0 2px 8px rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  background: rgba(40, 44, 52, 0.62);
  transition: none;
  position: relative;
  z-index: 1;
}

/* Maximized state */
.terminal.maximized {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 48px;
  width: 100%;
  max-width: 100%;
  height: auto;
  max-height: none;
  border-radius: 0;
  border: none;
  box-shadow: none;
  z-index: 10;
}

/* maximize animation */
.terminal.mac-maximizing {
  animation: macMaximize 0.5s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
.terminal.mac-restoring {
  animation: macRestore 0.45s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes macMaximize {
  0% {
    transform: scale(1);
    border-radius: 8px;
    opacity: 1;
  }
  15% {
    transform: scale(0.92);
    border-radius: 10px;
    opacity: 0.9;
  }
  100% {
    transform: scale(1);
    border-radius: 0;
    opacity: 1;
  }
}

@keyframes macRestore {
  0% {
    transform: scale(1);
    border-radius: 0;
    opacity: 1;
  }
  20% {
    transform: scale(0.88);
    border-radius: 4px;
    opacity: 0.85;
  }
  100% {
    transform: scale(1);
    border-radius: 8px;
    opacity: 1;
  }
}

/* ── Title bar ── */
.title-bar {
  background: rgba(33, 37, 43, 0.7);
  border-bottom: 1px solid var(--border);
  padding: 0;
  display: flex;
  align-items: center;
  height: 48px;
  user-select: none;
  -webkit-app-region: drag;
}

.title-bar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  height: 100%;
  flex-shrink: 0;
}

.title-icon {
  display: flex;
  align-items: center;
  opacity: 0.8;
}
.title-icon svg {
  width: 16px;
  height: 16px;
}

.title-bar-tabs {
  display: flex;
  align-items: stretch;
  flex: 1;
  height: 100%;
  min-width: 0;
}

.tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  font-size: 13px;
  color: var(--comment);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  position: relative;
}
.tab:hover { background: rgba(255, 255, 255, 0.04); }
.tab.active {
  color: var(--fg);
  background: var(--bg);
  border-bottom: 2px solid var(--blue);
}
.tab-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  margin-left: 4px;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
  flex-shrink: 0;
}
.tab:hover .tab-close,
.tab.active .tab-close { opacity: 0.5; }
.tab-close:hover {
  opacity: 1 !important;
  background: rgba(255, 255, 255, 0.1);
}

.title-bar-controls {
  display: flex;
  align-items: stretch;
  height: 100%;
  flex-shrink: 0;
  -webkit-app-region: no-drag;
}

.ctrl-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 100%;
  border: none;
  background: none;
  color: var(--fg);
  font-size: 11px;
  cursor: pointer;
  transition: background 0.12s;
  font-family: var(--font);
  line-height: 0;
}
.ctrl-btn svg {
  display: block;
}
.ctrl-btn:hover { background: rgba(255, 255, 255, 0.06); }
.ctrl-btn.close:hover { background: var(--red); color: var(--bright-white); }

/* ── Terminal body ── */
.terminal-body {
  background: rgba(40, 44, 52, 0.75);
  padding: 20px 20px;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ── Prompt styling ── */
.prompt {
  color: var(--comment);
  text-shadow: 0 0 3px rgba(0, 0, 0, 0.6);
}


/* ── Interactive input ── */
.input-line {
  display: flex;
  align-items: center;
  gap: 0;
  margin-top: 8px;
  position: relative;
}

#cmd-input {
  background: none;
  border: none;
  outline: none;
  color: var(--bright-white);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  flex: 1;
  caret-color: transparent;
  padding: 0;
  margin-left: 6px;
}

.cursor-block {
  position: absolute;
  width: 1ch;
  height: 1.2em;
  background: var(--blue);
  opacity: 0.7;
  pointer-events: none;
  animation: blockBlink 1s step-end infinite;
}

@keyframes blockBlink {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 0; }
}
.terminal.stdin-mode .cmd-block:last-child {
  margin-bottom: 0;
}
.terminal.stdin-mode .cmd-block:last-child .cmd-stdout:last-child,
.terminal.stdin-mode .cmd-block:last-child .cmd-stderr:last-child {
  margin-bottom: 0;
}
.input-line.stdin-mode {
  align-items: baseline;
  margin-top: 0;
  line-height: 1.2;
}
.input-line.stdin-mode #cmd-input {
  margin-left: 0;
  line-height: inherit;
  height: 1.2em;
}

#cmd-input::placeholder {
  color: var(--comment);
  opacity: 0.7;
  text-shadow: 0 0 3px rgba(0, 0, 0, 0.6);
  text-indent: 1ch;
}

#cmd-output:empty {
  display: none;
}

/* ── Thinking animation ── */
.thinking {
  color: var(--comment);
  font-style: italic;
  animation: breathe 1.5s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

/* ── Links in command output ── */
.cmd-stdout a {
  color: var(--blue);
  text-decoration: none;
  border-bottom: 1px dashed rgba(97, 175, 239, 0.4);
  transition: all 0.15s;
}
.cmd-stdout a:hover {
  color: var(--bright-white);
  border-bottom-color: var(--bright-white);
}

/* ── Skill icons in JSON output ── */
.cmd-stdout img {
  vertical-align: middle;
}

/* ── Footer (fixed at page bottom) ── */
.footer {
  position: fixed;
  bottom: 8px;
  left: 0;
  right: 0;
  text-align: center;
  color: rgba(255, 255, 255, 0.85);
  font-size: 11px;
  pointer-events: none;
  z-index: 2;
  transition: opacity 0.3s ease;
  -webkit-text-stroke: 0.5px rgba(0, 0, 0, 0.6);
  text-shadow:
    0 0 4px rgba(0, 0, 0, 0.9),
    1px 1px 2px rgba(0, 0, 0, 0.8),
    -1px -1px 2px rgba(0, 0, 0, 0.8);
}
.footer .uptime { margin-top: 2px; }

/* ── Mobile ── */
@media (max-width: 640px) {
  body {
    justify-content: flex-start;
    gap: 0;
    padding: 0 0 var(--footer-clearance);
  }
  .terminal {
    border-radius: 0;
    height: calc(100vh - var(--footer-clearance));
    max-height: calc(100vh - var(--footer-clearance));
    border: none;
  }
  .terminal-body { padding: 14px 10px; }
  body { font-size: 12px; }
  .title-bar { height: 40px; position: relative; }
  .ctrl-btn { width: 36px; font-size: 10px; }
  #cmd-input { font-size: 12px; }
  .tab { padding: 0 10px; font-size: 11px; }
  .title-bar-left { padding: 0 8px; }
}

@media (max-width: 380px) {
  .terminal-body { padding: 12px 8px; }
  body { font-size: 11px; }
  .ctrl-btn { width: 32px; }
}

/* ── Command output blocks ── */
.cmd-block { margin-bottom: 12px; }
.cmd-stdout,
.cmd-stderr {
  margin: 2px 0;
  white-space: pre-wrap;
  font-family: inherit;
  color: var(--fg);
  line-height: 1.2;
  text-shadow: 0 0 3px rgba(0, 0, 0, 0.6);
}
.cmd-stderr { color: var(--red); }
