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

:root {
  --bg:           #0f172a;
  --bg-surface:   #1e293b;
  --bg-raised:    #293548;
  --text:         #e2e8f0;
  --text-muted:   #94a3b8;
  --text-faint:   #475569;
  --border:       rgba(148,163,184,0.12);
  --border-hover: rgba(148,163,184,0.28);
  --accent:       #38bdf8;
  --accent-bg:    rgba(56,189,248,0.10);
  --accent-text:  #38bdf8;
  --hint-bg:      rgba(251,191,36,0.10);
  --hint-text:    #fbbf24;
  --none-bg:      rgba(248,113,113,0.08);
  --none-text:    #f87171;
  --new-bg:       rgba(56,189,248,0.12);
  --new-border:   rgba(56,189,248,0.3);
}

[data-theme="light"] {
  --bg:           #f1f5f9;
  --bg-surface:   #ffffff;
  --bg-raised:    #f8fafc;
  --text:         #0f172a;
  --text-muted:   #64748b;
  --text-faint:   #94a3b8;
  --border:       rgba(15,23,42,0.10);
  --border-hover: rgba(15,23,42,0.22);
  --accent:       #0284c7;
  --accent-bg:    rgba(2,132,199,0.08);
  --accent-text:  #0284c7;
  --hint-bg:      rgba(180,130,0,0.08);
  --hint-text:    #92680a;
  --none-bg:      rgba(220,38,38,0.07);
  --none-text:    #b91c1c;
  --new-bg:       rgba(2,132,199,0.08);
  --new-border:   rgba(2,132,199,0.25);
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Header ── */
.header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  gap: 12px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.back-btn {
  font-size: 12px;
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.15s;
}
.back-btn:hover { color: var(--text); }

.app-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.01em;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.hint-pill, .disc-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 11px;
  border-radius: 99px;
  border: 1px solid var(--border);
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s, opacity 0.15s;
  background: var(--bg-surface);
  color: var(--text-muted);
}

.hint-pill {
  color: var(--accent-text);
  background: var(--accent-bg);
  border-color: rgba(56,189,248,0.2);
}
.hint-pill:hover:not(:disabled) { border-color: var(--accent); }
.hint-pill:disabled { opacity: 0.45; cursor: default; }
.hint-pill.hint-full { opacity: 1; }
.hint-timer { color: var(--text-muted); }

[data-theme="light"] .hint-pill {
  border-color: rgba(2,132,199,0.2);
}

.disc-pill:hover { border-color: var(--border-hover); color: var(--text); }

.theme-btn {
  width: 30px;
  height: 30px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  cursor: pointer;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s;
}
.theme-btn:hover { border-color: var(--border-hover); }

.reset-btn {
  width: 100%;
  padding: 8px 0;
  border-radius: 8px;
  border: 1px solid rgba(248,113,113,0.25);
  background: rgba(248,113,113,0.06);
  color: #f87171;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.reset-btn:hover {
  border-color: rgba(248,113,113,0.45);
  background: rgba(248,113,113,0.12);
}
[data-theme="light"] .reset-btn {
  border-color: rgba(185,28,28,0.2);
  background: rgba(185,28,28,0.05);
  color: #b91c1c;
}
[data-theme="light"] .reset-btn:hover {
  border-color: rgba(185,28,28,0.35);
  background: rgba(185,28,28,0.1);
}

/* ── Layout ── */
.main {
  display: grid;
  grid-template-columns: 1fr 272px;
  height: calc(100vh - 48px);
  margin-top: 48px;
}

/* ── Elements panel ── */
.panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  min-height: 0;
}

.search {
  width: 100%;
  padding: 7px 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}
.search:focus { border-color: var(--border-hover); }
.search::placeholder { color: var(--text-faint); }

.elements-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-content: flex-start;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, color 0.12s;
  white-space: nowrap;
}
.chip:hover {
  border-color: var(--border-hover);
  background: var(--bg-raised);
}
.chip.sel-a, .chip.sel-b {
  border-color: var(--accent);
  background: var(--accent-bg);
  color: var(--accent-text);
}

/* ── Workspace ── */
.workspace {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  min-height: 0;
}

.ws-block {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ws-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.ws-divider {
  height: 1px;
  background: var(--border);
  flex-shrink: 0;
}

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

.slot {
  flex: 1;
  height: 65px;
  flex-shrink: 0;
  overflow: hidden;
  border-radius: 8px;
  border: 1px dashed var(--border-hover);
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  transition: border-color 0.15s, background 0.15s;
  overflow: hidden;
  padding: 6px 8px;
}
.slot.filled {
  border-style: solid;
  border-color: var(--border-hover);
  background: var(--bg-raised);
}

.slot-empty { color: var(--text-faint); font-style: italic; text-align: center; }
.slot-content { color: var(--text); font-size: 13px; }

.plus {
  font-size: 16px;
  color: var(--text-faint);
  flex-shrink: 0;
}

.slot-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.combine-btn {
  flex: 1;
  padding: 7px 0;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent-bg);
  color: var(--accent-text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  letter-spacing: 0.01em;
}
.combine-btn:hover:not(:disabled) { background: rgba(56,189,248,0.18); }
.combine-btn:disabled {
  opacity: 0.35;
  cursor: default;
  border-color: var(--border);
  color: var(--text-faint);
  background: transparent;
}
[data-theme="light"] .combine-btn { border-color: var(--accent); }
[data-theme="light"] .combine-btn:disabled { border-color: var(--border); }

.clear-btn {
  font-size: 11px;
  font-family: inherit;
  color: var(--text-faint);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color 0.15s;
  white-space: nowrap;
}
.clear-btn:hover { color: var(--text-muted); }

/* ── Result area ── */
.result-area {
  height: 110px;
  flex-shrink: 0;
  overflow: hidden;
}

.result-idle, .result-none, .result-hint {
  padding: 12px;
  border-radius: 8px;
  font-size: 12px;
}
.result-idle {
  color: var(--text-faint);
  font-style: italic;
}
.result-none {
  background: var(--none-bg);
  color: var(--none-text);
}
.result-hint {
  background: var(--hint-bg);
  color: var(--hint-text);
  font-weight: 500;
}

@keyframes badge-pop {
  0%   { transform: scale(0.5); opacity: 0; }
  70%  { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1);   opacity: 1; }
}

@keyframes border-pulse {
  0%   { box-shadow: 0 0 0 0   rgba(56,189,248,0.7); }
  100% { box-shadow: 0 0 0 14px rgba(56,189,248,0); }
}

@keyframes page-flash {
  0%   { opacity: 0; }
  15%  { opacity: 1; }
  100% { opacity: 0; }
}

.discovery-flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 500;
}
.discovery-flash.active { animation: page-flash 0.9s ease-out forwards; }

.discovery-flash.flash-blue   { background: rgba(34,197,94,0.09); }
.discovery-flash.flash-red    { background: rgba(248,113,113,0.13); }
.discovery-flash.flash-orange { background: rgba(250,204,21,0.09); }

[data-theme="light"] .discovery-flash.flash-blue   { background: rgba(21,128,61,0.07); }
[data-theme="light"] .discovery-flash.flash-red    { background: rgba(185,28,28,0.10); }
[data-theme="light"] .discovery-flash.flash-orange { background: rgba(202,138,4,0.07); }

.result-card {
  border-radius: 8px;
  padding: 11px 13px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
}
.result-card.result-new {
  background: var(--new-bg);
  border-color: var(--new-border);
  animation: border-pulse 0.7s ease-out;
}

.result-card.result-new .new-badge {
  animation: badge-pop 0.4s ease-out 0.2s both;
}

.result-emoji { font-size: 22px; flex-shrink: 0; line-height: 1.3; }
.result-info { flex: 1; min-width: 0; }
.result-name { font-size: 13px; font-weight: 600; color: var(--text); }
.result-desc {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: calc(11px * 1.4 * 3);
}

.new-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 99px;
  background: var(--accent);
  color: #0f172a;
  flex-shrink: 0;
  align-self: flex-start;
}

/* ── History ── */
.history { display: flex; flex-direction: column; gap: 5px; }
.history-empty { font-size: 12px; color: var(--text-faint); font-style: italic; }
.history-row {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted);
}
.hist-sep { color: var(--text-faint); }
.hist-name { color: var(--text); margin-left: 2px; }

/* ── Modal ── */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-backdrop.open { display: flex; }

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-hover);
  border-radius: 12px;
  width: 100%;
  max-width: 680px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 16px 18px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.modal-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
}
.modal-close {
  width: 26px;
  height: 26px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s;
}
.modal-close:hover { border-color: var(--border-hover); color: var(--text); }

.modal-body {
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-tier {}
.tier-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 7px;
}
.tier-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.modal-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-family: inherit;
  white-space: nowrap;
}
.modal-chip.found {
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text);
  cursor: default;
  transition: border-color 0.12s, background 0.12s;
}
.modal-chip.found:hover {
  border-color: var(--border-hover);
  background: var(--bg-surface);
}
.modal-chip.hidden {
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--text-faint);
  font-style: italic;
  letter-spacing: 0.04em;
  cursor: default;
}

/* ── Dev button ── */
.dev-btn {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-faint);
  font-family: inherit;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.dev-btn:hover { border-color: var(--border-hover); color: var(--text-muted); }

/* ── Dev modal ── */
.dev-modal { max-width: 460px; }
.dev-body { padding: 6px 0 4px; }
.dev-section { padding: 10px 18px; }
.dev-section + .dev-section { border-top: 1px solid var(--border); }
.dev-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 10px;
}
.dev-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
}
.dev-row + .dev-row { border-top: 1px solid var(--border); }
.dev-row-info { flex: 1; min-width: 0; }
.dev-row-name { font-size: 13px; color: var(--text); }
.dev-row-desc { font-size: 11px; color: var(--text-muted); margin-top: 1px; }
.dev-action-btn {
  padding: 4px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s;
  flex-shrink: 0;
}
.dev-action-btn:hover { border-color: var(--border-hover); color: var(--text); }
.dev-select {
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  flex-shrink: 0;
}

/* ── Reset modal ── */
.reset-modal {
  max-width: 360px;
}
.reset-body {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 18px;
  font-size: 13px;
  color: var(--hint-text);
  background: var(--hint-bg);
  line-height: 1.55;
  border-top: 1px solid rgba(251,191,36,0.15);
  border-bottom: 1px solid rgba(251,191,36,0.15);
}
[data-theme="light"] .reset-body {
  border-color: rgba(180,130,0,0.15);
}
.reset-warning-icon { flex-shrink: 0; font-size: 15px; margin-top: 1px; }
.reset-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
}
.reset-cancel {
  padding: 6px 14px;
  border-radius: 7px;
  font-size: 13px;
  font-family: inherit;
  border: 1px solid var(--border-hover);
  background: var(--bg-raised);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.reset-cancel:hover { border-color: var(--border-hover); background: var(--bg-surface); }
.reset-confirm {
  padding: 6px 14px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  border: 1px solid rgba(248,113,113,0.4);
  background: rgba(248,113,113,0.1);
  color: #f87171;
  cursor: pointer;
  transition: background 0.15s;
}
.reset-confirm:hover { background: rgba(248,113,113,0.18); }
[data-theme="light"] .reset-confirm {
  border-color: rgba(185,28,28,0.3);
  color: #b91c1c;
  background: rgba(185,28,28,0.07);
}
[data-theme="light"] .reset-confirm:hover { background: rgba(185,28,28,0.13); }

/* ── Discovery modal ── */
@keyframes discovery-pop {
  0%   { transform: scale(0.8); opacity: 0; }
  60%  { transform: scale(1.04); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes discovery-emoji-pulse {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.18); }
  100% { transform: scale(1); }
}

.discovery-modal {
  max-width: 340px;
  padding: 32px 28px 24px;
  text-align: center;
  align-items: center;
  gap: 0;
  border-color: rgba(34,197,94,0.35);
  animation: discovery-pop 0.35s cubic-bezier(0.34,1.56,0.64,1) forwards;
}

.discovery-modal-badge {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #4ade80;
  background: rgba(34,197,94,0.1);
  border: 1px solid rgba(34,197,94,0.25);
  border-radius: 20px;
  padding: 3px 12px;
  margin-bottom: 20px;
}
[data-theme="light"] .discovery-modal-badge {
  color: #15803d;
  background: rgba(21,128,61,0.08);
  border-color: rgba(21,128,61,0.2);
}

.discovery-modal-emoji {
  font-size: 56px;
  line-height: 1;
  margin-bottom: 14px;
  animation: discovery-emoji-pulse 0.5s ease-out 0.1s both;
}

.discovery-modal-name {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.discovery-modal-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.55;
  margin-bottom: 24px;
}

.discovery-modal-btn {
  padding: 9px 28px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  border: 1px solid rgba(34,197,94,0.4);
  background: rgba(34,197,94,0.1);
  color: #4ade80;
  cursor: pointer;
  transition: background 0.15s;
}
.discovery-modal-btn:hover { background: rgba(34,197,94,0.18); }
[data-theme="light"] .discovery-modal-btn {
  border-color: rgba(21,128,61,0.3);
  color: #15803d;
  background: rgba(21,128,61,0.07);
}
[data-theme="light"] .discovery-modal-btn:hover { background: rgba(21,128,61,0.13); }

/* ── Tooltip ── */
.tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--bg-surface);
  border: 1px solid var(--border-hover);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 11px;
  max-width: 240px;
  z-index: 300;
  opacity: 0;
  transition: opacity 0.1s;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}
.tooltip.visible { opacity: 1; }
.tooltip-recipe {
  font-size: 11px;
  color: var(--accent-text);
  font-weight: 500;
  margin-bottom: 4px;
}
.tooltip-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.45;
}

/* ── Responsive ── */
@media (max-width: 600px) {
  .main { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .panel { border-right: none; border-bottom: 1px solid var(--border); }
  .workspace { max-height: 340px; }
  .app-title { display: none; }
}
