:root {
  --font-size: 56px;
  --container-width: 920px;
  --panel-width: 920px;
  --settings-width: 920px;
  --control-height: 38px;
  --radius: 0;
  --flash-color: #1a1a1a;
  --bg: #ffffff;
  --bg-translucent: rgba(255, 255, 255, 0.85);
  --text: #1a1a1a;
  --muted: #777777;
  --ghost: #888888;
  --surface-border: rgba(15, 23, 42, 0.12);
  --field-bg: rgba(15, 23, 42, 0.025);
  --danger: #b42318;
  --caret-color: #1a1a1a;
  --caret-x: 0px;
}

body.dark {
  --bg: #09090b;
  --bg-translucent: rgba(9, 9, 11, 0.85);
  --text: #f0f0f0;
  --muted: #a1a1aa;
  --ghost: #80808a;
  --surface-border: rgba(255, 255, 255, 0.14);
  --field-bg: rgba(255, 255, 255, 0.035);
  --danger: #ff8a80;
  --caret-color: #f0f0f0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  min-width: 760px;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Menlo", "Monaco", "Consolas", "Courier New", "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", monospace;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  opacity: 1;
  transform: scale(1);
  transition: none;
}

body.theme-ready {
  transition: background 0.5s ease, opacity 0.4s ease, transform 0.4s cubic-bezier(0.2, 0, 0, 1);
}

body.departing {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.985);
}

.shell {
  display: flex;
  align-items: center;
  min-height: 100dvh;
  padding: 0 40px;
}

form {
  width: 100%;
  display: flex;
  justify-content: center;
  z-index: 1;
}

.input-wrapper {
  position: relative;
  width: min(100%, var(--container-width));
  height: 112px;
  display: flex;
  align-items: center;
  overflow: hidden;
  font-size: var(--font-size);
  transform-origin: center;
  backface-visibility: hidden;
  transition: transform 0.18s cubic-bezier(0.2, 0, 0, 1);
  will-change: transform;
}

.recoil {
  transform: scale(0.98) translateY(2px);
}

.error-shake {
  animation: error-shake 0.22s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

.typo {
  margin: 0;
  padding: 0;
  border: 0;
  font-family: inherit;
  font-size: inherit;
  font-variant-ligatures: none;
  font-weight: 400;
  letter-spacing: 0;
  line-height: normal;
}

#q {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  padding-right: 80px;
  outline: none;
  background: transparent;
  color: var(--text);
  caret-color: transparent;
}

.idle-caret {
  position: absolute;
  left: 0;
  top: 50%;
  z-index: 3;
  width: 14px;
  height: 1.1em;
  border-radius: 0;
  background: var(--caret-color);
  box-shadow: none;
  pointer-events: none;
  transform: translate(var(--caret-x), -50%);
  transform-origin: left center;
  transition: background-color 0.2s, opacity 0.5s ease;
  will-change: transform;
}

body.panel-visible .idle-caret {
  opacity: 0 !important;
  animation: none;
  transition: none;
}

.measure {
  position: absolute;
  left: 0;
  top: 0;
  visibility: hidden;
  white-space: pre;
  pointer-events: none;
}

.panel {
  position: fixed;
  left: 50%;
  bottom: clamp(32px, 6vh, 72px);
  z-index: 10;
  width: min(var(--panel-width), calc(100vw - 80px));
  max-height: calc(100dvh - 160px);
  overflow: auto;
  padding: 30px 32px 34px;
  border: 1px solid var(--surface-border);
  border-radius: var(--radius);
  background: var(--bg-translucent);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
  color: var(--text);
  transform: translateX(-50%);
}

.panel[hidden] {
  display: none;
}

.panel:focus {
  outline: none;
}

.help-content h2 {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
}

.help-content {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(0, 0.92fr) minmax(0, 1.1fr);
  gap: 40px;
}

.help-list {
  display: grid;
  grid-template-columns: minmax(88px, max-content) minmax(0, 1fr);
  gap: 9px 14px;
  margin: 14px 0 0;
  font-size: 13px;
  line-height: 1.45;
}

.help-list dt {
  margin: 0;
  color: var(--text);
  font-weight: 700;
  white-space: nowrap;
}

.help-list dd {
  margin: 0;
  color: var(--muted);
}

.settings-panel {
  width: min(var(--settings-width), calc(100vw - 80px));
}

.settings-content {
  display: grid;
  gap: 20px;
}

.settings-group {
  margin: 0;
}

.settings-group h2 {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
}

.settings-group-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.settings-group-header h2 {
  margin: 0;
}

.choice-button {
  min-width: 74px;
  height: var(--control-height);
  padding: 0 12px;
  border: 1px solid var(--surface-border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  letter-spacing: 0;
}

.choice-button:hover,
.choice-button:focus-visible {
  border-color: var(--text);
  background: var(--text);
  color: var(--bg);
  outline: none;
}

.custom-engine-form {
  display: grid;
  grid-template-columns: 8ch 16ch minmax(0, 1fr) 96px 64px;
  gap: 12px;
  align-items: end;
  font-size: 13px;
}

.custom-engine-form label {
  display: grid;
  gap: 6px;
}

.custom-engine-form span {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.color-field {
  position: relative;
}

.custom-engine-form .color-field input {
  padding-right: 32px;
}

.color-preview-dot {
  position: absolute;
  right: 12px;
  bottom: 14px;
  width: 10px;
  height: 10px;
  border: 1px solid var(--surface-border);
  background: var(--flash-color);
  pointer-events: none;
}

.color-preview-dot.invalid {
  background: transparent;
  border-style: dashed;
}

.custom-engine-form input,
.custom-engine-row input {
  width: 100%;
  height: var(--control-height);
  border: 1px solid transparent;
  border-radius: var(--radius);
  outline: none;
  background: var(--field-bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  letter-spacing: 0;
  padding: 0 12px;
  transition: border-color 0.2s, background-color 0.2s;
}

.custom-engine-form input:hover,
.custom-engine-row input:hover {
  background: rgba(15, 23, 42, 0.05);
}

body.dark .custom-engine-form input:hover,
body.dark .custom-engine-row input:hover {
  background: rgba(255, 255, 255, 0.05);
}

.custom-engine-form input::placeholder,
.custom-engine-row input::placeholder {
  color: var(--ghost);
}

.custom-engine-form input:focus,
.custom-engine-row input:focus {
  border-color: var(--text);
  background: transparent;
  color: var(--text);
}

.custom-engine-form input:focus-visible,
.custom-engine-row input:focus-visible {
  outline: none;
}

.add-engine-button {
  min-width: 0;
  width: 64px;
  justify-self: end;
}

.custom-engine-error {
  min-height: 18px;
  margin-top: 8px;
  color: var(--danger);
  font-size: 12px;
}

.custom-engine-error:empty {
  display: none;
}

.custom-engine-list {
  display: grid;
  gap: 8px;
  margin-top: 24px;
  border-top: 1px solid var(--surface-border);
  padding-top: 20px;
}

.custom-engine-empty {
  display: flex;
  align-items: center;
  min-height: 48px;
  padding: 0 16px;
  border: 1px dashed var(--surface-border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 13px;
  background: var(--field-bg);
}

.custom-engine-row {
  display: grid;
  grid-template-columns: 8ch 16ch minmax(0, 1fr) 12ch 64px 34px;
  gap: 12px;
  align-items: center;
  min-height: 48px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--field-bg);
  color: var(--muted);
  font-size: 13px;
  transition: background-color 0.2s, transform 0.2s cubic-bezier(0.2, 0, 0, 1), border-color 0.2s, color 0.2s;
}

.custom-engine-row:hover:not(.editing) {
  background: rgba(15, 23, 42, 0.045);
  color: var(--text);
}

body.dark .custom-engine-row:hover:not(.editing) {
  background: rgba(255, 255, 255, 0.045);
}

.custom-engine-row.editing {
  animation: edit-row-in 0.16s cubic-bezier(0.2, 0, 0, 1);
  border-color: var(--text);
  background: transparent;
  color: var(--text);
}

.custom-engine-row.editing input {
  animation: edit-field-in 0.18s cubic-bezier(0.2, 0, 0, 1);
  height: 32px;
}

.custom-engine-row.editing .choice-button {
  animation: edit-field-in 0.18s cubic-bezier(0.2, 0, 0, 1);
}

.custom-engine-row strong {
  color: var(--text);
  font-weight: 700;
}

.custom-engine-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-engine-color-code {
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.edit-engine-button,
.delete-engine-button {
  min-width: 34px;
  padding: 0;
}

.edit-engine-button {
  min-width: 64px;
}

.blink {
  animation: blink 1s steps(1) infinite;
}

.flash-brand {
  animation: flash-color 0.5s cubic-bezier(0.2, 0, 0, 1) forwards;
}

@keyframes blink {
  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0;
  }
}

@keyframes flash-color {
  0% {
    background: var(--caret-color);
    transform: translate(var(--caret-x), -50%) scale(1);
  }

  40% {
    background: var(--flash-color);
    box-shadow: 0 0 60px var(--flash-color);
    transform: translate(var(--caret-x), -50%) scale(1.6, 0.7);
  }

  100% {
    background: var(--caret-color);
    transform: translate(var(--caret-x), -50%) scale(1);
  }
}

@keyframes edit-row-in {
  from {
    border-color: var(--surface-border);
    opacity: 0.76;
  }

  to {
    border-color: var(--text);
    opacity: 1;
  }
}

@keyframes edit-field-in {
  from {
    opacity: 0;
    transform: translateY(2px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes error-shake {
  0%,
  100% {
    transform: translateX(0);
  }

  20%,
  60% {
    transform: translateX(-5px);
  }

  40%,
  80% {
    transform: translateX(5px);
  }
}

@media (min-width: 1800px) {
  :root {
    --font-size: 72px;
    --container-width: 1160px;
    --panel-width: 1040px;
    --settings-width: 1040px;
  }

  .idle-caret {
    width: 18px;
  }
}

@media (max-width: 980px) {
  .panel,
  .settings-panel {
    width: calc(100vw - 48px);
  }

  .custom-engine-form {
    grid-template-columns: 76px 112px minmax(0, 1fr) 86px 54px;
    gap: 8px;
  }

  .add-engine-button {
    width: 54px;
  }

  .custom-engine-row {
    grid-template-columns: 76px 112px minmax(0, 1fr) 86px 54px 34px;
    gap: 8px;
  }
}

@media (max-height: 560px) {
  .input-wrapper {
    height: 96px;
  }

  :root {
    --font-size: 42px;
  }
}

@media (max-height: 680px) {
  body.panel-visible {
    --font-size: 42px;
  }

  body.panel-visible .shell {
    align-items: flex-start;
    padding-top: 16px;
  }

  body.panel-visible .input-wrapper {
    height: 96px;
  }
}

@media (prefers-color-scheme: dark) {
  body:not(.light-forced) {
    --bg: #09090b;
    --bg-translucent: rgba(9, 9, 11, 0.85);
    --text: #f0f0f0;
    --muted: #a1a1aa;
    --ghost: #80808a;
    --surface-border: rgba(255, 255, 255, 0.14);
    --field-bg: rgba(255, 255, 255, 0.035);
    --danger: #ff8a80;
    --caret-color: #f0f0f0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .idle-caret {
    transition: none;
  }

  body.theme-ready {
    transition: background 0.01ms;
  }
}

@media (prefers-contrast: high) {
  :root {
    --ghost: #666666;
  }

  body {
    --text: #000000;
    --caret-color: #000000;
  }

  body.dark {
    --text: #ffffff;
    --caret-color: #ffffff;
    --ghost: #999999;
  }

  .idle-caret {
    box-shadow: none;
  }
}
