/* WebCraft styles */

:root {
  --bg: #f0f4ff;
  --panel: #fff;
  --border: #e2e8f8;
  --hc: #e8560a;
  --hl: #fff4ef;
  --hb: #ffd0bc;
  --cc: #1a6cf0;
  --cl: #eff5ff;
  --cb: #bdd3ff;
  --jc: #c9920a;
  --jl: #fffbef;
  --jb: #ffedb0;
  --coin: #f59e0b;
  --green: #16a34a;
  --gl: #dcfce7;
  --red: #dc2626;
  --rl: #fee2e2;
  --text: #1e2240;
  --muted: #7a82a8;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Nunito', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* HEADER */
header {
  background: var(--panel);
  border-bottom: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 56px;
  flex-shrink: 0;
  gap: 10px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.2rem;
  font-weight: 900;
  white-space: nowrap;
}

/* The small </> badge, same as the browser tab icon */
.logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 7px;
  border-radius: 8px;
  background: var(--text);
  color: var(--coin);
  font-family: 'Fira Code', monospace;
  font-size: 0.8rem;
  font-weight: 500;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Text for screen readers only */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.world-tabs {
  display: flex;
  gap: 6px;
}

.wtab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 30px;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.2s;
  user-select: none;
}

.wtab.ht {
  background: var(--hl);
  color: var(--hc);
  border-color: var(--hb);
}

.wtab.ct {
  background: var(--cl);
  color: var(--cc);
  border-color: var(--cb);
}

.wtab.jt {
  background: var(--jl);
  color: var(--jc);
  border-color: var(--jb);
}

.wtab.active.ht {
  background: var(--hc);
  color: #fff;
}

.wtab.active.ct {
  background: var(--cc);
  color: #fff;
}

.wtab.active.jt {
  background: var(--jc);
  color: #fff;
}

.wtab.locked {
  background: #f3f4f8;
  color: var(--muted);
  border-color: var(--border);
  cursor: pointer;
}

.wtab.locked::after {
  content: "\1F512";
  font-size: 0.75rem;
}

.lbadge {
  font-size: 0.75rem;
  background: var(--coin);
  color: #fff;
  border-radius: 20px;
  padding: 1px 7px;
  font-weight: 800;
}

.coins-disp {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--jl);
  border: 2px solid var(--jb);
  border-radius: 30px;
  padding: 5px 14px;
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--jc);
  white-space: nowrap;
}

/* MAIN */
main {
  display: grid;
  grid-template-columns: 290px 1fr 1fr;
  flex: 1;
  overflow: hidden;
}

/* SIDEBAR */
.sidebar {
  background: var(--panel);
  border-right: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sb-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.lnav-title {
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--muted);
  margin-bottom: 4px;
}

.lvlbtn {
  width: 100%;
  color: inherit;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 11px;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
  font-family: 'Nunito', sans-serif;
}

.lvlbtn:hover {
  border-color: #c5d0f0;
  background: #fff;
}

.lvlbtn.done {
  border-color: var(--green);
  background: var(--gl);
}

.lvlbtn.ha {
  border-color: var(--hc);
  background: var(--hl);
}

.lvlbtn.ca {
  border-color: var(--cc);
  background: var(--cl);
}

.lvlbtn.ja {
  border-color: var(--jc);
  background: var(--jl);
}

#level-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lbtn-icon {
  font-size: 1.1rem;
  flex-shrink: 0;
}

.lbtn-info {
  flex: 1;
  min-width: 0;
}

.lbtn-name {
  font-size: 0.8rem;
  font-weight: 700;
}

.lbtn-sub {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 1px;
}

.done-badge {
  font-size: 0.75rem;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 20px;
  background: var(--green);
  color: #fff;
  flex-shrink: 0;
}

/* INSTRUCTION CARD */
.icard {
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}

.icard-wtag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 3px 10px;
  border-radius: 20px;
  margin-bottom: 10px;
}

.icard-wtag.ht {
  background: var(--hl);
  color: var(--hc);
  border: 1px solid var(--hb);
}

.icard-wtag.ct {
  background: var(--cl);
  color: var(--cc);
  border: 1px solid var(--cb);
}

.icard-wtag.jt {
  background: var(--jl);
  color: var(--jc);
  border: 1px solid var(--jb);
}

.icard-title {
  font-size: 1rem;
  font-weight: 900;
  margin-bottom: 8px;
  line-height: 1.3;
}

.icard-desc {
  font-size: 0.8rem;
  color: #3a4060;
  line-height: 1.7;
  margin-bottom: 12px;
}

.eg-box {
  background: #1e2240;
  border-radius: 8px;
  padding: 11px 13px;
  margin-bottom: 12px;
}

.eg-label {
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #7a82a8;
  margin-bottom: 6px;
}

.eg-code {
  font-family: 'Fira Code', monospace;
  font-size: 0.75rem;
  color: #a6e3a1;
  white-space: pre;
  line-height: 1.7;
  overflow-x: auto;
}

.sidebar,
.editor-pane,
.preview-pane {
  min-width: 0;
}

.chk-title {
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin-bottom: 6px;
}

.chklist {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.chkitem {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.78rem;
  padding: 6px 10px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--border);
  transition: all 0.25s;
  line-height: 1.4;
}

.chkitem.pass {
  background: var(--gl);
  border-color: #86efac;
  color: var(--green);
}

.chkitem.fail {
  background: var(--rl);
  border-color: #fca5a5;
  color: var(--red);
}

.chk-dot {
  font-size: 0.9rem;
  flex-shrink: 0;
  margin-top: 1px;
}

.reward-line {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--coin);
  margin-top: 8px;
}

/* EDITOR */
.editor-pane {
  display: flex;
  flex-direction: column;
  border-right: 2px solid var(--border);
  background: #1e2240;
}

.ed-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 13px;
  min-height: 42px;
  flex-wrap: wrap;
  gap: 6px;
  background: #171930;
  border-bottom: 1px solid #2e3260;
  flex-shrink: 0;
}

.ed-fname {
  font-family: 'Fira Code', monospace;
  font-size: 0.75rem;
  color: #7a82a8;
  display: flex;
  align-items: center;
  gap: 7px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.dr {
  background: #ff5f57;
}

.dy {
  background: #febc2e;
}

.dg {
  background: #28c840;
}

.btn-row {
  display: flex;
  gap: 7px;
}

/* Keep each button's icon and word on one line; the row wraps instead */
.btn-row button {
  white-space: nowrap;
}

.run-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: #28c840;
  color: #fff;
  border: none;
  padding: 5px 13px;
  border-radius: 7px;
  font-family: 'Nunito', sans-serif;
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.15s;
}

.run-btn:hover {
  background: #22a836;
}

.sub-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--coin);
  color: #fff;
  border: none;
  padding: 5px 13px;
  border-radius: 7px;
  font-family: 'Nunito', sans-serif;
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.15s;
}

.sub-btn:hover {
  opacity: 0.85;
}

.sub-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.tool-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  background: transparent;
  color: #a9b1d6;
  border: 1px solid #3e4480;
  padding: 5px 10px;
  border-radius: 7px;
  font-family: 'Nunito', sans-serif;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
}

.tool-btn:hover {
  background: #2e3260;
  color: #fff;
}

.next-btn {
  display: none;
  align-items: center;
  gap: 5px;
  background: var(--cc);
  color: #fff;
  border: none;
  padding: 5px 13px;
  border-radius: 7px;
  font-family: 'Nunito', sans-serif;
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
}

.next-btn.show {
  display: flex;
}

.next-btn:hover {
  opacity: 0.85;
}

#code-editor {
  flex: 1;
  background: #1e2240;
  color: #cdd6f4;
  font-family: 'Fira Code', monospace;
  font-size: 0.8rem;
  line-height: 1.9;
  border: none;
  outline: none;
  padding: 15px;
  resize: none;
  tab-size: 2;
}

.ins-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 7px 13px;
  background: #171930;
  border-top: 1px solid #2e3260;
  flex-shrink: 0;
}

.ichip {
  font-family: 'Fira Code', monospace;
  font-size: 0.75rem;
  background: #2e3260;
  color: #a6e3a1;
  border: 1px solid #3e4480;
  border-radius: 5px;
  padding: 3px 8px;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
  white-space: nowrap;
}

.ichip:hover {
  background: #3e4480;
}

.ed-foot {
  padding: 5px 13px;
  background: #171930;
  border-top: 1px solid #2e3260;
  font-size: 0.75rem;
  color: #5a6290;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

/* PREVIEW */
.preview-pane {
  display: flex;
  flex-direction: column;
  background: #fff;
}

.pv-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 13px;
  height: 42px;
  background: #f8f9ff;
  border-bottom: 2px solid var(--border);
  flex-shrink: 0;
}

.pv-title {
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #28c840;
  animation: blink 1.5s infinite;
}

@keyframes blink {
  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.3;
  }
}

#preview-frame {
  flex: 1;
  border: none;
  background: #fff;
  display: none;
}

.pv-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
  font-size: 0.88rem;
}

.pv-hint {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
}

.pv-empty-note {
  font-size: 0.76rem;
}

.pv-empty-icon {
  font-size: 3rem;
  opacity: 0.4;
}

.res-banner {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px 13px;
  font-size: 0.8rem;
  font-weight: 700;
  border-top: 2px solid transparent;
  flex-shrink: 0;
}

.res-banner.show {
  display: flex;
}

.res-banner.ok {
  background: var(--gl);
  border-color: #86efac;
  color: var(--green);
}

.res-banner.bad {
  background: var(--rl);
  border-color: #fca5a5;
  color: var(--red);
}

.res-banner.partial {
  background: var(--jl);
  border-color: var(--jb);
  color: var(--jc);
}

/* SHOP */
#shop-screen {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(30,34,64,0.85);
  backdrop-filter: blur(4px);
  z-index: 50;
  align-items: center;
  justify-content: center;
}

#shop-screen.show {
  display: flex;
}

#finish-screen {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(30,34,64,0.85);
  backdrop-filter: blur(4px);
  z-index: 60;
  align-items: center;
  justify-content: center;
}

#finish-screen.show {
  display: flex;
}

.finish-panel {
  text-align: center;
}

.finish-icon {
  font-size: 3.2rem;
  margin-bottom: 8px;
}

.finish-actions {
  display: flex;
  gap: 10px;
}

.shop-close.danger {
  color: var(--red);
}

.shop-panel {
  background: #fff;
  border-radius: 20px;
  padding: 34px;
  max-width: 500px;
  width: 95%;
  box-shadow: 0 24px 80px rgba(30,34,64,0.3);
}

.shop-title {
  font-size: 1.5rem;
  font-weight: 900;
  margin-bottom: 6px;
}

.shop-sub {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 24px;
  line-height: 1.6;
}

.shop-items {
  display: flex;
  flex-direction: column;
  gap: 13px;
  margin-bottom: 22px;
}

.shop-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border-radius: 13px;
  border: 2px solid var(--border);
  transition: all 0.2s;
}

.shop-item.css-si {
  border-color: var(--cb);
  background: var(--cl);
}

.shop-item.js-si {
  border-color: var(--jb);
  background: var(--jl);
}

.shop-item.owned {
  border-color: #86efac;
  background: var(--gl);
}

.si-icon {
  font-size: 1.8rem;
}

.si-info {
  flex: 1;
}

.si-name {
  font-size: 0.95rem;
  font-weight: 800;
  margin-bottom: 3px;
}

.css-si .si-name {
  color: var(--cc);
}

.js-si .si-name {
  color: var(--jc);
}

.si-desc {
  font-size: 0.76rem;
  color: var(--muted);
  line-height: 1.5;
}

.buy-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 8px 16px;
  border-radius: 9px;
  border: none;
  font-family: 'Nunito', sans-serif;
  font-size: 0.82rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.buy-css {
  background: var(--cc);
  color: #fff;
}

.buy-css:hover {
  opacity: 0.85;
}

.buy-js {
  background: var(--jc);
  color: #fff;
}

.buy-js:hover {
  opacity: 0.85;
}

.buy-dis {
  background: #e2e8f8;
  color: var(--muted);
  cursor: not-allowed;
}

.owned-b {
  background: var(--green);
  color: #fff;
  border-radius: 20px;
  padding: 6px 14px;
  font-weight: 800;
  font-size: 0.8rem;
}

.shop-close {
  width: 100%;
  padding: 11px;
  border-radius: 11px;
  border: 2px solid var(--border);
  background: #fff;
  font-family: 'Nunito', sans-serif;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--muted);
  transition: all 0.15s;
}

.shop-close:hover {
  background: var(--bg);
}

/* TOAST */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  padding: 11px 22px;
  border-radius: 30px;
  font-weight: 800;
  font-size: 0.88rem;
  opacity: 0;
  transition: all 0.3s;
  pointer-events: none;
  z-index: 200;
  white-space: nowrap;
  box-shadow: 0 8px 30px rgba(0,0,0,0.2);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.success {
  background: var(--green);
  color: #fff;
}

.toast.error {
  background: var(--red);
  color: #fff;
}

.toast.coins {
  background: var(--coin);
  color: #fff;
}

.toast.info {
  background: var(--cc);
  color: #fff;
}

/* SHOP BTN */
.shop-open-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 13px;
  border-radius: 20px;
  border: 2px solid var(--jb);
  background: var(--jl);
  color: var(--jc);
  font-family: 'Nunito', sans-serif;
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.15s;
}

.shop-open-btn:hover {
  background: var(--jc);
  color: #fff;
}

/* TABLET AND PHONE */
@media (max-width: 1100px) {
  main {
    grid-template-columns: 260px 1fr;
  }

  .preview-pane {
    grid-column: 1 / -1;
    min-height: 340px;
    border-top: 2px solid var(--border);
  }

  body {
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  main {
    overflow: visible;
  }

  .editor-pane {
    min-height: 520px;
  }
}

@media (max-width: 760px) {
  header {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 12px;
    row-gap: 8px;
  }

  .logo {
    font-size: 1.05rem;
  }

  .world-tabs {
    order: 3;
    width: 100%;
    justify-content: center;
  }

  .wtab {
    flex: 1;
    justify-content: center;
  }

  main {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: none;
    border-bottom: 2px solid var(--border);
    overflow: visible;
  }

  .sb-scroll {
    overflow: visible;
  }

  .editor-pane {
    min-height: 420px;
    border-right: none;
  }

  .ed-top {
    height: auto;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px;
  }

  .btn-row {
    flex-wrap: wrap;
  }

  .ed-foot span:first-child {
    display: none;
  }

  .preview-pane {
    min-height: 360px;
  }

  .shop-panel {
    padding: 22px;
  }

  .shop-item {
    flex-wrap: wrap;
  }

  .finish-actions {
    flex-direction: column;
  }

  .toast {
    white-space: normal;
    width: max-content;
    max-width: 90vw;
    text-align: center;
  }
}

button:focus-visible,
.ichip:focus-visible,
#code-editor:focus-visible {
  outline: 3px solid var(--coin);
  outline-offset: 2px;
}

::-webkit-scrollbar {
  width: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #d0d6f0;
  border-radius: 4px;
}
