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

:root {
  --scratch-purple: #855cd6;
  --scratch-purple-dark: #6b47b8;
  --scratch-orange: #ffab19;
  --scratch-blue: #4c97ff;
  --scratch-gray: #575e75;
  --scratch-light-gray: #f9f9f9;
  --scratch-border: #d9e3f2;
  --text-dark: #575e75;
  --text-light: #ffffff;
}

body {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: var(--text-dark);
  background: white;
  line-height: 1.6;
}

header {
  background: var(--scratch-purple);
  color: var(--text-light);
  padding: 16px 0;
  border-bottom: 1px solid var(--scratch-purple-dark);
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 20px;
  font-weight: bold;
  text-decoration: none;
  color: var(--text-light);
}

.header-links {
  display: flex;
  gap: 20px;
  align-items: center;
}

.header-links a {
  color: var(--text-light);
  text-decoration: none;
  font-size: 14px;
}

.header-links a:hover {
  text-decoration: underline;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 30px 20px;
}

.hero {
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 2px solid var(--scratch-border);
}

.hero h1 {
  color: var(--scratch-purple);
  font-size: 32px;
  margin-bottom: 8px;
}

.hero p {
  color: var(--text-dark);
  font-size: 16px;
}

.hashtag {
  color: var(--scratch-orange);
  font-weight: bold;
}

.input-section {
  margin-bottom: 30px;
}

.input-group {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  align-items: flex-end;
}

.input-wrapper {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dark);
}

input {
  padding: 10px 12px;
  border: 1px solid var(--scratch-border);
  border-radius: 4px;
  font-size: 14px;
  font-family: inherit;
}

input:focus {
  outline: none;
  border-color: var(--scratch-blue);
}

button {
  background: var(--scratch-purple);
  color: white;
  padding: 10px 24px;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

button:hover:not(:disabled) {
  background: var(--scratch-purple-dark);
}

button:disabled {
  background: #ccc;
  cursor: not-allowed;
}

.console {
  background: #1e1e1e;
  color: #d4d4d4;
  font-family: "Courier New", monospace;
  font-size: 13px;
  padding: 16px;
  border-radius: 4px;
  min-height: 200px;
  max-height: 400px;
  overflow-y: auto;
  margin-bottom: 30px;
  border: 1px solid #333;
  display: none;
}

.console.show {
  display: block;
}

.console-line {
  white-space: pre-wrap;
  word-break: break-word;
}

.console-line.error {
  color: #f48771;
}

.console-line.success {
  color: #89d185;
}

.console-line.info {
  color: var(--scratch-orange);
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
  margin-bottom: 30px;
  padding: 20px;
  background: var(--scratch-light-gray);
  border-radius: 4px;
  border: 1px solid var(--scratch-border);
}

.stat-card {
  text-align: center;
}

.stat-value {
  font-size: 28px;
  font-weight: bold;
  color: var(--scratch-purple);
}

.stat-label {
  font-size: 13px;
  color: var(--text-dark);
  margin-top: 4px;
}

.tree-container {
  margin-bottom: 30px;
}

.tree-card {
  background: var(--scratch-light-gray);
  border-radius: 4px;
  padding: 20px;
  border: 1px solid var(--scratch-border);
}

.tree-actions {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.tree-actions button {
  background: white;
  color: var(--text-dark);
  border: 1px solid var(--scratch-border);
  padding: 8px 16px;
  font-size: 13px;
}

.tree-actions button:hover {
  background: #f0f0f0;
  border-color: var(--scratch-purple);
}

.tree {
  background: white;
  border-radius: 4px;
  padding: 20px;
  overflow-x: auto;
  max-height: 600px;
  overflow-y: auto;
  border: 1px solid var(--scratch-border);
}

.tree ul {
  list-style: none;
  padding-left: 0;
}

.tree ul ul {
  padding-left: 24px;
  margin-top: 4px;
  border-left: 1px solid var(--scratch-border);
}

.tree li {
  margin: 8px 0;
  position: relative;
}

.tree-node {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: white;
  border-radius: 4px;
  border: 1px solid var(--scratch-border);
  cursor: pointer;
  transition: border-color 0.2s, background-color 0.2s;
}

.tree-node:hover {
  border-color: var(--scratch-purple);
}

.tree-node.popular {
  background: #f5f0ff;
  border-color: var(--scratch-purple);
  box-shadow: 0 2px 4px rgba(133, 92, 214, 0.1);
}

.tree-node.popular:hover {
  background: #ede4ff;
}

.tree-node.depth-0 {
  border-left: 3px solid var(--scratch-purple);
}
.tree-node.depth-1 {
  border-left: 3px solid var(--scratch-blue);
}
.tree-node.depth-2 {
  border-left: 3px solid var(--scratch-orange);
}
.tree-node.depth-3 {
  border-left: 3px solid #0fbd8c;
}
.tree-node.depth-4 {
  border-left: 3px solid #ff6680;
}

.node-title {
  font-weight: 600;
  color: var(--text-dark);
}

.node-author {
  color: var(--scratch-gray);
  font-size: 12px;
}

.node-count {
  background: var(--scratch-light-gray);
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 11px;
  color: var(--scratch-gray);
}

.toggle-btn {
  width: 18px;
  height: 18px;
  border-radius: 3px;
  background: var(--scratch-purple);
  color: white;
  border: none;
  cursor: pointer;
  font-size: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-weight: bold;
  padding: 0;
  line-height: 1;
}

.toggle-btn:hover {
  background: var(--scratch-purple-dark);
}

.collapsed > ul {
  display: none;
}


.info-section {
  margin-bottom: 30px;
}

.info-section h2 {
  color: var(--scratch-purple);
  font-size: 24px;
  margin-bottom: 16px;
}

.expandable {
  border: 1px solid var(--scratch-border);
  border-radius: 4px;
  margin-bottom: 12px;
}

.expandable-header {
  padding: 12px 16px;
  background: var(--scratch-light-gray);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
}

.expandable-header:hover {
  background: #f0f0f0;
}

.expandable-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--scratch-purple);
}

.expandable-icon {
  font-size: 16px;
  color: var(--scratch-gray);
  transition: transform 0.2s;
}

.expandable.active .expandable-icon {
  transform: rotate(180deg);
}

.expandable-content {
  padding: 0 16px;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.2s ease-out, padding 0.2s ease-out;
}

.expandable.active .expandable-content {
  padding: 16px;
  max-height: 1000px;
}

.expandable-content p {
  margin-bottom: 10px;
  font-size: 14px;
  color: var(--text-dark);
}

.expandable-content code {
  background: var(--scratch-light-gray);
  padding: 2px 6px;
  border-radius: 3px;
  font-family: "Courier New", monospace;
  font-size: 13px;
}

footer {
  text-align: center;
  padding: 30px 20px;
  color: var(--scratch-gray);
  font-size: 13px;
  border-top: 1px solid var(--scratch-border);
}

footer a {
  color: var(--scratch-purple);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

.sort-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: auto;
  padding: 4px 0;
}

.sort-controls label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dark);
  white-space: nowrap;
}

.sort-controls select {
  padding: 8px 32px 8px 12px;
  border: 1px solid var(--scratch-border);
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  background: white;
  color: var(--text-dark);
  cursor: pointer;
  min-width: 200px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23575e75' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.sort-controls select:focus {
  outline: none;
  border-color: var(--scratch-purple);
  box-shadow: 0 0 0 2px rgba(133, 92, 214, 0.1);
}

.sort-controls select:hover {
  border-color: var(--scratch-purple);
  background-color: #fafafa;
}

@media (max-width: 768px) {
  .hero h1 {
    font-size: 24px;
  }

  .input-group {
    flex-direction: column;
    align-items: stretch;
  }

  .stats {
    grid-template-columns: 1fr;
  }
  
  .tree-actions {
    flex-direction: column;
    align-items: stretch;
  }
  
  .sort-controls {
    margin-right: 0;
    margin-bottom: 8px;
  }
  
  .sort-controls select {
    min-width: 100%;
  }
}


@media (max-width: 768px) {
  .sort-controls {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    margin-right: 0;
    margin-bottom: 8px;
  }

  .sort-controls label {
    margin-bottom: 4px;
  }

  .sort-controls select {
    width: 100%;
    min-width: unset;
    padding: 10px 36px 10px 12px;
    background-color: #fff;
    border: 1px solid var(--scratch-border);
    border-radius: 4px;
    font-size: 14px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 12 12'%3E%3Cpath fill='%23575e75' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 12px;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
  }

  select::-ms-expand {
    display: none;
  }
}
