/**
 * worldbook_app.css
 * 世界书 App - Journal/Note Fusion 重构版
 */

#app-worldbook {
  width: 100%;
  height: 100%;
}

.worldbook-app {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #F5F5F2;
  color: #1e1f24;
  font-family: Inter, -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  -webkit-font-smoothing: antialiased;
}

.worldbook-header {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: var(--header-total-height);
  padding: calc(var(--safe-area-top) + 8px) var(--spacing-md) 10px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background: color-mix(in srgb, #F5F5F2 82%, #fff 18%);
  border-bottom: 1px solid rgba(30, 31, 36, 0.08);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.worldbook-back-btn,
.worldbook-header-action {
  border: none;
  background: transparent;
  color: #2a2a32;
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  min-height: 30px;
  -webkit-tap-highlight-color: transparent;
}

.worldbook-back-btn {
  justify-self: start;
}

.worldbook-header-actions {
  justify-self: end;
  display: inline-flex;
  gap: 12px;
}

.worldbook-header-title {
  justify-self: center;
  margin: 0;
  font-family: 'Lora', Georgia, 'Times New Roman', serif;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: #1f2129;
}

.worldbook-header-title-editor {
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.worldbook-content {
  height: calc(100% - var(--header-total-height));
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px var(--spacing-md) calc(20px + var(--safe-area-bottom));
}

.worldbook-scope-segment {
  margin-bottom: 14px;
  height: 40px;
}

.segmented-control {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 40px;
  padding: 3px;
  background: #EBEAE4;
  border-radius: 999px;
}

.segmented-control button {
  position: relative;
  border: 0;
  border-radius: 999px;
  background: transparent;
  min-width: 68px;
  height: 100%;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
  color: rgba(58, 61, 73, 0.72);
  cursor: pointer;
  transition: color 180ms ease, background-color 180ms ease, box-shadow 180ms ease;
}

.segmented-control button.is-active {
  color: #2513ec;
  background: #fff;
  box-shadow: 0 1px 4px rgba(15, 16, 25, 0.1);
}

.worldbook-card-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.worldbook-card-shell {
  display: grid;
  grid-template-columns: 1fr;
  border-radius: 18px;
  overflow: hidden;
}

.worldbook-card-shell.is-editing {
  grid-template-columns: minmax(0, 1fr) 78px;
  background: transparent;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
}

.worldbook-card {
  position: relative;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  border: none;
  border-radius: 18px;
  padding: 14px;
  background: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
}

.worldbook-card-shell.is-editing .worldbook-card {
  border-radius: 18px 0 0 18px;
  box-shadow: none;
}

.worldbook-card-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: #E2E2E2;
  color: #4A4A4A;
  font-size: 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.worldbook-card-main { min-width: 0; }

.worldbook-card-title {
  font-family: 'Lora', Georgia, serif;
  font-size: 16px;
  font-weight: 700;
  color: #20212a;
  margin: 0 0 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.worldbook-card-desc,
.worldbook-card-meta {
  margin: 0;
  font-size: 12px;
  color: #767682;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.worldbook-card-meta {
  margin-top: 3px;
}

.worldbook-global-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 700;
  color: #5b4a00;
  background: #FFF0A7;
}

.worldbook-card-tap {
  position: absolute;
  inset: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.worldbook-swipe-delete {
  border: none;
  border-radius: 0 18px 18px 0;
  background: #ff3b30;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.worldbook-switch {
  --switch-w: 44px;
  --switch-h: 26px;
  position: relative;
  width: var(--switch-w);
  height: var(--switch-h);
  border: none;
  border-radius: 999px;
  background: #d1d1d6;
  transition: background-color 180ms ease;
  cursor: pointer;
  z-index: 1;
}

.worldbook-switch::after {
  content: '';
  position: absolute;
  left: 2px;
  top: 2px;
  width: calc(var(--switch-h) - 4px);
  height: calc(var(--switch-h) - 4px);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 180ms cubic-bezier(0.2, 0.8, 0.25, 1);
}

.worldbook-switch[aria-checked='true'] {
  background: #2513ec;
}

.worldbook-switch[aria-checked='true']::after {
  transform: translateX(18px);
}

.worldbook-switch-mini {
  --switch-w: 36px;
  --switch-h: 20px;
}

.worldbook-switch-mini[aria-checked='true']::after {
  transform: translateX(16px);
}

.worldbook-loading,
.worldbook-empty {
  min-height: 42vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
  color: #7f7f86;
}

.worldbook-spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid rgba(37, 19, 236, 0.2);
  border-top-color: #2513ec;
  animation: wb-spin 0.9s linear infinite;
}

@keyframes wb-spin {
  to { transform: rotate(360deg); }
}

.worldbook-editor-shell {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.worldbook-editor-paper {
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
  padding: 18px 16px 10px;
}

.worldbook-editor-title {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  margin: 0 0 8px;
  padding: 0;
  font-family: 'Lora', Georgia, serif;
  font-size: 32px;
  font-weight: 700;
  color: #1f2129;
}

.worldbook-editor-title::placeholder {
  color: #c5c2b9;
}

.worldbook-form-textarea {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  overflow: hidden;
  min-height: 240px;
  max-height: none;
  background: transparent;
  color: #262731;
  font-size: 17px;
  line-height: 1.68;
  padding: 0;
}

.worldbook-form-textarea::placeholder {
  color: #c5c2b9;
}

.worldbook-inline-stepper-row {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  margin-top: 12px;
  min-height: 36px;
  padding: 0;
}

.worldbook-form-label {
  font-size: 13px;
  font-weight: 600;
  color: #353641;
}

.worldbook-stepper {
  justify-self: end;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.52);
  border: 1px solid rgba(66, 71, 87, 0.12);
  min-height: 30px;
}

.worldbook-stepper-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: rgba(58, 65, 81, 0.86);
  font-size: 15px;
  font-weight: 300;
  cursor: pointer;
}

.worldbook-stepper-value {
  min-width: 32px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: #4A4A4A;
  font-variant-numeric: tabular-nums;
}

.worldbook-advanced-panel {
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
  overflow: hidden;
}

.worldbook-advanced-toggle {
  width: 100%;
  border: none;
  background: #fff;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  cursor: pointer;
  font-family: 'Lora', Georgia, serif;
  font-size: 16px;
  font-weight: 700;
  color: #262731;
}

.worldbook-advanced-arrow {
  font-size: 20px;
  color: rgba(38, 39, 49, 0.48);
  transition: transform 250ms cubic-bezier(0.22, 1, 0.36, 1);
}

.worldbook-advanced-panel.is-open .worldbook-advanced-arrow {
  transform: rotate(90deg);
}

.worldbook-advanced-content {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 320ms cubic-bezier(0.22, 1, 0.36, 1), opacity 220ms ease;
}

.worldbook-advanced-panel.is-open .worldbook-advanced-content {
  opacity: 1;
}

.worldbook-manual-panel {
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
  overflow: hidden;
}

.worldbook-manual-panel .worldbook-advanced-arrow {
  transition: transform 280ms cubic-bezier(0.22, 1, 0.36, 1);
}

.worldbook-manual-panel.is-open .worldbook-advanced-arrow {
  transform: rotate(90deg);
}

.worldbook-manual-content {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 360ms cubic-bezier(0.22, 1, 0.36, 1), opacity 240ms ease;
}

.worldbook-manual-panel.is-open .worldbook-manual-content {
  opacity: 1;
}

.worldbook-manual-content-inner {
  padding: 8px 16px 18px;
  background: linear-gradient(180deg, rgba(248, 248, 246, 0.98), rgba(244, 244, 241, 0.95));
}

.worldbook-manual-group {
  border-radius: 14px;
  padding: 12px;
  margin: 0 0 10px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.42);
}

.worldbook-manual-group:last-child {
  margin-bottom: 0;
}

.worldbook-manual-group-trigger {
  background: linear-gradient(180deg, rgba(169, 199, 185, 0.24), rgba(169, 199, 185, 0.16));
}

.worldbook-manual-group-injection {
  background: linear-gradient(180deg, rgba(179, 175, 204, 0.24), rgba(179, 175, 204, 0.16));
}

.worldbook-manual-group-behavior {
  background: linear-gradient(180deg, rgba(165, 194, 217, 0.24), rgba(165, 194, 217, 0.16));
}

.worldbook-manual-title {
  margin: 0 0 12px;
  padding-bottom: 8px;
  font-family: 'Lora', Georgia, 'Times New Roman', serif;
  font-size: 18px;
  font-weight: 700;
  color: #262731;
  border-bottom: 0.5px solid rgba(38, 39, 49, 0.26);
}

.worldbook-manual-item {
  margin-bottom: 16px;
}

.worldbook-manual-item:last-child {
  margin-bottom: 0;
}

.worldbook-manual-item-label {
  margin-bottom: 6px;
  font-size: 15px;
  font-weight: 600;
  color: #2f3039;
  line-height: 1.5;
}

.worldbook-manual-text {
  margin: 0 0 16px;
  color: #8E8E93;
  font-size: 14px;
  line-height: 1.8;
}

.worldbook-manual-text:last-child {
  margin-bottom: 0;
}

.worldbook-manual-key-trigger {
  color: #A9C7B9;
  font-weight: 700;
}

.worldbook-manual-key-injection {
  color: #B3AFCC;
  font-weight: 700;
}

.worldbook-manual-key-behavior {
  color: #A5C2D9;
  font-weight: 700;
}

.worldbook-manual-key-variable {
  color: #D9C5A5;
  font-weight: 700;
}

.worldbook-manual-chip {
  display: inline-block;
  padding: 0 6px;
  margin: 0 2px;
  border-radius: 6px;
  background: rgba(148, 149, 157, 0.16);
  color: #4A4A4A;
  font-size: 12px;
  line-height: 1.55;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', monospace;
}

.worldbook-form-group {
  margin: 0;
  border-radius: 0;
  box-shadow: none;
  padding: 10px;
}

.worldbook-group-triggers,
.worldbook-group-injection,
.worldbook-group-behavior {
  border-radius: 14px;
  margin: 0 0 8px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.worldbook-group-triggers {
  background: linear-gradient(180deg, #DDE5DF, #D7E0D9);
}

.worldbook-group-injection {
  background: linear-gradient(180deg, #E3DEE7, #DDD7E2);
}

.worldbook-group-behavior {
  background: linear-gradient(180deg, #DDE3E8, #D7DEE4);
}

.worldbook-group-title {
  padding: 4px 8px 8px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.worldbook-group-triggers .worldbook-group-title { color: #4E6458; }
.worldbook-group-injection .worldbook-group-title { color: #615A72; }
.worldbook-group-behavior .worldbook-group-title { color: #526372; }

.worldbook-form-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(92px, auto) 1fr;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  padding: 0 8px;
  background: transparent;
}

.worldbook-group-injection .worldbook-form-row {
  border-radius: 10px;
}

.worldbook-form-row::after { display: none; }

.worldbook-form-row-column {
  display: block;
  min-height: 0;
  padding-top: 6px;
  padding-bottom: 6px;
}

.worldbook-inline-segment {
  justify-self: end;
  display: inline-flex;
  width: auto;
  min-width: auto;
  max-width: 100%;
}

.worldbook-inline-segment[data-role='matching-mode'] {
  min-width: 140px;
}

.worldbook-inline-segment[data-role='role-segment'] {
  min-width: 220px;
}

.worldbook-select-row {
  width: 100%;
  border: none;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.55);
  text-align: left;
  cursor: pointer;
}

.worldbook-select-value {
  justify-self: end;
  color: #4A4A4A;
  font-size: 14px;
  font-weight: 600;
}

.worldbook-form-range {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 999px;
  background: rgba(37, 19, 236, 0.18);
}

.worldbook-form-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid rgba(37, 19, 236, 0.2);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.16);
}

.worldbook-range-row [data-probability-value],
.worldbook-range-row [data-scan-depth-value] {
  font-weight: 700;
  color: #2513ec;
  font-variant-numeric: tabular-nums;
}

.worldbook-form-row.is-regex-error {
  border-radius: 10px;
  background: rgba(255, 59, 48, 0.08);
}

.worldbook-tag-block {
  margin-bottom: 8px;
}

.worldbook-tag-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
}

.worldbook-tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 24px;
  margin-bottom: 8px;
}

.worldbook-tag-item,
.worldbook-tag-empty-pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
}

.worldbook-tag-item {
  gap: 4px;
}

.worldbook-tag-item-mint {
  background: #63AA8A;
  color: #fff;
}

.worldbook-tag-item-mint button {
  border: none;
  background: transparent;
  color: #fff;
  cursor: pointer;
  padding: 0;
}

.worldbook-tag-empty-pill {
  background: rgba(62, 64, 72, 0.12);
  color: rgba(46, 47, 55, 0.55);
}

.worldbook-tag-input {
  width: 100%;
  text-align: left;
  border: none;
  border-bottom: 1px solid rgba(59, 65, 81, 0.24);
  border-radius: 0;
  background: transparent;
  min-height: 30px;
  padding: 4px 2px;
  color: #2c2d35;
  outline: none;
  box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.28);
}

.worldbook-secondary-cell {
  width: 100%;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.42);
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  margin: 2px 0 4px;
  cursor: pointer;
  color: #4A4A4A;
  font-size: 13px;
  font-weight: 500;
}

.worldbook-secondary-cell-left {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.worldbook-secondary-cell-icon {
  font-size: 16px;
  color: #4A4A4A;
}

.worldbook-secondary-cell-chevron {
  font-size: 16px;
  color: #4A4A4A;
  transition: transform 240ms cubic-bezier(0.22, 1, 0.36, 1);
}

.worldbook-secondary-cell.is-open .worldbook-secondary-cell-chevron {
  transform: rotate(180deg);
}

.worldbook-sub-collapse {
  overflow: hidden;
  max-height: 0;
  transition: max-height 320ms cubic-bezier(0.22, 1, 0.36, 1);
}

.worldbook-sub-collapse.is-open {
  max-height: 560px;
}

.worldbook-sub-panel {
  margin-top: 4px;
  padding: 8px;
  border-radius: 10px;
  background: rgba(84, 92, 110, 0.12);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.worldbook-regex-hint {
  margin: 4px 0;
  font-size: 12px;
}

.worldbook-regex-ok-text { color: #218f4b; }
.worldbook-regex-error-text { color: #d93025; }

.worldbook-select-sheet-mask {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
  background: rgba(22, 23, 30, 0.24);
}

.worldbook-select-sheet {
  width: min(460px, 100%);
  border-radius: 16px;
  background: rgba(245, 245, 247, 0.82);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.18);
  padding: 8px;
}

.worldbook-select-sheet-title {
  text-align: center;
  color: rgba(31, 33, 41, 0.56);
  font-size: 13px;
  padding: 8px 6px;
}

.worldbook-select-sheet-list {
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
}

.worldbook-select-sheet-option {
  width: 100%;
  border: none;
  border-bottom: 1px solid rgba(31, 33, 41, 0.08);
  background: #fff;
  color: #20212a;
  min-height: 46px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 15px;
  cursor: pointer;
}

.worldbook-select-sheet-option:last-child { border-bottom: none; }

.worldbook-select-sheet-option.is-selected {
  color: #2513ec;
  font-weight: 700;
}

.worldbook-select-sheet-cancel {
  width: 100%;
  border: none;
  border-radius: 12px;
  min-height: 46px;
  margin-top: 8px;
  background: #fff;
  color: #2513ec;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.worldbook-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.worldbook-toolbar .worldbook-header-action {
  padding: 0 2px;
}

@media (max-width: 430px) {
  .worldbook-header-title {
    font-size: 22px;
  }

  .worldbook-editor-title {
    font-size: 28px;
  }
}
