:root {
  color-scheme: light;
  font-size: 16px;
  --bg: #0f172a;
  --panel: rgba(19, 27, 44, 0.78);
  --panel-blur: saturate(160%) blur(22px);
  --accent: #5d66ff;
  --accent-muted: rgba(93, 102, 255, 0.16);
  --accent-strong: rgba(93, 102, 255, 0.28);
  --text: #f8fbff;
  --text-muted: rgba(240, 244, 255, 0.68);
  --line: rgba(115, 125, 155, 0.28);
  --form-bg: rgba(13, 18, 31, 0.9);
}

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 20% -10%, rgba(93, 102, 255, 0.35), transparent 50%),
    radial-gradient(circle at 80% -5%, rgba(31, 209, 254, 0.3), transparent 55%),
    radial-gradient(circle at 50% 40%, rgba(115, 102, 255, 0.18), transparent 65%),
    var(--bg);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.5rem;
  padding: 1.5rem clamp(1.25rem, 3vw, 2.5rem);
  backdrop-filter: blur(18px);
  background: rgba(11, 15, 29, 0.78);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.6rem, 3vw, 2.2rem);
}

.brand p {
  margin: 0.3rem 0 0;
  color: var(--text-muted);
}

.brand__tag {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  background: rgba(93, 102, 255, 0.16);
  color: rgba(250, 252, 255, 0.8);
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 0.5rem;
}

.actions {
  display: inline-flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.language-switcher {
  position: relative;
}

.language-select {
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(16, 21, 38, 0.74);
  color: var(--text);
  padding: 0.55rem 1rem;
  border-radius: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  appearance: none;
  min-width: 9rem;
}

.language-select:focus {
  outline: none;
  border-color: rgba(170, 190, 255, 0.65);
  box-shadow: 0 0 0 3px rgba(93, 102, 255, 0.2);
}

.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(16, 21, 38, 0.74);
  color: var(--text);
  padding: 0.65rem 1.2rem;
  border-radius: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.action-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 255, 255, 0.3);
  box-shadow: 0 10px 30px -15px rgba(11, 9, 90, 0.8);
}

.action-btn__icon {
  width: 1.35rem;
  height: 1.35rem;
  display: block;
}

.action-btn--icon {
  padding: 0.55rem;
  border-radius: 0.85rem;
  gap: 0;
  min-width: 0;
}

.action-btn--icon .action-btn__icon {
  width: 1.4rem;
  height: 1.4rem;
}

.action-btn--icon .sr-only {
  position: absolute;
}

.action-btn__feedback {
  font-weight: 600;
  letter-spacing: 0.01em;
  display: block;
  text-align: center;
}

.action-btn--primary {
  background: linear-gradient(120deg, var(--accent), #4fd1ff);
  border: none;
}

.action-btn--success {
  background: linear-gradient(120deg, #1bd098, #55f0d0);
  border: none;
  color: #051016;
}

.action-btn--error {
  background: linear-gradient(120deg, #ff5d8f, #ff8f5d);
  border: none;
}

.layout {
  --layout-gap: clamp(1.5rem, 2vw, 2rem);
  --form-width: clamp(360px, 48vw, 560px);
  display: flex;
  align-items: stretch;
  gap: var(--layout-gap);
  padding: clamp(1.25rem, 3vw, 2.5rem);
}

.panel {
  background: var(--panel);
  backdrop-filter: var(--panel-blur);
  border-radius: 28px;
  padding: clamp(1.75rem, 4vw, 2.5rem);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 25px 60px -30px rgba(4, 9, 28, 0.7);
}

.panel h2 {
  margin-top: 0;
  font-size: 1.4rem;
  letter-spacing: 0.01em;
}

#webquest-form {
  display: grid;
  gap: 1.3rem;
}

label span,
legend {
  display: block;
  margin-bottom: 0.45rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

input,
textarea {
  width: 100%;
  background: var(--form-bg);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 0.75rem 0.95rem;
  border-radius: 0.9rem;
  font-size: 1rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  font-family: inherit;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: rgba(170, 190, 255, 0.65);
  box-shadow: 0 0 0 3px rgba(93, 102, 255, 0.2);
  transition: 0.2s;
}

textarea {
  resize: vertical;
  min-height: 120px;
}

.form-grid {
  display: grid;
  gap: 1rem;
}

.fieldset {
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 1.1rem;
  background: rgba(14, 17, 31, 0.65);
}

.fieldset__header {
  display: flex;
  align-items: center;
  gap: 1rem;
  justify-content: space-between;
  padding: 1.25rem 1.35rem 0.5rem;
}

.fieldset__header h3 {
  margin: 0;
  font-size: 1.1rem;
}

.fieldset__header--wrap {
  flex-wrap: wrap;
}

.inline-controls {
  display: flex;
  gap: 0.75rem;
  width: 100%;
  align-items: flex-start;
}

.inline-controls input,
.inline-controls textarea {
  flex: 1;
}

.inline-controls textarea {
  min-height: 120px;
  resize: vertical;
}

.chip-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 0.65rem 1rem;
  border-radius: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.18s ease;
}

.chip-btn:hover {
  transform: translateY(-1px);
}

.chip-list,
.resource-list {
  list-style: none;
  margin: 0;
  padding: 0.9rem 1.35rem 1.35rem;
  display: grid;
  gap: 0.75rem;
}

.chip {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  padding: 0.6rem 0.85rem;
  border-radius: 0.85rem;
  background: var(--accent-muted);
  font-size: 0.95rem;
  color: rgba(240, 244, 255, 0.9);
}

.chip__text {
  flex: 1;
  min-width: 0;
  word-break: break-word;
  white-space: pre-line;
}

.chip__actions {
  display: inline-flex;
  align-items: flex-start;
  gap: 0.4rem;
}

.chip__btn {
  border: none;
  border-radius: 0.65rem;
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  color: rgba(240, 244, 255, 0.9);
  background: rgba(255, 255, 255, 0.12);
  transition: transform 0.18s ease, background 0.18s ease, box-shadow 0.2s ease;
}

.chip__btn:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.18);
  box-shadow: 0 10px 20px -12px rgba(5, 7, 20, 0.6);
}

.chip__btn:focus-visible {
  outline: 2px solid rgba(141, 152, 255, 0.8);
  outline-offset: 2px;
}

.chip__btn--edit {
  background: rgba(255, 255, 255, 0.16);
  color: #0f172a;
}

.chip__btn--edit:hover {
  background: rgba(255, 255, 255, 0.22);
}

.chip__btn--delete {
  width: 1.85rem;
  min-width: 1.85rem;
  padding: 0.35rem;
  border-radius: 999px;
  font-size: 1.1rem;
  line-height: 1;
  color: rgba(240, 244, 255, 0.95);
}

.chip--editing {
  background: rgba(93, 102, 255, 0.32);
}

.chip__edit-input {
  flex: 1;
  min-width: 0;
  border: 1px solid rgba(170, 190, 255, 0.55);
  border-radius: 0.7rem;
  padding: 0.5rem 0.7rem;
  font-size: 0.95rem;
  font-family: inherit;
  background: rgba(9, 13, 26, 0.85);
  color: rgba(240, 244, 255, 0.95);
  box-shadow: 0 0 0 2px rgba(93, 102, 255, 0.2);
  resize: vertical;
  min-height: 3.25rem;
  line-height: 1.5;
}

.chip__edit-input:focus {
  outline: none;
  border-color: rgba(196, 206, 255, 0.8);
  box-shadow: 0 0 0 3px rgba(93, 102, 255, 0.28);
}

.shake {
  animation: shake 0.35s ease;
  border-color: rgba(255, 153, 153, 0.9) !important;
}

@keyframes shake {
  10% {
    transform: translateX(-4px);
  }
  30% {
    transform: translateX(4px);
  }
  50% {
    transform: translateX(-3px);
  }
  70% {
    transform: translateX(3px);
  }
  100% {
    transform: translateX(0);
  }
}

.resource-inputs {
  display: grid;
  width: 100%;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 0.75rem;
}

.resource-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.9rem;
  padding: 0.95rem 1rem;
  border-radius: 0.95rem;
  background: rgba(13, 19, 33, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.08);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.resource-item:hover {
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: 0 16px 30px -26px rgba(5, 7, 20, 0.65);
}

.resource-item__body {
  display: grid;
  gap: 0.4rem;
  min-width: 0;
}

.resource-item__body strong {
  font-size: 1rem;
}

.resource-item__body a {
  color: rgba(121, 235, 255, 0.95);
  text-decoration: none;
  font-size: 0.95rem;
  word-break: break-word;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.resource-item__body span {
  font-size: 0.92rem;
  color: rgba(240, 244, 255, 0.75);
  white-space: pre-line;
}

.resource-item__actions {
  display: inline-flex;
  flex-direction: column;
  gap: 0.45rem;
}

.resource-item__btn {
  border: none;
  border-radius: 0.65rem;
  padding: 0.45rem 0.85rem;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  background: rgba(255, 255, 255, 0.12);
  color: rgba(240, 244, 255, 0.95);
  cursor: pointer;
  transition: transform 0.18s ease, background 0.18s ease, box-shadow 0.2s ease;
}

.resource-item__btn:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.18);
  box-shadow: 0 10px 20px -12px rgba(5, 7, 20, 0.6);
}

.resource-item__btn:focus-visible {
  outline: 2px solid rgba(141, 152, 255, 0.8);
  outline-offset: 2px;
}

.resource-item__btn--delete {
  background: rgba(255, 105, 138, 0.22);
  color: rgba(255, 220, 229, 0.92);
}

.resource-item__btn--delete:hover {
  background: rgba(255, 105, 138, 0.32);
}

.resource-item--editing {
  border-color: rgba(170, 190, 255, 0.55);
  box-shadow: 0 0 0 2px rgba(93, 102, 255, 0.15);
  background: rgba(17, 23, 38, 0.78);
}

.resource-edit {
  display: grid;
  gap: 0.65rem;
}

.resource-edit__field {
  display: grid;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: rgba(240, 244, 255, 0.8);
}

.resource-edit__field span {
  font-weight: 600;
  letter-spacing: 0.01em;
}

.resource-edit__field input,
.resource-edit__field textarea {
  width: 100%;
  border-radius: 0.75rem;
  border: 1px solid rgba(170, 190, 255, 0.35);
  background: rgba(9, 13, 26, 0.88);
  color: rgba(240, 244, 255, 0.95);
  padding: 0.55rem 0.75rem;
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.resource-edit__field input:focus,
.resource-edit__field textarea:focus {
  outline: none;
  border-color: rgba(196, 206, 255, 0.8);
  box-shadow: 0 0 0 3px rgba(93, 102, 255, 0.28);
}

.resource-edit__field textarea {
  min-height: 96px;
  resize: vertical;
}

.resource-edit__actions {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.3rem;
}

.resource-edit__save,
.resource-edit__cancel {
  border: none;
  border-radius: 0.7rem;
  padding: 0.5rem 1.1rem;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.resource-edit__save {
  background: linear-gradient(120deg, var(--accent), #4fd1ff);
  color: #051016;
}

.resource-edit__cancel {
  background: rgba(255, 255, 255, 0.16);
  color: rgba(240, 244, 255, 0.92);
}

.resource-edit__save:hover,
.resource-edit__cancel:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px -18px rgba(5, 7, 20, 0.65);
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 90;
  padding: 1.5rem;
  transition: opacity 0.25s ease;
}

.modal--hidden {
  opacity: 0;
  pointer-events: none;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 6, 18, 0.7);
  backdrop-filter: blur(12px);
}

.modal__content {
  position: relative;
  max-width: min(520px, 100%);
  background: rgba(13, 20, 38, 0.92);
  border-radius: 22px;
  padding: clamp(1.5rem, 4vw, 2.25rem);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 28px 70px -32px rgba(5, 8, 24, 0.85);
  color: var(--text);
  display: grid;
  gap: 1rem;
  z-index: 1;
}

.modal__close {
  position: absolute;
  top: 0.9rem;
  right: 0.9rem;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.7);
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.2s ease, color 0.2s ease;
}

.modal__close:hover {
  transform: scale(1.08);
  color: #fff;
}

.modal__steps {
  margin: 0;
  padding-left: 1.4rem;
  display: grid;
  gap: 0.75rem;
  color: var(--text-muted);
  font-size: 0.98rem;
}

.modal__steps strong {
  color: #fff;
}

.modal__note {
  margin: 0;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.65);
  background: rgba(93, 102, 255, 0.12);
  border-radius: 0.75rem;
  padding: 0.75rem 1rem;
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.theme-fieldset {
  padding: 1.35rem 1.35rem 1.15rem;
  display: grid;
  gap: 0.9rem;
}

.theme-grid {
  display: grid;
  gap: 1rem;
}

.panel--form {
  flex: 0 0 var(--form-width);
  min-width: 320px;
}

.panel--preview {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-width: 340px;
}

.layout__resizer {
  position: relative;
  width: 12px;
  min-width: 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(93, 102, 255, 0.45), rgba(31, 209, 254, 0.45));
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  cursor: col-resize;
  outline: none;
  transition: box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.layout__resizer::before {
  content: "";
  position: absolute;
  inset: 28% 3px;
  border-radius: 999px;
  background: rgba(12, 16, 28, 0.35);
  opacity: 0.6;
  pointer-events: none;
}

.layout__resizer:hover,
.layout__resizer:focus-visible {
  border-color: rgba(255, 255, 255, 0.35);
  box-shadow: 0 0 0 3px rgba(93, 102, 255, 0.35);
}

.layout--resizing {
  cursor: col-resize;
}

.layout--resizing *,
.layout__resizer:active * {
  user-select: none !important;
}

.layout--resizing .layout__resizer {
  background: linear-gradient(180deg, rgba(93, 102, 255, 0.7), rgba(31, 209, 254, 0.7));
}

.preview-wrapper {
  display: grid;
  gap: 1rem;
  height: 100%;
  grid-template-rows: auto 1fr;
  align-content: start;
  align-items: stretch;
}

.preview-wrapper h2 {
  margin: 0;
}

#preview {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 1.2rem;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  background: #fff;
}

@media (max-width: 1180px) {
  .layout {
    flex-direction: column;
  }
  .layout__resizer {
    display: none;
  }
  .panel--form,
  .panel--preview {
    min-width: 0;
    flex: 1 1 auto;
  }
  .panel--preview {
    order: -1;
  }
  #preview {
    min-height: 460px;
  }
}

@media (max-width: 880px) {
  .resource-inputs {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }
  .inline-controls {
    flex-direction: column;
  }
}

@media (max-width: 640px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .actions {
    width: 100%;
  }
  .action-btn {
    flex: 1;
    text-align: center;
  }
  .resource-inputs {
    grid-template-columns: 1fr;
  }
}
