.eco-root {
  max-width: 1460px;
  margin: 0 auto;
  padding: 24px;
  color: var(--text-primary);
  --wdl-win: #27c26a;
  --wdl-draw: #b0b6bf;
  --wdl-loss: #e04b4b;
}

.eco-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.eco-back,
.eco-back-inline {
  color: var(--text-primary);
  text-decoration: none;
  border: 1px solid var(--panel-border);
  background: var(--panel-bg);
  border-radius: 8px;
  padding: 6px 10px;
}

.eco-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.eco-layout {
  display: grid;
  grid-template-columns: minmax(420px, 1fr) minmax(520px, 1.2fr);
  gap: 16px;
  align-items: start;
}

.eco-master {
  min-width: 0;
}

.eco-detail {
  min-width: 520px;
}

#ecoSearch {
  flex: 1 1 300px;
  min-height: 38px;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 8px 12px;
  background: var(--panel-bg);
  color: var(--text-primary);
}

.eco-tabs {
  display: flex;
  gap: 8px;
}

.eco-tab {
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--panel-bg);
  color: var(--text-primary);
  padding: 6px 10px;
  cursor: pointer;
}

.eco-tab.active {
  background: rgba(255, 140, 0, 0.2);
  border-color: rgba(255, 140, 0, 0.45);
}

.eco-list {
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  overflow: hidden;
}

.eco-row {
  display: grid;
  grid-template-columns: 84px minmax(220px, 1fr) minmax(280px, 1.2fr);
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  text-decoration: none;
  color: var(--text-primary);
  border-bottom: 1px solid var(--panel-border);
}

.eco-row:last-child {
  border-bottom: 0;
}

.eco-row:hover {
  background: rgba(255, 255, 255, 0.05);
}

.eco-row.is-selected {
  background: rgba(255, 140, 0, 0.14);
}

.eco-code {
  font-family: 'Roboto Mono', monospace;
  color: var(--text-secondary);
}

.eco-name {
  min-width: 0;
}

.eco-moves {
  min-width: 0;
  color: var(--text-secondary);
  opacity: 0.95;
  white-space: normal;
  line-height: 1.35;
  max-height: 4.5em;
  overflow: auto;
}

.eco-theory {
  white-space: pre-line;
  line-height: 1.45;
  color: var(--text-primary);
}

.eco-fallback {
  color: var(--danger-color);
  margin-top: 10px;
}

.eco-card {
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: var(--panel-bg);
  padding: 14px;
}

.eco-detail-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-items: start;
}

.eco-detail-header h2 {
  margin-top: 0;
  margin-bottom: 4px;
}

.eco-detail-layout h3 {
  margin: 0 0 10px;
}

.eco-defining #ecoDetailMoves {
  line-height: 1.45;
  white-space: normal;
  max-height: 8.5em;
  overflow: auto;
  margin: 0;
}

.eco-board-wrap {
  display: grid;
  gap: 8px;
  justify-items: start;
}

.eco-board-container {
  width: 4in;
  height: 4in;
  max-width: 92vw;
  max-height: 92vw;
  aspect-ratio: 1 / 1;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  overflow: hidden;
  background: #111317;
}

.eco-board-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.eco-board-controls button {
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
  padding: 5px 10px;
  font-size: 12px;
  line-height: 1.1;
  cursor: pointer;
}

.eco-board-controls button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
}

.eco-board-controls button:focus-visible {
  outline: 2px solid rgba(154, 215, 255, 0.9);
  outline-offset: 2px;
}

.eco-board-controls button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.eco-overview {
  border-top: 1px solid var(--panel-border);
  padding-top: 10px;
}

.eco-mini-board {
  width: 100% !important;
  height: 100% !important;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, minmax(0, 1fr));
  contain: layout paint size;
  box-sizing: border-box;
}

.eco-sq {
  position: relative;
  overflow: hidden;
}

.eco-sq.light {
  background: #f0d9b5;
}

.eco-sq.dark {
  background: #b58863;
}

.eco-piece {
  position: absolute;
  inset: 6%;
  display: block;
  width: 88%;
  height: 88%;
  margin: auto;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

.eco-piece-fallback {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(14px, 1.9vw, 22px);
  line-height: 1;
  pointer-events: none;
}

.eco-pro-block {
  border-top: 1px solid var(--panel-border);
  padding-top: 10px;
  margin-top: 10px;
}

.eco-defining,
.eco-coach {
  border-top: 1px solid var(--panel-border);
  padding-top: 10px;
}

.eco-related {
  margin: 0;
  padding-left: 18px;
}

.eco-related li {
  margin-bottom: 8px;
}

.eco-related a {
  color: #9ad7ff;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 2px 6px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  display: inline-block;
}

.eco-related a:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.16);
}

.eco-related a:focus-visible {
  outline: 2px solid rgba(154, 215, 255, 0.9);
  outline-offset: 2px;
}

.eco-stats-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.eco-stats-row strong {
  color: var(--text-primary);
}

.eco-wdl-bar {
  display: flex;
  width: 100%;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--panel-border);
  margin-bottom: 8px;
}

.eco-wdl-white {
  background: var(--wdl-win);
}

.eco-wdl-draw {
  background: var(--wdl-draw);
}

.eco-wdl-black {
  background: var(--wdl-loss);
}

.eco-continuations {
  margin: 0;
  padding-left: 20px;
}

.eco-continuations li {
  margin-bottom: 10px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  min-width: 0;
}

.eco-cont-move {
  min-width: 110px;
  color: var(--text-primary);
  white-space: nowrap;
}

.eco-cont-stats {
  margin-left: 48px;
  flex: 1 1 auto;
  min-width: 0;
}

.eco-cont-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  margin-bottom: 6px;
}

.eco-cont-note {
  color: var(--text-secondary);
  font-size: 12px;
  white-space: nowrap;
}

.eco-cont-main {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.eco-cont-pct {
  text-align: right;
  color: var(--text-primary);
}

.eco-cont-bar {
  display: flex;
  height: 6px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--panel-border);
}

.eco-cont-w {
  display: block;
  height: 100%;
  background: var(--wdl-win);
}

.eco-cont-d {
  display: block;
  height: 100%;
  background: var(--wdl-draw);
}

.eco-cont-l {
  display: block;
  height: 100%;
  background: var(--wdl-loss);
}

.eco-muted {
  color: var(--text-secondary);
  font-size: 12px;
}

@media (max-width: 840px) {
  .eco-layout {
    grid-template-columns: 1fr;
  }

  .eco-detail {
    min-width: 0;
  }

  .eco-row {
    grid-template-columns: 84px 1fr;
    grid-template-areas:
      "code name"
      "moves moves";
    align-items: start;
    row-gap: 6px;
  }

  .eco-code {
    grid-area: code;
  }

  .eco-name {
    grid-area: name;
  }

  .eco-moves {
    grid-area: moves;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    font-size: 12px;
  }

  .eco-detail-layout {
    grid-template-columns: 1fr;
  }

  .eco-mini-board {
    width: 100% !important;
    height: 100% !important;
  }

  .eco-board-container {
    width: min(92vw, 4in);
    height: min(92vw, 4in);
  }

  .eco-continuations li {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .eco-cont-stats {
    margin-left: 0;
  }

  .eco-cont-move {
    min-width: 0;
  }

  .eco-cont-meta {
    flex-wrap: wrap;
  }
}

@media (max-width: 1260px) {
  .eco-layout {
    grid-template-columns: 1fr;
  }

  .eco-detail {
    min-width: 0;
  }
}
