:root {
  --bg: #e8eaed;
  --panel: #ffffff;
  --panel-muted: #f4f5f7;
  --border: #d8dbe0;
  --text: #1f2328;
  --text-muted: #6b7280;
  --accent: #2f6fed;
  --accent-soft: #e8effc;
  --danger: #c43c3c;
  --danger-soft: #fdecec;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.06);
  --radius: 10px;
  --toolbar-h: 52px;
  --left-w: 236px;
  --right-w: 300px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

.app {
  display: grid;
  grid-template-columns: var(--left-w) 1fr var(--right-w);
  grid-template-rows: var(--toolbar-h) 1fr;
  height: 100%;
}

.toolbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}

.toolbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 10px;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.toolbar-brand span {
  color: var(--text-muted);
  font-weight: 500;
}

.toolbar-sep {
  width: 1px;
  height: 22px;
  background: var(--border);
  margin: 0 4px;
}

.tool-btn,
.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
}

.icon-btn {
  width: 32px;
  padding: 0;
  justify-content: center;
}

.tool-btn:hover,
.icon-btn:hover {
  background: var(--panel-muted);
}

.tool-btn.active,
.icon-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: #c9d7f6;
}

.tool-btn:disabled,
.icon-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.tool-btn svg,
.icon-btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.toolbar-select {
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-muted);
  padding: 0 8px;
  color: var(--text);
}

.panel {
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow: auto;
  min-width: 0;
}

.panel-right {
  border-right: 0;
  border-left: 1px solid var(--border);
}

.panel-header {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 14px 14px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.panel-header h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.parts-group-title {
  margin: 14px 14px 0;
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.parts-list {
  display: grid;
  gap: 6px;
  padding: 8px 12px 12px;
}

.part-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--panel);
  cursor: grab;
  user-select: none;
}

.part-item:hover {
  border-color: #b9c4d4;
  background: var(--panel-muted);
}

.part-item:active {
  cursor: grabbing;
}

.part-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--panel-muted);
  display: grid;
  place-items: center;
  color: var(--text);
}

.part-icon svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.6;
}

.part-item strong {
  display: block;
  font-size: 13px;
  font-weight: 600;
}

.part-item small {
  display: block;
  color: var(--text-muted);
  font-size: 11px;
}

.viewport {
  position: relative;
  overflow: hidden;
  background: #dfe3e8;
  min-width: 0;
}

.viewport canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.start-cards {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-content: center;
  gap: 16px;
  background: linear-gradient(180deg, rgba(223, 227, 232, 0.2), rgba(223, 227, 232, 0.55));
  pointer-events: auto;
}

.start-cards[hidden] {
  display: none;
}

.start-lead {
  margin: 0;
  text-align: center;
  font-size: 20px;
  font-weight: 650;
}

.start-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 200px));
  gap: 12px;
}

.start-grid button {
  display: grid;
  gap: 6px;
  padding: 22px 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: left;
}

.start-grid button:hover {
  border-color: #c9d7f6;
  background: var(--accent-soft);
}

.start-grid strong {
  font-size: 16px;
}

.start-grid span {
  color: var(--text-muted);
  font-size: 13px;
}

.btn-accent {
  width: 100%;
  height: 40px;
  border: 1px solid #c9d7f6;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 650;
}

.dim-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.dim-label {
  font-size: 11px;
  font-weight: 650;
  color: #334155;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  box-shadow: var(--shadow);
}

.place-hint {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  background: #111827;
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 650;
}

.align-hint {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 7;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(520px, calc(100% - 24px));
  background: #111827;
  color: #fff;
  padding: 12px 12px 12px 16px;
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.align-hint[hidden] {
  display: none;
}

.align-hint p {
  margin: 0;
  font-size: 14px;
  font-weight: 650;
  line-height: 1.4;
}

.align-hint kbd {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 6px;
  background: #374151;
  font-family: inherit;
  font-size: 13px;
}

.align-hint button {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: #374151;
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.align-hint button:hover {
  background: #4b5563;
}

.quick-actions {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  max-width: calc(100% - 24px);
  padding: 8px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 5;
}

.coach {
  display: grid;
  gap: 8px;
  min-width: min(520px, calc(100% - 24px));
  padding: 14px 16px;
}

.coach-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  text-align: center;
}

.coach-hint {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

.coach-btns {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.cover-choice {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
}

.cover-choice button {
  height: 46px !important;
  padding: 0 12px !important;
  border: 2px solid var(--border) !important;
  border-radius: 10px !important;
  background: #fff !important;
  font-size: 14px !important;
  font-weight: 800 !important;
  cursor: pointer;
}

.cover-choice button.on {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  color: #fff !important;
}

.coach-main {
  height: 40px !important;
  padding: 0 16px !important;
  background: var(--accent-soft) !important;
  border-color: #c9d7f6 !important;
  color: var(--accent) !important;
  font-weight: 700;
}

.quick-actions button {
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-size: 12px;
}

.quick-actions button:hover {
  background: var(--accent-soft);
  border-color: #c9d7f6;
  color: var(--accent);
}

.live-label {
  position: absolute;
  z-index: 6;
  transform: translate(-50%, -120%);
  background: #111827;
  color: #fff;
  font-size: 12px;
  font-weight: 650;
  padding: 4px 8px;
  border-radius: 8px;
  pointer-events: none;
}

.props {
  padding: 12px;
  display: grid;
  gap: 10px;
}

.props-empty {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
  padding: 8px 2px;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.field {
  display: grid;
  gap: 4px;
}

.field.span-2 {
  grid-column: 1 / -1;
}

.field label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
}

.field input,
.field select {
  width: 100%;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 8px;
  background: #fff;
}

.field input:focus,
.field select:focus {
  outline: 2px solid #c9d7f6;
  border-color: var(--accent);
}

.field-error {
  grid-column: 1 / -1;
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
}

.prop-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.prop-actions button,
.btn {
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-muted);
  cursor: pointer;
}

.btn-danger {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: #f3c4c4;
}

.selection-title {
  font-size: 14px;
  font-weight: 650;
  margin: 0;
}

.selection-meta {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 12px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  max-width: 360px;
  background: #111827;
  color: #fff;
  padding: 12px 14px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 13px;
}

.boot-error {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: #eef1f4;
}

.boot-error[hidden] {
  display: none;
}

.boot-error-card {
  width: min(440px, calc(100% - 32px));
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.boot-error-card h1 {
  margin: 0 0 8px;
  font-size: 20px;
}

.boot-error-card p {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Mobil kabuk parçaları — masaüstünde gizli */
.mobile-dock,
.mobile-scrim,
.toolbar-mobileonly {
  display: none;
}

.start-cards.no-tap {
  pointer-events: none;
}

@media (max-width: 1100px) {
  .app {
    --left-w: 188px;
    --right-w: 260px;
  }

  .tool-btn span {
    display: none;
  }
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: var(--toolbar-h) 1fr auto;
    height: 100dvh;
    --dock-h: 60px;
  }

  /* Toolbar: yatay kaydırma + 44px hedefler */
  .toolbar {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  .toolbar::-webkit-scrollbar {
    display: none;
  }
  .toolbar-brand span {
    display: none;
  }
  .tool-btn span {
    display: none;
  }
  .tool-btn,
  .icon-btn {
    height: 44px;
    min-width: 44px;
    flex: 0 0 auto;
  }
  .icon-btn {
    width: 44px;
  }
  .toolbar-select {
    height: 44px;
  }
  .toolbar-mobileonly {
    display: inline-flex;
  }
  .toolbar-mobileonly.toolbar-sep {
    display: block;
  }
  .toolbar-mobileonly span {
    display: inline;
  }

  .panel {
    grid-column: 1;
  }

  /* Alt dock (grid satırı 3) */
  .mobile-dock {
    display: grid;
    grid-column: 1;
    grid-row: 3;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
    background: var(--panel);
    border-top: 1px solid var(--border);
    z-index: 30;
  }
  .dock-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 44px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel-muted);
    color: var(--text);
    font-size: 13px;
    font-weight: 650;
    cursor: pointer;
  }
  .dock-btn.active {
    background: var(--accent-soft);
    border-color: #c9d7f6;
    color: var(--accent);
  }
  .dock-btn svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  /* Paneller = alt sheet (gizlenmez, aşağıdan gelir) */
  .panel-left,
  .panel-right {
    display: block;
    position: fixed;
    left: 0;
    right: 0;
    top: auto;
    bottom: var(--kb, 0px);
    width: auto;
    max-height: min(72vh, calc(100dvh - var(--toolbar-h) - 16px - var(--kb, 0px)));
    border: 1px solid var(--border);
    border-left: 0;
    border-right: 0;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -10px 34px rgba(16, 24, 40, 0.22);
    transform: translateY(120%);
    transition: transform 0.26s ease;
    z-index: 46;
    padding-bottom: env(safe-area-inset-bottom);
    overscroll-behavior: contain;
  }
  .panel-left::before,
  .panel-right::before {
    content: "";
    display: block;
    width: 40px;
    height: 4px;
    margin: 8px auto 2px;
    border-radius: 999px;
    background: var(--border);
  }
  .app.sheet-parts .panel-left {
    transform: translateY(0);
  }
  .app.sheet-props .panel-right {
    transform: translateY(0);
  }

  .mobile-scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.38);
    z-index: 44;
  }
  .mobile-scrim[hidden] {
    display: none;
  }

  /* Overlay'ler dock ve güvenli alanın üstünde */
  .quick-actions {
    bottom: 12px;
    max-width: calc(100% - 16px);
  }
  .quick-actions button {
    height: 44px;
    font-size: 13px;
  }
  .toast {
    left: 12px;
    right: 12px;
    max-width: none;
    bottom: calc(var(--dock-h) + 12px + env(safe-area-inset-bottom));
  }

  /* Dokunma hedefleri + iOS input zoom engeli (16px) */
  .part-item {
    padding: 12px;
  }
  .field input,
  .field select {
    height: 44px;
    font-size: 16px;
  }
  .prop-actions button,
  .btn {
    height: 44px;
  }
  .align-hint {
    max-width: calc(100% - 16px);
  }
  .align-hint button {
    width: 44px;
    height: 44px;
  }
  .size-dialog {
    width: min(440px, calc(100% - 24px));
  }
  .size-dialog-unit button {
    height: 44px;
  }
  .size-dialog-grid input {
    height: 44px;
    font-size: 16px;
  }
  .size-dialog-actions .btn {
    height: 46px;
  }
  .start-grid {
    grid-template-columns: 1fr;
    width: min(320px, calc(100% - 24px));
  }
  .start-grid button {
    padding: 18px 16px;
  }
}

.size-dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, 0.45);
}

.size-dialog {
  width: min(420px, calc(100% - 32px));
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
}

.size-dialog h2 {
  margin: 0;
  font-size: 18px;
}

.size-dialog-sub {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
}

.size-dialog-unit {
  display: inline-flex;
  gap: 6px;
}

.size-dialog-unit button {
  height: 32px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-weight: 650;
}

.size-dialog-unit button.active {
  background: var(--accent-soft);
  border-color: #c9d7f6;
  color: var(--accent);
}

.size-dialog-grid {
  display: grid;
  gap: 10px;
}

.size-dialog-grid label {
  display: grid;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.size-dialog-grid .unit-suffix {
  color: var(--text-muted);
  font-weight: 500;
}

.size-dialog-grid input {
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 10px;
  font-size: 15px;
}

.size-dialog-error {
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
}

.size-dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.size-dialog-actions .btn {
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-muted);
  cursor: pointer;
  font-weight: 650;
}

.size-dialog-actions .btn-accent {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
