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

:root {
  --bg: #0B0F0E;
  --bg-secondary: #111716;
  --bg-card: #111716;
  --border: #1E2A26;
  --text: #E6F2EE;
  --text-secondary: #9FB8AF;
  --text-muted: #6B857C;
  --accent: #32E78C;
  --accent-dim: rgba(50, 231, 140, 0.3);
  --purple: #6dd5a0;
  --pink: #a8e6cf;
  --green: #32E78C;
  --danger: #f87171;
  --radius: 8px;
  --font: 'SF Mono', 'Fira Code', 'Cascadia Code', 'JetBrains Mono', ui-monospace, monospace;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--bg-card);
}
.header-left { display: flex; align-items: baseline; gap: 0.75rem; }
.logo {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
}
.tag {
  font-size: .7rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  color: var(--text-muted);
}
nav {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.nav-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: .85rem;
  transition: color .15s;
}
.nav-link:hover { color: var(--accent); }

/* Wallet */
.wallet-area {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.wallet-btn {
  font-size: .75rem;
  padding: 0.35rem 0.75rem;
}
.wallet-btn.connect {
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
  border: none;
}
.wallet-btn.connect:hover { opacity: 0.85; }
.wallet-btn.disconnect {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: .7rem;
}
.wallet-account {
  color: var(--purple);
  font-size: .8rem;
  font-family: var(--font);
}

/* Main */
main {
  flex: 1;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 2rem;
}

/* Controls */
.controls { margin-bottom: 1rem; }
.contract-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.label {
  font-size: .75rem;
  color: var(--text-muted);
  font-family: var(--font);
  flex-shrink: 0;
}
.contract-row input {
  max-width: 220px;
}
.search-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  align-items: center;
}
.search-row input[type="text"] { flex: 1; }

/* Field rows + swap button */
.field-rows {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.field-rows .contract-row {
  margin-bottom: 0;
}
.swap-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 0.2rem 0.4rem;
  line-height: 1;
  transition: border-color 0.15s, color 0.15s;
  flex-shrink: 0;
}
.swap-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

input {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: .85rem;
  padding: 0.5rem 0.75rem;
  outline: none;
  transition: border-color .15s;
}
input:focus { border-color: var(--accent); }
input::placeholder { color: rgba(136,136,136,0.5); }

textarea {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: .85rem;
  padding: 0.5rem 0.75rem;
  outline: none;
  resize: vertical;
  width: 100%;
  transition: border-color .15s;
}
textarea:focus { border-color: var(--accent); }
textarea::placeholder { color: rgba(136,136,136,0.5); }

button {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: .8rem;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
button:hover {
  border-color: var(--accent-dim);
  color: var(--accent);
}
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#explore-btn {
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
  border: none;
  padding: 0.5rem 1.2rem;
}
#explore-btn:hover { opacity: 0.85; }
#explore-btn:disabled { opacity: 0.5; cursor: default; }

.tree-truncated {
  color: var(--text-muted);
  font-size: .75rem;
  font-family: var(--font);
  font-style: italic;
  padding: 0.5rem;
  border-top: 1px solid var(--border);
  margin-top: 0.5rem;
}

/* Breadcrumb */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-wrap: wrap;
  font-size: .85rem;
  font-family: var(--font);
  margin-bottom: 0.75rem;
  min-height: 1.5rem;
}
.breadcrumb .sep { color: rgba(136,136,136,0.4); }
.breadcrumb button {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0;
  font-size: .85rem;
  cursor: pointer;
}
.breadcrumb button:hover { text-decoration: underline; }
.breadcrumb .current { color: var(--text); }

/* Create button (header) */
.create-btn {
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
  border: none;
  font-size: .75rem;
  padding: 0.35rem 0.75rem;
}
.create-btn:hover { opacity: 0.85; }

/* Error bar */
.error-bar {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 0.75rem;
  align-items: center;
  justify-content: space-between;
  font-size: .85rem;
  color: var(--danger);
  font-family: var(--font);
}
.error-bar:not([hidden]) {
  display: flex;
}
#retry-btn {
  font-size: .75rem;
  color: var(--text);
}

/* Content area */
.content {
  gap: 1rem;
}
.content:not([hidden]) {
  display: flex;
}
.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  overflow: auto;
  max-height: 600px;
}
.tree-panel { flex: 1; min-width: 0; }
.detail-panel { width: 360px; flex-shrink: 0; }
/* Tree nodes */
.tree-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: .85rem;
  font-family: var(--font);
  transition: background .1s;
  width: 100%;
  text-align: left;
}
.tree-item:hover { background: var(--bg-secondary); }
.tree-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.tree-icon {
  color: var(--text-muted);
  width: 14px;
  text-align: center;
  flex-shrink: 0;
  font-size: .7rem;
}
.tree-icon.leaf { opacity: 0.5; }
.tree-name { color: var(--accent); }
.tree-name.branch { color: var(--text); }
.tree-name.near-account {
  color: var(--purple);
  cursor: pointer;
}
.tree-name.near-account:hover { text-decoration: underline; }
.tree-preview {
  color: var(--text-muted);
  margin-left: 0.25rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 300px;
  font-size: .75rem;
}
.tree-children { margin-left: 1.25rem; }
.tree-empty {
  color: var(--text-muted);
  font-size: .8rem;
  font-family: var(--font);
  padding: 1.5rem;
  line-height: 1.6;
}
.tree-empty .empty-heading {
  color: var(--text-secondary);
  font-size: .85rem;
  margin-bottom: 0.75rem;
}
.tree-empty .empty-detail {
  font-size: .75rem;
  margin-bottom: 0.5rem;
}
.tree-loading {
  color: var(--text-muted);
  font-size: .85rem;
  font-family: var(--font);
  padding: 1.5rem;
}

/* Detail panel */
.detail-path {
  color: var(--text-muted);
  font-family: var(--font);
  font-size: .75rem;
  margin-bottom: 0.75rem;
}
.detail-value {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: .75rem;
  overflow: auto;
  max-height: 300px;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 0 0 0.75rem;
}
.detail-meta {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: .75rem;
  font-family: var(--font);
}
.detail-meta .meta-label { color: var(--text-muted); }
.detail-meta .meta-value { color: var(--text-secondary); }
.detail-meta a {
  color: var(--accent);
  text-decoration: none;
}
.detail-meta a:hover { text-decoration: underline; }
.detail-meta .meta-writer { color: var(--purple); }
.detail-extra {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}
.detail-extra button {
  font-size: .7rem;
  padding: 0.2rem 0.5rem;
  margin-right: 0.3rem;
}
/* Copy buttons */
.copy-bar {
  display: flex;
  gap: 0.3rem;
  margin-top: 0.4rem;
}
.copy-btn {
  font-size: .65rem;
  padding: 0.2rem 0.5rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
}
.copy-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* Write panel */
.write-panel {
  max-height: none;
}
.write-connect-prompt {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: .85rem;
}
.write-connect-prompt button {
  margin-top: 0.75rem;
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
  border: none;
  padding: 0.5rem 1.2rem;
}
.write-connect-prompt button:hover { opacity: 0.85; }
.write-heading {
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}
.write-label {
  font-size: .75rem;
  color: var(--text-muted);
  font-family: var(--font);
  margin-right: 0.25rem;
}
.write-field {
  margin-bottom: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.write-field input {
  width: 100%;
}
.write-btn {
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
  border: none;
  padding: 0.5rem 1.5rem;
  font-size: .85rem;
}
.write-btn:hover { opacity: 0.85; }
.write-btn:disabled { opacity: 0.5; cursor: default; }
.write-status {
  margin-top: 0.75rem;
  font-size: .8rem;
  color: var(--green);
  font-family: var(--font);
}
.write-view-btn {
  background: none;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: .75rem;
  padding: 0.2rem 0.5rem;
  margin-left: 0.5rem;
}

/* Footer */
footer {
  padding: 1.5rem 2rem;
  border-top: 1px solid var(--bg-card);
}
footer p { color: var(--text-muted); font-size: .75rem; }
footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* Responsive */
@media (max-width: 768px) {
  header { padding: 0.75rem 1rem; flex-wrap: wrap; gap: 0.5rem; }
  nav { gap: 0.5rem; }
  main { padding: 1rem; }
  .content { flex-direction: column; }
  .detail-panel { width: 100%; }
  .tree-preview { max-width: 150px; }
  .search-row { flex-wrap: wrap; }
}
@media (max-width: 400px) {
  .logo { font-size: 1.3rem; }
}
