/* ============================================================
   hexwolf — terminal hub
   配色はこの :root で一括変更できる
   ============================================================ */

:root {
  --bg:         #0d1117;
  --bg-panel:   #10161f;
  --fg:         #c9d1d9;
  --fg-dim:     #6e7a89;
  --accent:     #7ee787;  /* プロンプト・ディレクトリ名 */
  --accent-alt: #58a6ff;  /* リンク */
  --error:      #ff7b72;
  --border:     #21262d;

  /* 本文用。日本語が混ざるのでCJK等幅を末尾のフォールバックに置く */
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
               "DejaVu Sans Mono", "Liberation Mono", "Noto Sans Mono CJK JP",
               monospace;

  /* ASCIIアート用。CJK等幅フォントはU+005C（\）を円記号の字形で描画するため、
     バナーには意図的にCJKフォントを含めないスタックを使う */
  --font-ascii: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
                "DejaVu Sans Mono", "Liberation Mono", "Courier New", monospace;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  padding: clamp(0.75rem, 3vw, 2rem);
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: clamp(0.8125rem, 0.75rem + 0.4vw, 0.95rem);
  line-height: 1.6;
}

/* 走査線風のうっすらした演出（控えめに） */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.015) 0px,
    rgba(255, 255, 255, 0.015) 1px,
    transparent 1px,
    transparent 3px
  );
  z-index: 1;
}

.terminal {
  position: relative;
  z-index: 2;
  max-width: 60rem;
  margin: 0 auto;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.5);
  transition: max-width 0.2s ease;
}

.terminal__body { padding: clamp(0.75rem, 2vw, 1.5rem); }

/* 最大化 / 最小化。どちらもボタンから class をトグルする */
.terminal--maximized { max-width: 100%; }
.terminal--minimized .terminal__body { display: none; }

/* ---------- タイトルバー ---------- */

.titlebar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.35rem 0.35rem 0.75rem;
  background: #161b22;
  border-bottom: 1px solid var(--border);
  border-radius: 5px 5px 0 0;
  user-select: none;
}

.terminal--minimized .titlebar {
  border-bottom: none;
  border-radius: 5px;
}

.titlebar__title {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  color: var(--fg-dim);
  font-size: 0.8em;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.titlebar__controls {
  flex: none;
  display: flex;
  gap: 0.15rem;
}

.wbtn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.4rem;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 3px;
  color: var(--fg-dim);
  font: inherit;
  font-size: 0.85em;
  line-height: 1;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.wbtn:hover,
.wbtn:focus-visible {
  background: rgba(255, 255, 255, 0.08);
  color: var(--fg);
  outline: none;
}

.wbtn--close:hover,
.wbtn--close:focus-visible {
  background: var(--error);
  color: #0d1117;
}

.wbtn:active { transform: translateY(1px); }

/* ---------- ヘッダー / バナー ---------- */

.terminal__header { margin-bottom: 1rem; }

.banner {
  margin: 0;
  color: var(--accent);
  font-family: var(--font-ascii);
  /* 45桁のアートが崩れないよう、狭い画面ではフォントサイズを絞る */
  font-size: clamp(0.4rem, 1.9vw, 0.875rem);
  line-height: 1.2;
  overflow-x: auto;
  white-space: pre;
}

.banner__sub {
  margin: 0.5rem 0 0;
  color: var(--fg-dim);
}

.banner__sub code {
  color: var(--accent);
  font-family: inherit;
}

/* ---------- 出力領域 ---------- */

.output {
  max-height: min(55vh, 30rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 0.25rem;
}

.output:empty { display: none; }

.line {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

/* 実行したコマンドのエコー表示 */
.line--echo {
  margin-top: 0.75rem;
  color: var(--fg-dim);
}

.line--echo .prompt { margin-right: 0.5ch; }

.line--error { color: var(--error); }
.line--dim   { color: var(--fg-dim); }

/* help の一覧 */
.help-list {
  margin: 0;
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0 1.5ch;
}

.help-list dt { color: var(--accent); }
.help-list dd { margin: 0; color: var(--fg); }

/* ls の出力 */
.ls-entry { white-space: pre-wrap; }

.ls-entry__perm { color: var(--fg-dim); }

.ls-entry__link {
  color: var(--accent-alt);
  text-decoration: none;
  border-bottom: 1px dotted currentColor;
}

.ls-entry__link:hover,
.ls-entry__link:focus-visible {
  color: var(--accent);
  background: rgba(126, 231, 135, 0.1);
  outline: none;
}

.ls-entry__desc { color: var(--fg-dim); }

/* ---------- 入力行 ---------- */

.prompt {
  color: var(--accent);
  white-space: nowrap;
  user-select: none;
}

.inputline {
  display: flex;
  align-items: center;
  gap: 0.75ch;
  margin-top: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.inputline__field {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  align-items: center;
}

.inputline__input {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  padding: 0;
  background: transparent;
  border: none;
  color: var(--fg);
  font: inherit;
  caret-color: transparent; /* 自前の点滅カーソルを使う */
  outline: none;
}

/* 入力テキストと同じ字形・字送りで幅を測るための隠し要素。
   見えないが幅は持つ必要があるので visibility: hidden を使う */
.mirror {
  position: absolute;
  top: 0;
  left: 0;
  visibility: hidden;
  font: inherit;
  letter-spacing: inherit;
  white-space: pre;
  pointer-events: none;
}

/* 文字入力位置を示すブロックカーソル。点滅はさせない。
   位置は script.js が transform で更新する */
.caret {
  position: absolute;
  top: 50%;
  left: 0;
  width: 0.6em;
  height: 1.15em;
  transform: translateY(-50%);
  background: var(--accent);
  opacity: 0.4;
  pointer-events: none;
}

/* フォーカス中は濃く。ここに入力できることを示す */
.inputline__input:focus ~ .caret { opacity: 1; }

/* ---------- ショートカットボタン ---------- */

.shortcuts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.shortcut {
  padding: 0.4rem 0.75rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--fg-dim);
  font: inherit;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background-color 0.15s;
}

.shortcut::before {
  content: "$ ";
  color: var(--accent);
}

.shortcut:hover,
.shortcut:focus-visible {
  color: var(--fg);
  border-color: var(--accent);
  background: rgba(126, 231, 135, 0.08);
  outline: none;
}

.shortcut:active { transform: translateY(1px); }

/* ---------- ユーティリティ ---------- */

.visually-hidden {
  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;
}

/* ---------- モーション配慮 ---------- */

@media (prefers-reduced-motion: reduce) {
  body::before { display: none; }
  * { transition: none !important; }
}
