:root {
  --indigo: #1C2A4A;
  --madder: #9B2C2C;
  --mustard: #C8922E;
  --wool: #F5ECDC;
  --wool-deep: #D8C6A5;
  --walnut: #3A261B;
  --walnut-soft: #6B5546;
  --line: #D5C4A5;
  --sans: 'Alegreya Sans', 'Segoe UI', system-ui, sans-serif;
  --serif: 'Alegreya', Georgia, serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  height: 100dvh;
  overflow: hidden;
  background: var(--wool);
  color: var(--walnut);
  font: 400 15px/1.35 var(--sans);
}

button, input { font: inherit; color: inherit; }

button { cursor: pointer; }

button:focus-visible, input:focus-visible {
  outline: 2px solid var(--mustard);
  outline-offset: 2px;
}

/* Üst şerit */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--indigo);
  color: var(--wool);
}

.brand {
  margin: 0;
  font: 700 22px/1.1 var(--serif);
  white-space: nowrap;
}

.toolbar { display: flex; gap: 4px; }

.tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 6px 10px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: none;
  color: var(--wool);
}

.tool:hover:not(:disabled) { border-color: var(--mustard); }
.tool:disabled { opacity: .4; cursor: default; }

.tool.primary {
  margin-left: 6px;
  background: var(--mustard);
  color: var(--indigo);
  font-weight: 700;
}

.tool.primary:hover:not(:disabled) { border-color: var(--wool); }

.tool svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Kilim bordürü */
.band {
  height: 24px;
  background-color: var(--indigo);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='24'%3E%3Crect width='48' height='24' fill='%239B2C2C'/%3E%3Cpath d='M0 0H48V3H0ZM0 21H48V24H0Z' fill='%231C2A4A'/%3E%3Cpath d='M24 3 28 7H32V11H36V13H32V17H28L24 21 20 17H16V13H12V11H16V7H20Z' fill='%23F5ECDC'/%3E%3Cpath d='M24 8 28 12 24 16 20 12Z' fill='%231C2A4A'/%3E%3Cpath d='M0 7 5 12 0 17ZM48 7 43 12 48 17Z' fill='%23C8922E'/%3E%3C/svg%3E");
  background-repeat: repeat-x;
  background-position: center;
}

/* Çalışma alanı */
.studio {
  display: grid;
  grid-template-columns: 296px minmax(0, 1fr) 272px;
  min-height: 0;
}

.panel {
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
  background: var(--wool);
}

.motifs { border-right: 1px solid var(--line); }
.props { border-left: 1px solid var(--line); }

h2 {
  margin: 0 0 10px;
  font: 700 18px/1.2 var(--serif);
  color: var(--indigo);
}

.motif-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 6px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #FBF6EC;
  color: var(--indigo);
  text-align: center;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}

.card:hover {
  border-color: var(--madder);
  color: var(--madder);
}

.card svg { width: 54px; height: 54px; pointer-events: none; }
.card b { font-weight: 700; font-size: 14px; line-height: 1.15; color: var(--walnut); }

/* Halı */
.stage {
  display: flex;
  min-width: 0;
  min-height: 0;
  padding: 10px;
  background-color: var(--wool-deep);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='44' height='44'%3E%3Cpath d='M22 15 29 22 22 29 15 22Z' fill='%23B8A27C' fill-opacity='.3'/%3E%3C/svg%3E");
}

#rug {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#ground {
  filter: drop-shadow(0 6px 10px rgba(58, 38, 27, .35));
}

#hint {
  font: 500 27px var(--sans);
  pointer-events: none;
}

.item { cursor: move; }

.handle { cursor: pointer; }
.handle[data-handle='scale'] { cursor: nwse-resize; }
.handle[data-handle='rotate'] { cursor: grab; }

/* Sağ panel */
.prop-group + .prop-group {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.empty { margin: 0; color: var(--walnut-soft); }

.field { display: block; margin-bottom: 12px; }

.label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 5px;
  font-weight: 500;
}

.number {
  display: inline-flex;
  align-items: center;
  font-weight: 400;
  color: var(--walnut-soft);
}

.number input {
  width: 4.5ch;
  padding: 0 2px;
  border: 0;
  border-bottom: 1px dashed var(--walnut-soft);
  border-radius: 2px;
  background: none;
  color: inherit;
  text-align: right;
  appearance: textfield;
  -moz-appearance: textfield;
}

.number input::-webkit-outer-spin-button,
.number input::-webkit-inner-spin-button {
  appearance: none;
  margin: 0;
}

.number input:hover { border-bottom-color: var(--madder); cursor: text; }

.number input:focus {
  border-bottom: 1px solid var(--indigo);
  background: #FBF6EC;
  color: var(--walnut);
  outline: 2px solid var(--mustard);
  outline-offset: 1px;
}

input[type='range'] {
  display: block;
  width: 100%;
  height: 26px;
  margin: 0;
  accent-color: var(--madder);
}

.swatches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(34px, 1fr));
  gap: 6px;
}

.swatch {
  position: relative;
  aspect-ratio: 1;
  min-height: 34px;
  padding: 0;
  border: 1px solid rgba(58, 38, 27, .35);
  border-radius: 3px;
  overflow: hidden;
}

.swatch[aria-pressed='true'] {
  outline: 3px solid var(--indigo);
  outline-offset: 1px;
}

.swatch.custom {
  display: block;
  background: conic-gradient(#9B2C2C, #C8922E, #5F6B3A, #2F7F86, #1C2A4A, #9B2C2C);
  cursor: pointer;
}

.swatch.custom input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.actions button {
  min-height: 38px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #FBF6EC;
}

.actions button:hover { border-color: var(--indigo); }
.actions .danger { color: var(--madder); font-weight: 700; }
.actions .danger:hover { border-color: var(--madder); }

.ghost {
  position: fixed;
  z-index: 10;
  width: 96px;
  height: 96px;
  margin: -48px 0 0 -48px;
  pointer-events: none;
  opacity: .9;
}

.tabs { display: none; }

.noscript {
  position: fixed;
  inset: auto 16px 16px;
  margin: 0;
  padding: 12px;
  background: var(--madder);
  color: var(--wool);
}

/* Telefon ve dar tablet */
@media (max-width: 860px) {
  .brand { font-size: 18px; white-space: normal; }
  .tool { padding: 6px 8px; }
  .tool span { display: none; }
  .band { height: 18px; background-size: 36px 18px; }

  .studio {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) 216px;
  }

  .stage { grid-row: 1; padding: 6px; }
  .panel { grid-row: 2; border: 0; border-top: 1px solid var(--line); padding: 10px 12px; }

  body[data-tab='motifs'] .props,
  body[data-tab='props'] .motifs { display: none; }

  .motifs h2 { display: none; }

  .motif-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .card { touch-action: pan-y; cursor: pointer; }
  .card svg { width: 44px; height: 44px; }

  .prop-group + .prop-group { margin-top: 12px; padding-top: 10px; }

  /* 16 pikselin altında iPhone odaklanınca sayfayı yakınlaştırıyor. */
  .number input { width: 5ch; font-size: 16px; }

  .tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--indigo);
  }

  .tabs button {
    min-height: 44px;
    border: 0;
    border-top: 3px solid transparent;
    background: none;
    color: var(--wool);
    font-weight: 500;
  }

  .tabs button[aria-pressed='true'] { border-top-color: var(--mustard); font-weight: 700; }
}

/* Yan çevrilmiş telefon: alt alta sığmıyor, halı ile panel yan yana durur. */
@media (max-width: 860px) and (max-height: 560px) {
  .studio {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
  }

  .stage { grid-row: 1; grid-column: 1; }

  .panel {
    grid-row: 1;
    grid-column: 2;
    border-top: 0;
    border-left: 1px solid var(--line);
  }
}

@media (max-width: 380px) {
  .topbar { padding-left: 10px; padding-right: 10px; gap: 6px; }
  .brand { font-size: 16px; }
  .toolbar { gap: 0; }
  .tool { padding: 6px 5px; }
}
