*{box-sizing:border-box}

:root{
  --gap:12px;
  --radius:12px;
  --border:#ddd;
}

html,body{
  height:100%;
}

body{
  font-family:system-ui;
  margin:16px;
  background:#fff;
  color:#111;
}

.top{
  display:flex;
  gap:12px;
  flex-wrap:wrap;
  align-items:center;
  justify-content:space-between;
}

.leftTools,.rightTools{
  display:flex;
  gap:12px;
  flex-wrap:wrap;
  align-items:center;
}

.pill{
  padding:8px 10px;
  border:1px solid var(--border);
  border-radius:12px;
  background:#fff;
}

button{
  padding:10px 12px;
  cursor:pointer;
  border:1px solid var(--border);
  border-radius:10px;
  background:#fff;
  font:inherit;
}

button.active{
  border-color:#000;
}

button.mode-on{
  background:#111;
  color:#fff;
  border-color:#111;
}

input[type="color"]{
  width:44px;
  height:44px;
  border:none;
  padding:0;
  background:transparent;
}

.small{
  opacity:.7;
  font-size:13px;
}

#wrap{
  margin-top:12px;
  position:relative;
  width:min(1200px, 96vw);
  height:min(700px, 70vh);
  border:1px solid var(--border);
  border-radius:14px;
  overflow:hidden;
  transition:opacity .2s ease;
  touch-action:none;
  background:#fff;
}

canvas{
  position:absolute;
  left:0;
  top:0;
  width:100%;
  height:100%;
  image-rendering:pixelated;
}

.hint{
  margin-top:8px;
  line-height:1.45;
}

.kbd{
  font-family:ui-monospace, SFMono-Regular, Menlo, monospace;
  border:1px solid var(--border);
  padding:2px 6px;
  border-radius:6px;
  background:#fafafa;
}

.userChip{
  display:flex;
  align-items:center;
  gap:10px;
  padding:6px 10px;
  border:1px solid var(--border);
  border-radius:999px;
  background:#fff;
  cursor:pointer;
}

.userChip img{
  width:34px;
  height:34px;
  border-radius:50%;
  object-fit:cover;
  background:#eee;
}

.userName{
  font-weight:700;
  line-height:1.1;
}

.userMenu{
  position:absolute;
  top:70px;
  right:16px;
  width:280px;
  border:1px solid var(--border);
  border-radius:16px;
  background:#fff;
  box-shadow:0 12px 30px rgba(0,0,0,.08);
  padding:14px;
  display:none;
  z-index:20;
}

.userMenu.open{
  display:block;
}

.userMenuTop{
  display:flex;
  gap:12px;
  align-items:center;
  margin-bottom:12px;
}

.userMenuTop img{
  width:54px;
  height:54px;
  border-radius:50%;
  object-fit:cover;
  background:#eee;
}

.menuName{
  font-weight:800;
}

.menuRow{
  display:flex;
  justify-content:space-between;
  gap:12px;
  padding:8px 0;
  border-top:1px solid #eee;
}

.logoutBtn{
  width:100%;
  margin-top:12px;
  background:#111;
  color:#fff;
  border-color:#111;
}

.loginOverlay{
  position:fixed;
  inset:0;
  background:rgba(255,255,255,.72);
  backdrop-filter:blur(4px);
  display:none;
  align-items:center;
  justify-content:center;
  z-index:50;
}

.loginOverlay.show{
  display:flex;
}

.loginCard{
  width:min(460px, 92vw);
  background:#fff;
  border:1px solid var(--border);
  border-radius:22px;
  padding:26px;
  box-shadow:0 20px 60px rgba(0,0,0,.12);
  text-align:center;
}

.loginCard h1{
  margin:0 0 8px 0;
  font-size:28px;
}

.loginCard p{
  margin:0 0 20px 0;
  opacity:.7;
}

.twitchBtn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:12px;
  padding:14px 18px;
  border:none;
  border-radius:14px;
  background:#9146FF;
  color:#fff;
  font-weight:700;
  font-size:16px;
  cursor:pointer;
}

.twitchBtn svg{
  width:22px;
  height:22px;
  display:block;
}

.twitchBtnMini{
  padding:10px 12px;
  font-size:14px;
}

.locked #wrap,
.locked .hint,
.locked .leftTools,
.locked .rightTools .pill:not(.authKeep){
  opacity:.25;
  pointer-events:none;
  user-select:none;
}

/* MOBILE */
@media (max-width: 820px){
  body{
    margin:10px;
    padding-bottom:10px;
  }

  .top{
    display:grid;
    grid-template-columns:1fr;
    align-items:stretch;
    gap:10px;
  }

  .leftTools,
  .rightTools{
    display:grid;
    grid-template-columns:1fr;
    gap:10px;
    width:100%;
  }

  .pill{
    width:100%;
    padding:10px;
  }

  .pill b{
    display:block;
    margin-bottom:8px;
  }

  .pill button{
    min-height:42px;
  }

  .pill input[type="color"]{
    width:52px;
    height:40px;
  }

  /* agrupar botones dentro de cada pill */
  .leftTools .pill:first-child,
  .leftTools .pill:nth-child(4){
    display:grid;
    grid-template-columns:repeat(2, minmax(0,1fr));
    gap:8px;
    align-items:center;
  }

  .leftTools .pill:first-child b,
  .leftTools .pill:nth-child(4) b{
    grid-column:1 / -1;
    margin-bottom:0;
  }

  .leftTools .pill:nth-child(2),
  .leftTools .pill:nth-child(3),
  .leftTools .pill:nth-child(5),
  .leftTools .pill:nth-child(6),
  .leftTools .pill:nth-child(7){
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:10px;
  }

  .rightTools{
    grid-template-columns:1fr;
  }

  #wrap{
    width:100%;
    height:min(58dvh, 76vw);
    min-height:320px;
    margin-top:10px;
    border-radius:16px;
  }

  .hint{
    font-size:12px;
    margin-top:10px;
  }

  .userMenu{
    position:fixed;
    top:auto;
    right:10px;
    left:10px;
    bottom:10px;
    width:auto;
    max-width:none;
    border-radius:18px;
  }

  .loginCard{
    width:min(94vw, 460px);
    padding:22px;
  }

  .loginCard h1{
    font-size:24px;
  }

  .twitchBtn{
    width:100%;
  }
}

@media (max-width: 480px){
  body{
    margin:8px;
  }

  .leftTools .pill:first-child,
  .leftTools .pill:nth-child(4){
    grid-template-columns:1fr 1fr;
  }

  .leftTools .pill:nth-child(2),
  .leftTools .pill:nth-child(3),
  .leftTools .pill:nth-child(5),
  .leftTools .pill:nth-child(6),
  .leftTools .pill:nth-child(7){
    flex-wrap:wrap;
    justify-content:flex-start;
  }

  #wrap{
    height:min(54dvh, 92vw);
    min-height:300px;
  }

  .userChip{
    width:100%;
    justify-content:center;
  }
}
