:root {
  color-scheme: light;
  --paper: #f6f6f3;
  --ink: #101010;
  --muted: #5b5b5b;
  --panel: #ffffff;
  --line: #101010;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body.settings-standalone {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family:
    Inter, "Pretendard", "Noto Sans KR", "Noto Sans SC", "Microsoft YaHei",
    sans-serif;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

:where(.settings-root, body.settings-standalone) button {
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  font: inherit;
}

.settings-root {
  position: fixed;
  inset: 0;
  z-index: 4;
  background: var(--paper);
}

.settings-root[hidden] {
  display: none !important;
}

.settings-app {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  width: min(100%, 430px);
  margin: 0 auto;
  padding:
    calc(env(safe-area-inset-top) + 14px)
    calc(env(safe-area-inset-right) + 15px)
    calc(env(safe-area-inset-bottom) + 16px)
    calc(env(safe-area-inset-left) + 15px);
  background: var(--paper);
  opacity: 0;
  transform: translateY(24px) scale(0.985);
  transform-origin: 50% 100%;
  transition:
    opacity 260ms ease,
    transform 360ms cubic-bezier(0.18, 0.9, 0.2, 1);
}

body.is-settings-ready .settings-app {
  opacity: 1;
  transform: translateY(0) scale(1);
}

body.is-settings-leaving .settings-app {
  opacity: 0;
  transform: translateY(18px) scale(0.99);
}

.settings-top {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 38px;
  gap: 12px;
  align-items: center;
  min-height: 58px;
  padding: 0 2px 8px;
}

.settings-back {
  display: grid;
  width: 44px;
  aspect-ratio: 1;
  place-items: center;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  cursor: pointer;
  transition:
    background 160ms ease,
    transform 160ms ease;
}

.settings-back:active {
  background: #f2f2ef;
  transform: scale(0.96);
}

.settings-back:focus-visible,
.settings-row:focus-visible,
.settings-toggle-input:focus-visible + .settings-toggle {
  outline: 2px solid var(--line);
  outline-offset: 3px;
}

.settings-back-icon {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: var(--line);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.2;
}

.settings-heading {
  min-width: 0;
}

.settings-kicker {
  margin: 0 0 3px;
  color: #505050;
  font-size: 0.68rem;
  font-weight: 850;
  letter-spacing: 0;
  line-height: 1;
}

.settings-heading h1 {
  margin: 0;
  font-size: clamp(2rem, 10vw, 2.7rem);
  font-weight: 900;
  letter-spacing: 0;
  line-height: 0.95;
}

.settings-ring {
  display: block;
  width: 30px;
  aspect-ratio: 1;
  border: 1.5px solid var(--line);
  border-radius: 50%;
  background:
    linear-gradient(90deg, transparent 45%, var(--line) 45% 55%, transparent 55%),
    linear-gradient(transparent 45%, var(--line) 45% 55%, transparent 55%);
}

.settings-line-art {
  position: relative;
  min-height: 94px;
  margin: 2px 0 12px;
  border-top: 1.5px solid var(--line);
  border-bottom: 1.5px solid var(--line);
  overflow: hidden;
}

.line-phone {
  position: absolute;
  top: 16px;
  left: 18px;
  width: 46px;
  height: 62px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(var(--line), var(--line)) 50% 9px / 15px 1.5px no-repeat,
    linear-gradient(var(--line), var(--line)) 50% 52px / 18px 1.5px no-repeat;
}

.line-arc {
  position: absolute;
  border: 1.5px solid var(--line);
  border-bottom: 0;
  border-radius: 999px 999px 0 0;
}

.line-arc-a {
  right: 18px;
  bottom: 18px;
  width: 178px;
  height: 68px;
}

.line-arc-b {
  right: 68px;
  bottom: 18px;
  width: 82px;
  height: 38px;
}

.line-dot {
  position: absolute;
  width: 9px;
  aspect-ratio: 1;
  border: 1.5px solid var(--line);
  border-radius: 50%;
  background: var(--panel);
}

.line-dot-a {
  top: 20px;
  right: 42px;
}

.line-dot-b {
  right: 158px;
  bottom: 22px;
}

.settings-list {
  display: grid;
  align-content: start;
  gap: 8px;
  min-height: 0;
  overflow: auto;
  padding: 0 1px 18px;
  scrollbar-width: none;
}

.settings-list::-webkit-scrollbar {
  display: none;
}

.settings-list[hidden],
.settings-line-art[hidden],
.api-protocol-fieldset[hidden],
.api-settings-panel[hidden] {
  display: none !important;
}

.settings-row {
  position: relative;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 66px;
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  cursor: pointer;
  text-align: left;
  transition:
    background 160ms ease,
    transform 160ms ease;
}

.settings-row:active,
.settings-row.is-tapped {
  background: #f2f2ef;
  transform: scale(0.985);
}

.settings-icon {
  position: relative;
  display: block;
  width: 38px;
  aspect-ratio: 1;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: #fbfbf8;
}

.settings-icon::before,
.settings-icon::after {
  position: absolute;
  content: "";
}

.settings-icon-api::before {
  inset: 10px 7px 14px;
  border: 1.5px solid var(--line);
  border-radius: 4px;
}

.settings-icon-api::after {
  left: 12px;
  right: 12px;
  bottom: 8px;
  height: 1.5px;
  background: var(--line);
  box-shadow:
    -5px -8px 0 var(--line),
    5px -8px 0 var(--line);
}

.settings-icon-image::before {
  inset: 8px;
  border: 1.5px solid var(--line);
  border-radius: 4px;
}

.settings-icon-image::after {
  right: 9px;
  bottom: 10px;
  width: 17px;
  height: 13px;
  border-left: 1.5px solid var(--line);
  border-bottom: 1.5px solid var(--line);
  transform: skewX(-20deg);
}

.settings-icon-voice::before {
  top: 9px;
  left: 10px;
  width: 8px;
  height: 20px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
}

.settings-icon-voice::after {
  top: 13px;
  right: 9px;
  width: 11px;
  height: 11px;
  border: 1.5px solid var(--line);
  border-left: 0;
  border-radius: 0 999px 999px 0;
}

.settings-icon-data::before {
  top: 8px;
  left: 9px;
  width: 18px;
  height: 21px;
  border: 1.5px solid var(--line);
  border-radius: 50% / 18%;
}

.settings-icon-data::after {
  left: 11px;
  right: 11px;
  top: 17px;
  height: 1.5px;
  background: var(--line);
  box-shadow: 0 7px 0 var(--line);
}

.settings-icon-font::before {
  inset: 9px 8px;
  color: var(--line);
  content: "Aa";
  font-size: 0.84rem;
  font-weight: 900;
  line-height: 1.2;
}

.settings-icon-font::after {
  left: 8px;
  right: 8px;
  bottom: 9px;
  height: 1.5px;
  background: var(--line);
}

.settings-icon-push::before {
  top: 8px;
  left: 11px;
  width: 15px;
  height: 18px;
  border: 1.5px solid var(--line);
  border-radius: 999px 999px 6px 6px;
}

.settings-icon-push::after {
  left: 15px;
  bottom: 8px;
  width: 7px;
  height: 1.5px;
  background: var(--line);
}

.settings-icon-float::before {
  inset: 8px;
  border: 1.5px solid var(--line);
  border-radius: 50%;
}

.settings-icon-float::after {
  top: 8px;
  left: 17px;
  width: 1.5px;
  height: 21px;
  background: var(--line);
  box-shadow:
    -8px 8px 0 -1px var(--line),
    8px 8px 0 -1px var(--line);
}

.settings-icon-log::before {
  inset: 8px 9px;
  border: 1.5px solid var(--line);
  border-radius: 3px;
}

.settings-icon-log::after {
  left: 14px;
  right: 13px;
  top: 15px;
  height: 1.5px;
  background: var(--line);
  box-shadow:
    0 5px 0 var(--line),
    0 10px 0 var(--line);
}

.settings-icon-about::before {
  inset: 8px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
}

.settings-icon-about::after {
  top: 12px;
  left: 18px;
  width: 2px;
  height: 14px;
  background: var(--line);
  box-shadow: 0 -4px 0 var(--line);
}

.settings-copy {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.settings-title {
  overflow: hidden;
  color: var(--ink);
  font-size: 0.96rem;
  font-weight: 850;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-note {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 650;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-arrow {
  width: 9px;
  height: 9px;
  margin-right: 3px;
  border-top: 1.5px solid var(--line);
  border-right: 1.5px solid var(--line);
  transform: rotate(45deg);
}

.settings-toggle-row {
  grid-template-columns: 42px minmax(0, 1fr) 50px;
}

.settings-toggle-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.settings-toggle {
  position: relative;
  display: block;
  width: 48px;
  height: 28px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  box-shadow: inset 2px 2px 0 rgba(16, 16, 16, 0.08);
  transition:
    background 180ms ease,
    box-shadow 180ms ease;
}

.settings-toggle::before {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 18px;
  aspect-ratio: 1;
  border: 1.5px solid var(--line);
  border-radius: 50%;
  background: var(--panel);
  content: "";
  transition:
    background 180ms ease,
    transform 180ms cubic-bezier(0.18, 0.9, 0.2, 1.35);
}

.settings-toggle-input:checked + .settings-toggle {
  background: var(--line);
  box-shadow: none;
}

.settings-toggle-input:checked + .settings-toggle::before {
  background: var(--panel);
  transform: translateX(20px);
}

.api-settings-panel {
  min-height: 0;
  overflow: auto;
  padding: 0 1px 18px;
  scrollbar-width: none;
}

.api-settings-panel.is-view-entering {
  animation: api-panel-float-in 320ms cubic-bezier(0.18, 0.9, 0.2, 1) both;
}

.api-settings-panel::-webkit-scrollbar {
  display: none;
}

.api-settings-form {
  display: grid;
  gap: 10px;
}

.api-fieldset {
  display: grid;
  gap: 9px;
  margin: 0;
  padding: 12px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.api-fieldset legend {
  padding: 0 6px;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 850;
}

.api-type-group,
.api-protocol-group,
.reasoning-group {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.reasoning-group {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.api-type-option,
.api-protocol-option,
.reasoning-option {
  position: relative;
  display: grid;
  min-height: 42px;
  place-items: center;
  border: 1.5px solid var(--line);
  border-radius: 7px;
  background: #fbfbf8;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 850;
}

.api-type-option input,
.api-protocol-option input,
.reasoning-option input {
  position: absolute;
  opacity: 0;
}

.api-type-option:has(input:checked),
.api-protocol-option:has(input:checked),
.reasoning-option:has(input:checked) {
  background: var(--line);
  color: var(--panel);
}

.api-help {
  margin: 0;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 650;
  line-height: 1.45;
}

.api-field,
.api-range-field {
  display: grid;
  gap: 7px;
  padding: 12px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.api-field span,
.api-range-head {
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 850;
}

.api-field input,
.api-field select {
  width: 100%;
  min-height: 42px;
  border: 1.5px solid var(--line);
  border-radius: 7px;
  padding: 0 10px;
  background: #fbfbf8;
  color: var(--ink);
  font: inherit;
  font-size: 0.86rem;
  outline: none;
}

.api-field input:read-only {
  color: #4f4f4f;
  background:
    linear-gradient(135deg, rgba(16, 16, 16, 0.05) 25%, transparent 25% 50%, rgba(16, 16, 16, 0.05) 50% 75%, transparent 75%),
    #fbfbf8;
  background-size: 12px 12px;
}

.api-field input:focus,
.api-field select:focus,
.api-range-field input:focus-visible {
  outline: 2px solid var(--line);
  outline-offset: 2px;
}

.api-model-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 104px;
  gap: 8px;
  align-items: stretch;
}

.api-model-field {
  min-width: 0;
}

.api-switch-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 50px;
  gap: 12px;
  align-items: center;
  min-height: 66px;
  padding: 12px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  cursor: pointer;
}

.api-switch-row span:first-child {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.api-switch-row strong {
  font-size: 0.9rem;
}

.api-switch-row small,
.api-range-field small {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 650;
  line-height: 1.4;
}

.api-range-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.api-range-head output {
  min-width: 42px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  background: #fbfbf8;
  text-align: center;
}

.api-range-field input[type="range"] {
  width: 100%;
  accent-color: var(--line);
}

.api-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.api-action {
  min-height: 44px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  font-weight: 850;
  transition:
    background 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

.api-action-dark,
.api-action:active {
  background: var(--line);
  color: var(--panel);
}

.api-action:active {
  transform: scale(0.985);
}

.api-action:disabled {
  cursor: wait;
  opacity: 0.52;
}

.api-library {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.api-library-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 104px;
  gap: 10px;
  align-items: start;
}

.api-library-head h2 {
  margin: 0;
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 900;
  line-height: 1.2;
}

.api-library-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 650;
  line-height: 1.45;
}

.api-library-save {
  min-height: 38px;
  font-size: 0.78rem;
}

.api-library-list {
  display: grid;
  gap: 8px;
}

.api-library-empty {
  margin: 0;
  padding: 11px;
  border: 1.5px dashed #777;
  border-radius: 7px;
  color: var(--muted);
  background: #fbfbf8;
  font-size: 0.76rem;
  font-weight: 700;
  line-height: 1.45;
}

.api-library-item {
  display: grid;
  gap: 9px;
  padding: 10px;
  border: 1.5px solid var(--line);
  border-radius: 7px;
  background: #fbfbf8;
}

.api-library-main {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.api-library-name {
  color: var(--ink);
  font-size: 0.86rem;
  font-weight: 900;
  line-height: 1.25;
  word-break: break-word;
}

.api-library-meta,
.api-library-url,
.api-library-key {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 650;
  line-height: 1.35;
  word-break: break-all;
}

.api-library-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.api-library-button {
  min-height: 36px;
  border: 1.5px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 850;
  transition:
    background 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

.api-library-button[data-api-library-action="apply"] {
  background: var(--line);
  color: var(--panel);
}

.api-library-button[data-api-library-action="delete"] {
  border-color: #9b1c1c;
  color: #9b1c1c;
}

.api-library-button:active {
  transform: scale(0.985);
}

.api-library-button:disabled {
  cursor: wait;
  opacity: 0.52;
}

.api-action:focus-visible,
.api-library-button:focus-visible {
  outline: 2px solid var(--line);
  outline-offset: 3px;
}

.api-status {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  line-height: 1.45;
}

.api-status.is-error {
  color: #9b1c1c;
}

.api-status.is-success {
  color: #1d5f34;
}

@media (max-height: 650px) {
  .settings-line-art {
    min-height: 74px;
  }

  .line-phone {
    top: 10px;
    height: 52px;
  }

  .settings-row {
    min-height: 62px;
  }

  .api-fieldset,
  .api-field,
  .api-range-field,
  .api-switch-row {
    padding: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .api-settings-panel.is-view-entering {
    animation: none;
  }
}

@keyframes api-panel-float-in {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.985);
  }

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