:root {
  --bg: #f9fafb;
  --panel: rgba(255, 255, 255, 0.7);
  --panel-border: rgba(255, 255, 255, 0.5);
  --line: rgba(0, 0, 0, 0.06);
  --text: #111827;
  --muted: #6b7280;
  --soft: #9ca3af;
  --navy: #111827;
  --green: #059669;
  --green-bg: #d1fae5;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --shadow: 0 10px 25px -5px rgba(0,0,0,0.03), 0 0 0 1px rgba(0,0,0,0.02);
  --shadow-hover: 0 20px 35px -10px rgba(0,0,0,0.08), 0 0 0 1px rgba(0,0,0,0.03);
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --sans: Pretendard, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--sans);
  color: var(--text);
  background: 
    radial-gradient(circle at 15% 50%, rgba(16, 185, 129, 0.04), transparent 25%),
    radial-gradient(circle at 85% 30%, rgba(59, 130, 246, 0.04), transparent 25%),
    #f9fafb;
  display: grid;
  place-items: center;
  padding: 24px;
}

button, input { font: inherit; }
button { cursor: pointer; transition: var(--transition); }
button:active { transform: scale(0.97); }

.app {
  width: min(460px, 100%);
  display: grid;
  gap: 14px;
}

.header {
  text-align: center;
  margin-bottom: 12px;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 10px;
  color: var(--muted);
  font-weight: 900;
  letter-spacing: -0.04em;
  user-select: none;
}

.main-copy {
  margin: 0 0 6px 0;
  font-size: 18px;
  font-weight: 900;
  color: var(--navy);
  letter-spacing: -0.03em;
}

.sub-copy {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
  word-break: keep-all;
}

.mini-icon {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 1px solid rgba(0,0,0,0.1);
  background: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 5px rgba(0,0,0,0.02);
}

.pixel {
  width: 17px;
  height: 17px;
  image-rendering: pixelated;
  background:
    linear-gradient(#6b7280 0 0) 5px 0 / 4px 2px no-repeat,
    linear-gradient(#9ca3af 0 0) 2px 2px / 10px 3px no-repeat,
    linear-gradient(#d1d5db 0 0) 3px 5px / 8px 5px no-repeat,
    linear-gradient(#4b5563 0 0) 1px 10px / 12px 3px no-repeat,
    linear-gradient(#9ca3af 0 0) 4px 13px / 6px 1px no-repeat;
  opacity: .8;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 18px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.section-title span:last-child {
  color: var(--soft);
  font-family: var(--mono);
  font-weight: 700;
}

.stock-list {
  display: grid;
  gap: 8px;
  min-height: 108px;
  max-height: 240px;
  overflow: auto;
  scrollbar-width: thin;
}

.stock-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.8);
  border-radius: 14px;
  padding: 12px 14px;
  transition: var(--transition);
}

.stock-item:hover {
  background: #ffffff;
  box-shadow: var(--shadow-hover);
  border-color: rgba(0,0,0,0.1);
  transform: translateY(-1px);
}

.stock-item.primary {
  border-color: var(--navy);
  background: #ffffff;
  box-shadow: 0 4px 12px rgba(0,0,0,0.04), inset 0 0 0 1px var(--navy);
}

.stock-main { min-width: 0; }

.stock-symbol {
  display: block;
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 800;
  color: var(--navy);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stock-sub {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stock-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.stock-signal {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 800;
  padding: 4px 8px;
  border-radius: 6px;
  background: #f3f4f6;
  color: var(--muted);
  transition: var(--transition);
}

.stock-signal.positive {
  background: var(--green-bg);
  color: var(--green);
}

.stock-signal.negative {
  background: var(--red-bg);
  color: var(--red);
}

.priority-btn,
.remove-btn {
  border: 0;
  background: #f3f4f6;
  color: var(--muted);
  height: 28px;
  border-radius: 8px;
  font-weight: 800;
}

.priority-btn {
  min-width: 44px;
  padding: 0 8px;
  font-size: 11px;
}

.priority-btn:hover {
  background: #e5e7eb;
  color: var(--navy);
}

.priority-btn.active {
  background: var(--navy);
  color: #fff;
}

.remove-btn {
  width: 28px;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.remove-btn:hover {
  background: var(--red-bg);
  color: var(--red);
}

.empty {
  height: 108px;
  display: grid;
  place-items: center;
  border: 1px dashed #d1d5db;
  border-radius: 14px;
  color: var(--soft);
  font-size: 13px;
  text-align: center;
  line-height: 1.5;
  background: rgba(255,255,255,0.4);
}

.input-row {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 82px;
  gap: 8px;
}

.input-wrapper {
  position: relative;
}

.input-row input {
  width: 100%;
  height: 48px;
  border: 1px solid #d1d5db;
  border-radius: 14px;
  background: #fff;
  color: var(--navy);
  padding: 0 16px;
  outline: none;
  font-size: 14px;
  font-weight: 700;
  transition: var(--transition);
}

.input-row input:focus {
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(17, 24, 39, 0.1);
}

.dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-hover);
  z-index: 10;
  max-height: 200px;
  overflow: auto;
  display: none;
}

.dropdown.show {
  display: block;
}

.dropdown-item {
  padding: 12px 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-bottom: 1px solid var(--line);
  transition: background 0.1s;
}

.dropdown-item:last-child {
  border-bottom: none;
}

.dropdown-item:hover {
  background: #f3f4f6;
}

.dropdown-item .d-symbol {
  font-family: var(--mono);
  font-weight: 800;
  font-size: 13px;
  color: var(--navy);
}

.dropdown-item .d-name {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.add-btn {
  border: 0;
  border-radius: 14px;
  background: var(--navy);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  box-shadow: 0 4px 12px rgba(17, 24, 39, 0.15);
}

.add-btn:hover {
  background: #000;
  box-shadow: 0 6px 16px rgba(17, 24, 39, 0.2);
  transform: translateY(-1px);
}

.add-btn:disabled {
  background: var(--soft);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.hint {
  margin-top: 10px;
  color: var(--soft);
  font-size: 12px;
  line-height: 1.5;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.fake-title-section {
  display: block;
  transition: var(--transition);
}

.fake-title-section.hidden {
  display: none;
}

.fake-title-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.title-chip {
  border: 1px solid #d1d5db;
  background: #fff;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}

.title-chip:hover {
  background: #f3f4f6;
}

.title-chip.active {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}

.state-btn {
  min-height: 58px;
  border: 1px solid #d1d5db;
  background: rgba(255,255,255,0.7);
  border-radius: 14px;
  color: var(--muted);
  padding: 10px;
  text-align: left;
  font-weight: 800;
  font-size: 13px;
}

.state-btn:hover {
  background: #fff;
  border-color: #9ca3af;
}

.state-btn small {
  display: block;
  margin-top: 4px;
  color: var(--soft);
  font-weight: 700;
  font-size: 11px;
  line-height: 1.3;
}

.state-btn.active {
  border-color: var(--navy);
  background: #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,0.03), inset 0 0 0 1px var(--navy);
  color: var(--navy);
}

.state-btn.active small {
  color: var(--muted);
}

.status-line {
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(0,0,0,0.02);
  border-radius: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.tab-preview {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--navy);
  font-family: var(--mono);
}

.toast {
  display: none;
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%) translateY(10px);
  background: rgba(17, 24, 39, 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: white;
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.show { 
  display: block; 
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Spinner for loading state */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 50%;
  border-top-color: #fff;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 420px) {
  body { padding: 16px; }
  .button-grid { grid-template-columns: 1fr; }
  .input-row { grid-template-columns: 1fr; }
  .add-btn { height: 48px; }
  .stock-right { gap: 6px; }
  .priority-btn { min-width: 38px; }
}
