/* builder.css: bara det som ar specifikt for spelbyggaren. Grundstil i agentfarmen.css. */

.builder-page { padding-bottom: 20px; }

.builder-header .container { gap: 12px; }
.title-field { flex: 1; display: flex; justify-content: flex-end; min-width: 0; }
.title-field .input {
  width: min(100%, 320px);
  font-size: 17px;
  padding: 8px 12px;
  border-color: var(--sun);
}

.builder-main { padding-top: 16px; }

/* Layout: farm-kolumnen forst i DOM, men pa desktop hamnar byggstenarna till hoger (bredare). */
@media (min-width: 900px) {
  .builder-layout { grid-template-columns: minmax(0, 3fr) minmax(300px, 2fr); align-items: start; }
  .blocks-panel { position: sticky; top: 76px; max-height: calc(100vh - 92px); overflow: auto; }
}

.builder-layout > * { min-width: 0; }
.builder-farm-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.blocks-panel { min-width: 0; overflow: hidden; }

.farm-panel { padding: 10px; }
.farm-container {
  position: relative;
  width: 100%;
  aspect-ratio: 5 / 3;
  max-height: 55vh;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 5px solid var(--earth-dark);
  border-radius: var(--radius-sm);
  background: var(--green-2);
  overflow: hidden;
  box-shadow: 0 6px 0 var(--earth-dark);
}
.farm-container canvas {
  max-width: 100%;
  max-height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* HTML-fallback for robotfragor nar farmen saknas (eller ovanpa) */
.robot-question {
  --robot: var(--neon-blue);
  margin-top: 10px;
  background: var(--ink);
  color: #fff;
  border: 3px solid var(--robot);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: 0 0 16px color-mix(in srgb, var(--robot) 55%, transparent);
  animation: pop-in .18s ease-out;
}
.robot-question-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.robot-question-icon { width: 36px; height: 36px; color: var(--robot); image-rendering: pixelated; }
.robot-question-name { font-family: var(--font-pixel); font-size: 11px; color: var(--robot); flex: 1; }
.robot-question-close {
  background: transparent; border: 2px solid rgba(255,255,255,.4); color: #fff;
  border-radius: 999px; width: 36px; height: 36px; font-size: 16px; cursor: pointer;
}
.robot-question-text { font-weight: 800; font-size: 18px; margin-bottom: 10px; }
.robot-question-choices { display: flex; flex-wrap: wrap; gap: 8px; }
.robot-question-choices .btn { flex: 1 1 120px; min-height: 48px; }

@keyframes pop-in { from { transform: scale(.94); opacity: 0; } to { transform: none; opacity: 1; } }

.game-summary-panel { padding-bottom: 12px; }
.summary-row { display: flex; align-items: flex-start; gap: 14px; }
.summary-body { flex: 1; min-width: 0; }
.hero-preview {
  flex: 0 0 auto; width: 72px; height: 72px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, var(--sky-2), #e6f6ff);
  border: 3px solid var(--ink); border-radius: 14px; box-shadow: 0 4px 0 var(--ink);
  overflow: hidden;
}
.hero-preview canvas { width: 100%; height: 100%; image-rendering: pixelated; image-rendering: crisp-edges; }
.hero-preview .hero-emoji { font-size: 40px; line-height: 1; }
.hero-preview.pop { animation: hero-pop .35s ease-out; }
@keyframes hero-pop { 0% { transform: scale(.7) rotate(-8deg); } 60% { transform: scale(1.15) rotate(4deg); } 100% { transform: none; } }
.game-summary { font-size: 17px; font-weight: 700; }
.summary-robot {
  display: flex; align-items: center; gap: 8px; margin-top: 8px;
  font-size: 13px; font-weight: 800; color: var(--ink-soft);
}
.summary-robot svg { width: 24px; height: 24px; image-rendering: pixelated; }

.builder-toolbar { justify-content: center; }
.builder-toolbar .btn { min-height: 52px; font-size: 16px; }
.builder-toolbar .btn .emoji { font-size: 1.2em; }

.status-line {
  min-height: 24px; text-align: center; font-weight: 800; color: #fff;
  text-shadow: 2px 2px 0 var(--green-3);
}

/* Byggstenar */
.category-tabs {
  display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 10px; margin-bottom: 8px;
  scrollbar-width: thin; -webkit-overflow-scrolling: touch;
}
.category-tab {
  flex: 0 0 auto;
  font-family: var(--font-body); font-weight: 900; font-size: 15px;
  padding: 10px 14px; min-height: 44px;
  border-radius: 999px; border: 3px solid var(--green-3);
  background: #fff; color: var(--green-3); cursor: pointer;
  box-shadow: 0 3px 0 var(--green-3);
  -webkit-tap-highlight-color: transparent;
}
.category-tab.active { background: var(--green-2); color: #fff; transform: translateY(2px); box-shadow: 0 1px 0 var(--green-3); }
.category-tab .count { display: inline-block; margin-left: 6px; background: var(--sun); color: #5a3d00; border-radius: 999px; padding: 0 7px; font-size: 12px; }

.chips-wrap { position: relative; }
.block-chips { min-height: 120px; }
.block-chip { min-height: 52px; font-size: 17px; position: relative; }
.block-chip.building { animation: chip-wobble .6s ease-in-out infinite; }
@keyframes chip-wobble { 0%, 100% { transform: rotate(-2deg); } 50% { transform: rotate(2deg); } }
.blocks-hint { font-size: 14px; margin: 12px 0 0; }

/* Konfetti-glimt nar roboten byggt klart blocket */
.block-chip.placed { animation: chip-pop .5s ease-out; }
@keyframes chip-pop { 0% { transform: scale(1); } 40% { transform: scale(1.12); } 100% { transform: scale(1); } }
.block-chip.placed::before, .block-chip.placed::after {
  content: ''; position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; border-radius: 2px;
  pointer-events: none; opacity: 0;
  animation: confetti .9s ease-out forwards;
}
.block-chip.placed::before {
  background: #ff2fb0;
  box-shadow: -26px -22px 0 #ffd23f, 30px -18px 0 #00fff2, -34px 10px 0 #6fe36f, 24px 20px 0 #ff6b35;
}
.block-chip.placed::after {
  background: #1e90ff;
  box-shadow: -14px -30px 0 #ff2fb0, 16px -32px 0 #6fe36f, -30px 24px 0 #ffd23f, 36px 4px 0 #ff2fb0;
  animation-delay: .06s;
}
@keyframes confetti {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(.3) rotate(0); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -80%) scale(1.15) rotate(180deg); }
}

/* Forsta besoket: pekande hint mot byggstenarna */
.tap-hint {
  position: absolute; z-index: 5; left: 12px; top: -6px;
  display: flex; align-items: center; gap: 6px;
  background: var(--sun); color: #5a3d00; font-weight: 900; font-size: 15px;
  padding: 8px 12px; border-radius: 999px; border: 3px solid #5a3d00;
  box-shadow: 0 4px 0 #5a3d00, 0 8px 18px rgba(0,0,0,.25);
  pointer-events: none;
  animation: hint-bounce 1.1s ease-in-out infinite;
}
.tap-hint-arrow { font-size: 22px; line-height: 1; }
@keyframes hint-bounce { 0%, 100% { transform: translateY(-8px); } 50% { transform: translateY(2px); } }
@media (max-width: 899px) {
  .tap-hint { left: 50%; transform: translateX(-50%); top: -30px; }
  @keyframes hint-bounce { 0%, 100% { transform: translate(-50%, -8px); } 50% { transform: translate(-50%, 2px); } }
}

/* Kodtavlan: Robotarnas kod (mork krittavla som verkstaden) */
.code-panel { margin-top: 0; background: #14192b; border-color: #2a3350; }
.code-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.code-panel .panel-title { color: var(--neon-cyan); margin: 0; }
.code-tabs { display: flex; gap: 6px; }
.code-tab {
  font-family: var(--font-body); font-weight: 900; font-size: 13px;
  padding: 6px 12px; min-height: 36px; border-radius: 999px; cursor: pointer;
  border: 2px solid rgba(0,255,242,.45); background: transparent; color: #cfe9ff;
  -webkit-tap-highlight-color: transparent;
}
.code-tab.active { background: var(--neon-cyan); color: #0b1020; border-color: var(--neon-cyan); }
.code-explain { font-size: 14px; opacity: .85; margin: 8px 0 0; }
.code-view {
  background: #0b1020; color: #e6f7ff; border-radius: var(--radius-sm);
  padding: 12px 14px; overflow-x: auto; font-size: 13px; line-height: 1.7;
  border: 2px solid rgba(0,255,242,.35); margin: 0; white-space: pre;
  font-family: 'Courier New', ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700;
  background-image: repeating-linear-gradient(0deg, transparent, transparent 26px, rgba(255,255,255,.025) 26px, rgba(255,255,255,.025) 27px);
  box-shadow: inset 0 0 40px rgba(0,0,0,.5);
}
.code-lines { min-height: 200px; counter-reset: ln; }
.cb-line { position: relative; padding-left: 30px; min-height: 22px; border-radius: 4px; transition: background .3s; }
.cb-line::before {
  counter-increment: ln; content: counter(ln);
  position: absolute; left: 0; width: 22px; text-align: right;
  color: rgba(207,233,255,.35); font-weight: 400;
}
.cb-line.flash { background: rgba(255,210,63,.32); animation: cb-flash 1s ease-out; }
@keyframes cb-flash { 0% { background: rgba(255,210,63,.75); } 100% { background: rgba(255,210,63,0); } }
.cb-line.pending { opacity: .55; }
.cb-line.leaving { opacity: 0; transition: opacity .25s; }
.cb-caret { color: var(--neon-cyan); animation: caret .6s steps(1) infinite; }
@keyframes caret { 50% { opacity: 0; } }
.cb-wait { animation: caret 1s steps(1) infinite; }
.code-view .kw { color: #ff7ad9; }
.code-view .v { color: var(--neon-yellow); }
.code-view .p { color: #8fd3ff; }
.code-view .f { color: #b8a8ff; }
.code-view .s { color: #8fe08a; }
.code-view .n { color: #ff9edb; }
.code-view .b { color: var(--neon-cyan); }
.code-view .c { color: #7f8fa6; font-weight: 400; }
.code-view .k { color: var(--neon-yellow); }
.code-panel.glow { animation: panel-glow 1.2s ease-out; }
@keyframes panel-glow { 0% { box-shadow: 0 0 0 4px var(--neon-cyan), 0 0 30px var(--neon-cyan); } 100% { box-shadow: 0 6px 0 rgba(0,0,0,.18), 0 12px 24px rgba(0,0,0,.18); } }
.code-legend { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 6px 14px; font-size: 13px; margin-top: 10px; }
.code-legend code { color: var(--neon-yellow); font-weight: 700; }

/* Modaler */
.modal {
  position: fixed; inset: 0; z-index: 200;
  background: #0b1020;
  display: flex; flex-direction: column;
}
.modal-topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  background: rgba(31,111,42,.95); color: #fff; border-bottom: 3px solid var(--green-3);
  flex: 0 0 auto;
}
.modal-title { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.play-wrap { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; }
.play-wrap canvas { display: block; }

.modal-dialog { background: rgba(11,16,32,.8); align-items: center; justify-content: center; padding: 16px; }
.link-panel { width: min(100%, 520px); }
.link-text { font-weight: 700; }
.link-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.link-url { flex: 1 1 200px; font-size: 15px; font-weight: 700; }
.link-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.link-actions .btn { flex: 1 1 140px; }
.link-copied { margin-top: 10px; text-align: center; font-weight: 900; color: var(--green-3); }

.builder-footer { margin-top: 30px; }

/* Mobil (< 900px): farm-kolumnen loses upp (display: contents) sa att alla delar kan ordnas
   i EN kolumn: header, farm, byggstenar, ditt spel, kodtavla, status, sticky toolbar. */
@media (max-width: 899px) {
  .builder-page { padding-bottom: 96px; }
  .builder-main { padding-top: 12px; }
  .builder-layout { gap: 12px; grid-template-columns: minmax(0, 1fr); }
  .builder-farm-col { display: contents; }
  .builder-farm-col > * { min-width: 0; max-width: 100%; }
  .farm-panel { order: 1; }
  .blocks-panel { order: 2; }
  .game-summary-panel { order: 3; }
  .code-panel { order: 4; }
  .status-line { order: 5; }
  .builder-toolbar { order: 6; }
  .farm-container { max-height: 45vh; }
  .farm-panel { padding: 8px; }
  .panel { padding: 12px; }
  .title-field .input { font-size: 15px; padding: 7px 10px; }

  /* Byggstenar: chips i 2-3 kolumner */
  .block-chips {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
  }
  .block-chip { justify-content: flex-start; padding: 8px 10px; font-size: 15px; border-radius: 14px; min-height: 48px; text-align: left; }
  .block-chip > span:last-child { line-height: 1.15; }
  .blocks-hint { display: none; }
  .code-view { font-size: 12px; padding: 10px 8px; }
  .code-lines { min-height: 160px; }
  .cb-line { padding-left: 26px; }
  .cb-line::before { width: 18px; }

  /* Ditt spel: kompakt rad */
  .game-summary { font-size: 15px; min-height: 0; }
  .summary-robot { display: none; }
  .hero-preview { width: 56px; height: 56px; }

  /* Verktygsraden: sticky bottom bar */
  .builder-toolbar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 60;
    display: grid;
    grid-template-columns: 2.2fr repeat(4, 1fr);
    gap: 6px;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    border-radius: 0;
    border-width: 3px 0 0;
    box-shadow: 0 -6px 18px rgba(0,0,0,.25);
  }
  .builder-toolbar .btn {
    min-height: 54px; padding: 6px 4px; font-size: 12px; gap: 2px;
    flex-direction: column; border-radius: 12px; box-shadow: 0 3px 0 var(--btn-shadow);
  }
  .builder-toolbar .btn .emoji { font-size: 20px; }
  .builder-toolbar .btn .lbl { font-size: 11px; white-space: nowrap; letter-spacing: -.2px; }
  .builder-toolbar #btn-play { flex-direction: row; gap: 6px; }
  .builder-toolbar #btn-play .lbl { font-size: 16px; }
  .builder-toolbar #btn-play .emoji { font-size: 22px; }
}
