:root,
[data-theme="dark"] {
  --light: #d6d4d5;
  --dark: #020002;
  --primary: #1d2850;
  --secondary: #535966;
  --info: #7a8ab7;
  --accent1: #345ec0;
  --accent2: #0080ff;
  --accent3: #a0aeb2;
  --success: #00a35d;
  --warning: #e2cb00;
  --danger: #f11900;
  --null-blue: #0080ff;
  --hover-bg: rgba(226, 203, 0, 0.15);
  --hover-border: rgba(241, 25, 0, 0.4);
  --sticky-bg: rgba(226, 203, 0, 0.25);
  --sticky-border: rgba(241, 25, 0, 0.6);
}

[data-theme="light"] {
  --light: #1a1a2e;
  --dark: #f0f1f4;
  --primary: #2d3a6e;
  --secondary: #3e4452;
  --info: #5a6a97;
  --accent1: #2a4ea0;
  --accent2: #0066cc;
  --accent3: #6e7e82;
  --success: #008a4e;
  --warning: #b8a600;
  --danger: #d01500;
  --null-blue: #0066cc;
  --hover-bg: rgba(184, 166, 0, 0.15);
  --hover-border: rgba(208, 21, 0, 0.35);
  --sticky-bg: rgba(184, 166, 0, 0.25);
  --sticky-border: rgba(208, 21, 0, 0.55);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--dark);
  color: var(--light);
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--primary);
  color: #fff;
  flex-shrink: 0;
}

header h1 {
  font-size: 1.1rem;
  font-weight: 600;
}

#format-btn {
  background: var(--accent1);
  color: #fff;
  border: none;
  padding: 4px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 5px;
}

#format-btn:hover,
#compact-btn:hover {
  opacity: 0.85;
}

#compact-btn {
  background: none;
  color: var(--light);
  border: 1px solid color-mix(in srgb, var(--light) 30%, transparent);
  padding: 4px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 5px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

#share-btn {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #fff;
  padding: 4px 14px;
  height: 32px;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 5px;
}

#share-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

#theme-btn {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

#theme-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

#workspace {
  display: flex;
  flex: 1;
  min-height: 0;
}

#input-panel {
  flex-basis: 50%;
  min-width: 15%;
  display: flex;
  flex-direction: column;
}

#input-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: color-mix(in srgb, var(--dark) 85%, var(--light));
  border-bottom: 1px solid color-mix(in srgb, var(--dark) 70%, var(--light));
  flex-shrink: 0;
}

#input-size {
  margin-left: auto;
  font-size: 0.75rem;
  opacity: 0.5;
}

#editor-wrap {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

#line-gutter {
  background: color-mix(in srgb, var(--dark) 90%, var(--light));
  color: var(--light);
  opacity: 0.4;
  font-family: inherit;
  font-size: 0.85rem;
  line-height: 20px;
  padding: 12px 0 0 0;
  text-align: right;
  overflow: hidden;
  user-select: none;
  flex-shrink: 0;
  min-width: 40px;
}

.line-number {
  padding: 0 8px 0 8px;
}

#editor-area {
  flex: 1;
  position: relative;
  min-width: 0;
}

#active-line-highlight {
  position: absolute;
  left: 0;
  right: 0;
  height: 20px;
  background: rgba(80, 180, 80, 0.25);
  pointer-events: none;
  visibility: hidden;
  z-index: 0;
}

#active-line-highlight.visible {
  visibility: visible;
}

[data-theme="light"] #active-line-highlight {
  background: color-mix(in srgb, var(--light) 8%, transparent);
}

#json-input {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--light);
  font-family: inherit;
  font-size: 0.85rem;
  padding: 12px;
  line-height: 20px;
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
}

#editor-area::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--dark);
  z-index: -1;
}

#splitter {
  width: 6px;
  flex-shrink: 0;
  background: var(--primary);
  cursor: col-resize;
  transition: background 0.15s;
}

#splitter:hover,
#splitter.active {
  background: var(--accent1);
}

#output-panel {
  flex-basis: 50%;
  min-width: 15%;
  display: flex;
  flex-direction: column;
}

#output-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: color-mix(in srgb, var(--dark) 85%, var(--light));
  border-bottom: 1px solid color-mix(in srgb, var(--dark) 70%, var(--light));
  flex-shrink: 0;
}

#output-toolbar button {
  background: none;
  color: var(--light);
  border: 1px solid color-mix(in srgb, var(--light) 30%, transparent);
  padding: 4px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 5px;
}

#output-toolbar button:hover {
  opacity: 0.85;
}

#output-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

#error-bar {
  display: none;
  background: var(--danger);
  color: #fff;
  padding: 8px 12px;
  border-radius: 4px;
  margin-bottom: 8px;
  font-size: 0.82rem;
  flex-shrink: 0;
}

#error-bar.visible {
  display: block;
}

#json-output {
  line-height: 1.6;
  font-size: 0.85rem;
}

/* JSON syntax classes */
.json-key {
  color: var(--accent3);
}

.json-string {
  color: var(--success);
}

.json-number {
  color: var(--accent2);
}

.json-bool {
  color: var(--warning);
}

.json-array-index {
  color: var(--secondary);
  opacity: 0.7;
}

.json-null {
  color: var(--null-blue);
  font-style: italic;
}

.json-bracket {
  color: var(--light);
}

.json-comma {
  color: var(--light);
}

.json-type-label {
  color: var(--light);
  opacity: 0.5;
  font-size: 0.8em;
  margin: 0 4px;
}

/* Fold/unfold toggle */
.toggle {
  display: inline-block;
  width: 1em;
  text-align: center;
  cursor: pointer;
  user-select: none;
  color: var(--light);
  opacity: 0.6;
  margin-right: 2px;
}

.toggle:hover {
  color: var(--accent2);
  opacity: 1;
}

/* Tree structure */
.json-node {
  /* wrapper for compound types */
}

.json-line {
  white-space: nowrap;
}

.json-children {
  padding-left: 20px;
}

.json-children.collapsed,
.json-closing.collapsed {
  display: none;
}

/* Hover highlight on keys and primitive values */
.json-key:hover,
.json-string:hover,
.json-number:hover,
.json-bool:hover,
.json-null:hover {
  background: var(--hover-bg);
  border: 1px solid var(--hover-border);
  border-radius: 3px;
}

/* Sticky highlight on click */
.json-sticky {
  background: var(--sticky-bg) !important;
  border: 1px solid var(--sticky-border) !important;
  border-radius: 3px;
}

/* No-select during drag */
.no-select {
  user-select: none;
  -webkit-user-select: none;
}

/* Decrypt modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-dialog {
  z-index: 101;
  background: var(--dark);
  border: 1px solid color-mix(in srgb, var(--light) 20%, transparent);
  border-radius: 8px;
  padding: 24px;
  width: 380px;
  max-width: 90vw;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  color: var(--light);
}

.modal-dialog h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.modal-dialog p {
  font-size: 0.82rem;
  opacity: 0.7;
  margin-bottom: 16px;
}

.modal-dialog input[type="password"] {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid color-mix(in srgb, var(--light) 30%, transparent);
  border-radius: 4px;
  background: color-mix(in srgb, var(--dark) 85%, var(--light));
  color: var(--light);
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
}

.modal-dialog input[type="password"]:focus {
  border-color: var(--accent2);
}

.modal-error {
  color: var(--danger);
  font-size: 0.8rem;
  min-height: 1.4em;
  margin-top: 8px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.modal-actions button {
  padding: 6px 18px;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
}

#decrypt-cancel {
  background: none;
  color: var(--light);
  border: 1px solid color-mix(in srgb, var(--light) 30%, transparent);
}

#decrypt-cancel:hover {
  opacity: 0.85;
}

#decrypt-submit {
  background: var(--accent1);
  color: #fff;
  border: none;
}

#decrypt-submit:hover {
  opacity: 0.85;
}

/* Share modal */
.modal-wide {
  width: 440px;
}

.share-step {
  margin-bottom: 12px;
}

.share-step label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 6px;
  opacity: 0.8;
}

.share-step input[type="text"] {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid color-mix(in srgb, var(--light) 30%, transparent);
  border-radius: 4px;
  background: color-mix(in srgb, var(--dark) 85%, var(--light));
  color: var(--light);
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
}

.share-step input[type="text"]:focus {
  border-color: var(--accent2);
}

.share-info {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.78rem;
  opacity: 0.6;
  line-height: 1.4;
  margin-bottom: 4px;
}

.share-info i {
  flex-shrink: 0;
  margin-top: 1px;
}

.share-disclaimer {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.78rem;
  line-height: 1.4;
  background: #3d3520;
  border: 1px solid #b54a4a;
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 8px;
  color: #e8c96d;
}

.share-disclaimer i {
  flex-shrink: 0;
  margin-top: 1px;
  color: #e8c96d;
}

.btn-primary {
  background: var(--accent1);
  color: #fff;
  border: none;
}

.btn-primary:hover {
  opacity: 0.85;
}

#share-cancel {
  background: none;
  color: var(--light);
  border: 1px solid color-mix(in srgb, var(--light) 30%, transparent);
}

#share-cancel:hover {
  opacity: 0.85;
}

.share-link-row {
  display: flex;
  gap: 6px;
}

.share-link-row input[type="text"] {
  flex: 1;
  min-width: 0;
}

.share-link-row button {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 4px;
  font-size: 1rem;
}

/* Footer */
footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  opacity: 0.5;
  padding: 8px 12px;
  flex-shrink: 0;
}

footer .ph-heart {
  color: var(--danger);
}

footer a {
  color: inherit;
  text-decoration: underline;
}

/* Drag-and-drop */

#editor-wrap {
  position: relative;
}

#editor-wrap .drop-overlay {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 10;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

#editor-wrap.drag-over .drop-overlay {
  display: flex;
}

/* Progress overlay */

.progress-overlay {
  position: absolute;
  inset: 0;
  z-index: 11;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  display: none;
}

.progress-overlay:not([hidden]) {
  display: flex;
}

.progress-box {
  background: color-mix(in srgb, var(--dark) 90%, var(--light));
  border: 1px solid color-mix(in srgb, var(--light) 15%, transparent);
  border-radius: 8px;
  padding: 20px 32px;
  min-width: 220px;
  text-align: center;
}

.progress-label {
  font-size: 0.85rem;
  color: var(--light);
  margin-bottom: 10px;
  opacity: 0.8;
}

.progress-bar {
  height: 4px;
  background: color-mix(in srgb, var(--light) 10%, transparent);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent2);
  border-radius: 2px;
  transition: width 0.2s ease;
}

.drop-overlay span {
  background: rgba(100, 220, 120, 0.15);
  border: 1px solid rgba(100, 220, 120, 0.3);
  border-radius: 8px;
  padding: 20px 36px;
  font-size: 0.9rem;
  font-weight: 600;
  color: #7eea7e;
}

/* About page */

.about-page {
  max-width: 620px;
  line-height: 1.7;
  font-size: 0.85rem;
  color: var(--light);
  opacity: 0.85;
}

.about-page h2 {
  font-size: 1.2rem;
  margin-bottom: 16px;
}

.about-page h3 {
  font-size: 0.95rem;
  margin-top: 20px;
  margin-bottom: 6px;
  color: var(--accent2);
}

.about-page p {
  margin-bottom: 10px;
}

.about-page a {
  color: var(--accent2);
  text-decoration: underline;
}

.about-author {
  margin-top: 24px;
  font-size: 0.78rem;
  opacity: 0.5;
  font-style: italic;
}
