@layer base, utils, components;

:root {
  --line-height: 1.5;
  --background0: #000000;
  --background1: #1a1a1a;
  --background2: #262626;
  --background3: #333333;
  --foreground0: #e8e8e8;
  --foreground1: #b8b8b8;
  --foreground2: #8a8a8a;
  --foreground3: #5a5a5a;
  --color-err: #ff6b6b;
  --color-hint: #8fa3b0;
}

:root.light {
  --background0: #ffffff;
  --background1: #f2f2f2;
  --background2: #e6e6e6;
  --background3: #d8d8d8;
  --foreground0: #141414;
  --foreground1: #3c3c3c;
  --foreground2: #5e5e5e;
  --foreground3: #8a8a8a;
  --color-hint: #5f7280;
}

body {
  display: flex; flex-direction: column;
  height: calc(100vh - 12px);
  background: var(--background0);
  color: var(--foreground0);
  font-family: "Cascadia Mono", Consolas, "Courier New",
               "Microsoft YaHei", "PingFang SC", monospace;
  margin: 6px;
  border: 3px double var(--foreground1);
  padding: 1rem 1.25rem .5rem;
  box-sizing: border-box;
  max-width: none;
  word-break: normal;
}
.site-header { position: relative; flex: 0 0 auto; }

button, input, select, textarea { font-family: inherit; font-size: inherit; }
input[type="radio"], input[type="checkbox"] {
  height: 1lh;
  vertical-align: middle;
}

/* radio/checkbox 统一 ASCII TUI 风格：( ) 未选 / (•) 单选已选 / (*) 复选已选 */
#app input[type="radio"],
#app input[type="checkbox"]:not([is="switch"]) {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  display: inline-block; position: relative;
  width: 3ch; min-width: initial;
  font-family: inherit; line-height: inherit; outline: none;
}
#app input[type="radio"]::before,
#app input[type="checkbox"]:not([is="switch"])::before {
  content: "( )";
  position: absolute; top: 0; right: 0; bottom: 0; left: 0;
  text-align: center; width: 3ch; height: 1lh;
  color: var(--foreground2);
}
#app input[type="radio"]:checked::before { content: "(•)"; color: var(--foreground0); }
#app input[type="checkbox"]:not([is="switch"]):checked::before { content: "(*)"; color: var(--foreground0); }

/* WebTUI 缺失时（断网回退）：switch 显示 [ON]/[OFF] 文本开关，保持 TUI 味 */
body.no-webtui input[type="checkbox"][is="switch"] {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  display: inline-block; position: relative;
  width: 5ch; min-width: initial;
  font-family: inherit; line-height: inherit; outline: none;
}
body.no-webtui input[type="checkbox"][is="switch"]::before {
  content: "[OFF]"; position: absolute; top: 0; right: 0; bottom: 0; left: 0;
  text-align: center; width: 5ch; height: 1lh;
  color: var(--foreground2);
}
body.no-webtui input[type="checkbox"][is="switch"]:checked::before {
  content: "[ON ]"; color: var(--foreground0);
}

.site-header h1 { margin: 0 0 .25rem; font-size: 1.25rem; }
.site-header p  { margin: 0 0 0 2ch; color: var(--foreground1); }
.header-actions { position: absolute; right: 0; top: 0; display: flex; gap: .5rem; }

.mode-row { display: flex; gap: 1rem; align-items: center; margin: .75rem 0; }
.cats { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }

.cats button[aria-pressed="true"] { background: var(--foreground0); color: var(--background0); }
.cats button[aria-pressed="false"] {
  background: transparent;
  color: var(--foreground0);
  border: 1px solid var(--foreground2);
}

#app { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.layout { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: minmax(320px, 400px) 1fr; gap: 1.25rem; }
#list { display: block; height: 100%; overflow-y: auto; }

.fn-item {
  display: block;
  width: 100%;
  box-sizing: border-box;
  height: auto;
  padding: .35rem .6rem;
  text-align: left;
  border: none;
  background: var(--background0);
  color: var(--foreground0);
  line-height: 1.5;
}

.fn-item:not(:last-child) { border-bottom: 1px dashed var(--foreground2); }
.fn-item.active { background: var(--foreground0); color: var(--background0); }
.fn-item.active .fn-name::before { content: '> '; }
.fn-name { display: block; font-weight: bold; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.fn-desc { display: block; opacity: .7; font-size: .82em; }

section#work { border: 1px solid; padding: .75rem 1rem; }

.param { margin-bottom: .9rem; }
/* 当前聚焦的参数：左侧 > 标记 + 反色 label（vim/fzf 光标行感） */
.param:focus-within { outline: 1px dashed var(--foreground2); outline-offset: 3px; }
.param:focus-within .param-label::before { content: '> '; font-weight: bold; }
.param:focus-within .param-name { background: var(--foreground0); color: var(--background0); padding: 0 .25ch; }
.param-label { margin-bottom: .25rem; }
.param-name { font-weight: bold; margin-right: .35rem; }
.param-optional { opacity: .6; font-size: .85em; }
.opt-row { display: flex; flex-wrap: wrap; gap: .35rem 1.1rem; }
.opt { display: inline-flex; align-items: center; gap: .3rem; cursor: pointer; }
.range-row { display: flex; align-items: center; gap: .6rem; }
.range-val { min-width: 3ch; }
.help { opacity: .62; font-size: .84em; margin-top: .15rem; }

#work {
  display: flex; flex-direction: column;
  height: 100%;
  min-height: 0;
}
#recipe-head { flex: 0 0 auto; }
#form-area, #wiz-mount { flex: 1 1 auto; overflow-y: auto; min-height: 0; }
#cmd-panel { flex: 0 0 auto; max-height: 42svh; overflow-y: auto; background: var(--background0); padding: .2rem 0; }
#cmd-panel h3 { margin-top: 1.25rem; }
/* 命令保持单行，超长横向滚动（终端式）；变化 token 用 .cmd-new 高亮 */
pre.cmd { white-space: pre; overflow-x: auto; padding: .6rem; border: 1px dashed; }
.cmd-new { text-decoration: underline; font-weight: bold; animation: cmd-new-flash .9s ease-out; }
@keyframes cmd-new-flash { 0% { background: var(--foreground1); } 100% { background: transparent; } }
.dollar { opacity: .55; }
.cmd-actions { margin-top: .4rem; display: flex; gap: .75rem; }
.err-line { color: var(--color-err); margin: .2rem 0; }
.hint { color: var(--color-hint); font-size: .86em; }
.cdn-warn { color: var(--color-hint); border: 1px dashed var(--color-hint); padding: .4rem .6rem; }

.wiz-progress { letter-spacing: 1px; display: flex; align-items: center; }
.wiz-explain { opacity: .8; }
.wiz-nav { display: flex; gap: .6rem; margin-top: 1rem; }
button:disabled { opacity: .55; }
.explain-list { line-height: 1.7; }
.explain-pair { font-weight: bold; }

body.wizard-mode #cats,
body.wizard-mode #list { display: none; }
body.wizard-mode .layout { grid-template-columns: 1fr; }
.wiz-fnlist { display: flex; flex-direction: column; gap: .35rem; max-width: 560px; }

body.fav-mode #cats,
body.fav-mode #list { display: none; }
body.fav-mode .layout { grid-template-columns: 1fr; }
.fav-item { margin-bottom: 1rem; }
.fav-meta { opacity: .85; margin: .3rem 0; font-size: .85em; }
.fav-actions { display: flex; gap: .5rem; margin-top: .3rem; }

#toast-host { position: fixed; right: 1rem; bottom: 1rem; display: flex;
  flex-direction: column; gap: .4rem; z-index: 9; }
.toast { border: 1px solid; padding: .35rem .7rem; background: var(--background0);
  transition: opacity .4s; }
.toast-err { color: var(--color-err); }
.toast-hint { color: var(--color-hint); }
.toast.gone { opacity: 0; }

.update-banner { position: fixed; left: 50%; bottom: 3rem; transform: translateX(-50%); z-index: 70;
  display: flex; align-items: center; gap: .75rem; padding: .5rem .9rem;
  background: var(--background0); color: var(--foreground0);
  border: 1px solid var(--foreground2);
  box-shadow: 0 0 0 3px var(--background0), 0 0 0 4px var(--foreground2); }
.update-banner .ub-msg { opacity: .9; }
.update-banner button { font-family: inherit; cursor: pointer; }
.update-banner .ub-close { opacity: .55; }

details.adv-box { margin-top: 1rem; border: 1px dashed var(--foreground2); padding: .5rem .75rem; }
details.adv-box summary { list-style: none; cursor: pointer; font-weight: bold; opacity: .85; }
details.adv-box summary::before { content: '▸ '; }
details.adv-box[open] summary::before { content: '▾ '; }
details.adv-box[open] summary { margin-bottom: .6rem; }

.welcome-steps {
  border: 1px dashed var(--foreground2);
  padding: .6rem .9rem; margin: .75rem 0;
  line-height: 1.9;
  color: var(--foreground1);
}
.welcome-steps::first-line { color: var(--foreground0); }

.section-title { display: flex; align-items: center; gap: .75ch; margin: .9rem 0 .5rem; }
.section-title [is-="separator"] { flex: 1; }
.section-title .st-label { white-space: nowrap; font-weight: bold; opacity: .9; }
.section-title .st-count { opacity: .6; }

.panel { border: 1px solid var(--foreground2); padding: .5rem .75rem; }

@keyframes tui-blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }
.cmd-cursor { animation: tui-blink 1.1s steps(1) infinite; }

.statusbar {
  flex: 0 0 auto;
  display: flex; gap: 2ch; align-items: center;
  padding: .3rem 1ch;
  border-top: 1px solid var(--foreground2);
  background: var(--background0);
  font-size: .85em;
  opacity: .85;
}
.statusbar .sb-brand { font-weight: bold; opacity: .9; }
.statusbar .sb-clock { margin-left: auto; opacity: .8; }

.about-wrap {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.about-dialog {
  display: none;
  background: var(--background0);
  color: var(--foreground0);
  pointer-events: auto;
  width: min(60ch, calc(100vw - 3rem));
  max-height: min(24lh, calc(100vh - 3rem));
  overflow: auto;
  padding: 1rem 1.25rem;
  border: 1px solid var(--foreground2);
  box-shadow: 0 0 0 3px var(--background0), 0 0 0 4px var(--foreground2);
  gap: .6rem;
}
.about-dialog.open { display: flex; flex-direction: column; }
.dim-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .65); z-index: 40; }
.header-actions { z-index: 50; }
.about-dialog a { color: var(--foreground0); text-decoration: underline dotted; }
.about-badge { width: 88px; height: 31px; object-fit: contain; margin: .2rem 0; align-self: flex-start; }
.about-close { align-self: flex-end; }

:focus-visible { outline: 2px solid var(--foreground0); outline-offset: 2px; }

::-webkit-scrollbar { width: 1ch; height: 1ch; }
::-webkit-scrollbar-track { background: var(--background1); }
::-webkit-scrollbar-thumb { background: var(--foreground2); border: 1px solid var(--background0); }
::-webkit-scrollbar-thumb:hover { background: var(--foreground0); }

.panel-box { border: 1px solid var(--foreground2); padding: .5rem .75rem; }

.err-line { animation: tui-blink 1.3s steps(1) infinite; }
pre.cmd.flash { outline: 2px solid var(--foreground0); outline-offset: 2px; }

.ascii-banner {
  margin: 0 0 .25rem; line-height: 1.15;
  font-family: "Cascadia Mono", Consolas, "Courier New", monospace;
  background: var(--background0); color: var(--foreground0);
  padding: .25rem 0;
  letter-spacing: 0;
}

@media (max-width: 768px) {
  body { height: auto; min-height: calc(100svh - 12px); }
  .layout { grid-template-columns: 1fr; gap: 1rem; }
  #list { height: auto; max-height: 40svh; }
  #work { height: auto; }
  #form-area, #wiz-mount { overflow: visible; }
  .ascii-banner { font-size: .7rem; }
  .fn-item { width: 100%; }
}
