/* Planner layout */
.plan-name { display: flex; flex-direction: column; border-left: 1px solid rgba(243, 238, 223, 0.35); padding-left: 18px; }
.plan-name__label { color: #B9C9BF; font-size: 11px; }
.plan-name__input {
  background: transparent; border: 0; border-bottom: 1px dashed rgba(243, 238, 223, 0.5);
  color: var(--cream); font-weight: 700; padding: 2px 0; width: min(260px, 60vw);
}
.header-actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; }

.planner {
  display: flex; flex-wrap: wrap; gap: 20px; padding: 20px; align-items: flex-start;
  max-width: 1600px; margin: 0 auto;
}
.planner__pieces { flex: 1 1 240px; min-width: 0; }
.planner__main { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.planner__parts { flex: 1 1 280px; min-width: 0; }

/* Pieces panel */
.pieces__hint { margin: 0 0 12px; font-size: 15px; color: var(--ink-2); }
.turn { border: 0; margin: 0 0 12px; padding: 0; }
.turn legend { margin-bottom: 6px; padding: 0; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; border: 1.5px solid var(--green); border-radius: 6px; overflow: hidden; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label { min-height: 42px; display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--green); background: var(--paper); cursor: pointer; }
.segmented input:checked + label { background: var(--green); color: var(--cream); }
.segmented input:focus-visible + label { outline: 3px solid var(--amber); outline-offset: -3px; }

.piece-group { margin: 0 0 12px; }
.piece-group h3 { margin: 0 0 6px; }
.piece-list { display: flex; flex-direction: column; gap: 6px; }
.piece {
  display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 6px 10px;
  border: 1px solid var(--rule); background: var(--paper); border-radius: 6px;
  text-align: left; cursor: pointer; width: 100%;
}
.piece:hover:not(:disabled) { border-color: var(--green); background: #F7F3E8; }
.piece:disabled { cursor: not-allowed; opacity: 0.5; }
.piece__icon { width: 44px; height: 38px; flex: none; display: inline-flex; align-items: center; justify-content: center; background: var(--board); border-radius: 4px; }
.piece__text { display: flex; flex-direction: column; min-width: 0; }
.piece__name { font-weight: 700; font-size: 15px; }
.piece__spec { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.explain { margin-top: 8px; border: 1px solid var(--rule); border-radius: 6px; background: #FAF6EC; }
.explain summary { min-height: 44px; display: flex; align-items: center; padding: 0 12px; font-weight: 700; font-size: 15px; color: var(--green); cursor: pointer; }
.explain p { margin: 0; padding: 0 12px 10px; font-size: 14px; color: var(--ink-2); }
.join-mode { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.join-mode select, .board-pick select, .board-custom input {
  min-height: 44px; border: 1px solid var(--steel); border-radius: 6px; padding: 0 10px; background: #fff;
}

/* Board bar */
.board-bar { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; }
.board-pick, .board-custom label { display: flex; flex-direction: column; gap: 4px; }
.board-custom { display: flex; gap: 10px; }
.board-custom[hidden] { display: none; }
.board-custom input { width: 110px; }
.board-tools { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; }

.status { display: flex; flex-wrap: wrap; gap: 8px; min-height: 36px; }

/* Drawing */
.drawing__paper {
  background-color: var(--paper);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  padding: 12px;
}
.board { display: block; width: 100%; height: auto; touch-action: manipulation; user-select: none; }
.board .track-bed { fill: none; stroke: var(--green); stroke-opacity: 0.16; }
.board .track { fill: none; stroke: var(--green); }
.board .track-hit { fill: none; stroke: transparent; cursor: pointer; }
.board .piece-g.selected .track { stroke: var(--amber-shadow); }
.board .piece-g.selected .track-bed { stroke: var(--amber); stroke-opacity: 0.45; }
.board .piece-g.clash .track-bed { stroke: var(--red); stroke-opacity: 0.4; }
.board .open-end { fill: var(--amber); stroke: var(--amber-deep); cursor: pointer; }
.board .open-end.active { fill: var(--paper); stroke: var(--amber-deep); }
.board .open-end-ring { fill: none; stroke: var(--amber-deep); stroke-dasharray: 6 5; }
.board .open-end-hit { fill: transparent; cursor: pointer; }
.board .joint { fill: var(--paper); stroke: var(--green); }
.board .dim { stroke: var(--muted); }
.board .dim-text { font-family: var(--mono); fill: var(--muted); }
.board .gap-line { stroke: var(--red); stroke-dasharray: 10 8; }

.title-block {
  margin: 0; border-top: 1.5px solid var(--ink); font-family: var(--mono); font-size: 13px;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.title-block div { display: flex; border-right: 1px solid var(--ink); border-bottom: 1px solid var(--ink); margin: 0 -1px -1px 0; }
.title-block dt { padding: 8px 10px; color: var(--muted); border-right: 1px solid var(--rule); }
.title-block dd { margin: 0; padding: 8px 10px; font-weight: 500; }
.drawing__note { margin: 0; font-size: 14px; color: var(--muted); }

/* Parts */
.parts { width: 100%; border-collapse: collapse; font-size: 15px; }
.parts th { text-align: left; padding: 8px 14px; font-family: var(--mono); font-size: 12px; font-weight: 500; color: var(--muted); border-bottom: 1px solid var(--rule); }
.parts td { padding: 9px 14px; border-bottom: 1px solid #EDE6D3; }
.parts .num { text-align: right; font-family: var(--mono); font-weight: 500; }
.parts .part-no { font-family: var(--mono); font-size: 13px; color: var(--muted); }
.parts__empty td { color: var(--muted); }
.parts__foot p { margin: 0 0 8px; font-size: 14px; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: var(--cream); padding: 12px 18px; border-radius: 8px;
  font-weight: 700; max-width: calc(100% - 32px); z-index: 10;
}

.site-foot { max-width: 1600px; margin: 0 auto; padding: 0 20px 28px; font-size: 14px; color: var(--muted); }
.site-foot p { margin: 0; }

/* Phones: drawing first, pieces underneath */
@media (max-width: 720px) {
  .planner { padding: 12px 16px; gap: 14px; }
  .site-header__inner { padding: 8px 16px; }
  .brand__name { font-size: 22px; }
  .header-actions .btn { min-height: 40px; padding: 0 12px; font-size: 15px; }
  .board-bar { gap: 8px; }
  .board-pick { flex: 1 1 150px; }
  .board-pick select { width: 100%; }
  .board-tools { width: 100%; }
  .board-tools .btn { flex: 1 1 auto; padding: 0 10px; font-size: 15px; }
  .planner__main { order: -1; }
  .header-actions { margin-left: 0; }
  .board-tools { margin-left: 0; }
  .plan-name { border-left: 0; padding-left: 0; }

  /* Pieces become a tray pinned to the bottom of the screen, so the board
     and the piece picker are both in reach while you build. */
  .planner { padding-bottom: 20px; }
  .site-foot { padding: 0 16px calc(250px + env(safe-area-inset-bottom, 0px)); }
  .planner__pieces {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
    border: 0; border-top: 1.5px solid var(--ink); border-radius: 0;
    box-shadow: 0 -6px 18px rgba(26, 31, 28, 0.12);
  }
  .planner__pieces .sheet__head { display: none; }
  .planner__pieces .sheet__body {
    display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px;
    padding: 10px max(16px, env(safe-area-inset-right, 0px)) calc(10px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  }
  .pieces__hint {
    grid-column: 1 / -1; grid-row: 1; margin: 0; font-size: 14px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .turn { grid-column: 1; grid-row: 2; margin: 0; }
  .turn legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .segmented label { min-height: 40px; }
  .join-mode { grid-column: 2; grid-row: 2; margin: 0; }
  .join-mode .mono-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .join-mode select { min-height: 42px; width: 100%; font-size: 15px; }
  .piece-groups {
    grid-column: 1 / -1; grid-row: 3;
    display: flex; gap: 14px; overflow-x: auto; overscroll-behavior-x: contain;
    scroll-snap-type: x proximity; padding-bottom: 4px; margin: 0 -2px;
  }
  .piece-group { margin: 0; flex: none; display: flex; flex-direction: column; gap: 4px; }
  .piece-group h3 { margin: 0; }
  .explain { display: none; }
  .piece-list { flex-direction: row; }
  .piece { width: 152px; flex: none; min-height: 50px; padding: 4px 8px; gap: 8px; scroll-snap-align: start; }
  .piece__icon { width: 36px; height: 32px; }
  .piece__name { font-size: 14px; line-height: 1.2; }
  .piece__spec { font-size: 11px; }
  .toast { bottom: calc(210px + env(safe-area-inset-bottom, 0px)); }
}

/* Print: just the drawing, title block and parts list */
@media print {
  @page { size: A4 landscape; margin: 12mm; }
  body { background: #fff; font-size: 11pt; }
  .site-header .header-actions, .site-header .plan-name, .planner__pieces, .board-bar, .status, .drawing__note, .parts__shops, .toast { display: none !important; }
  .site-header { background: #fff; color: var(--green); border-bottom: 2px solid var(--green); }
  .brand, .brand:hover { color: var(--green); }
  .planner { display: block; padding: 0; }
  .drawing__paper { background-image: none; }
  .board .open-end-ring, .board .open-end-hit, .board .track-hit { display: none; }
  .planner__parts { margin-top: 8mm; break-inside: avoid; }
  .sheet { border-color: #000; }
}
